Search in sources :

Example 21 with SchemaReadCore

use of org.neo4j.internal.kernel.api.SchemaReadCore in project neo4j by neo4j.

the class SchemaReadWriteTestBase method shouldNotSeeDroppedRelationshipPropertyExistenceConstraintFromTransaction.

@Test
void shouldNotSeeDroppedRelationshipPropertyExistenceConstraintFromTransaction() throws Exception {
    ConstraintDescriptor existing;
    try (KernelTransaction transaction = beginTransaction()) {
        existing = transaction.schemaWrite().relationshipPropertyExistenceConstraintCreate(forRelType(type, prop1), "constraint name");
        transaction.commit();
    }
    try (KernelTransaction transaction = beginTransaction()) {
        SchemaReadCore before = transaction.schemaRead().snapshot();
        transaction.schemaWrite().constraintDrop(existing);
        SchemaRead schemaRead = transaction.schemaRead();
        assertFalse(schemaRead.constraintExists(existing));
        assertFalse(schemaRead.index(SchemaDescriptor.forLabel(type, prop2)).hasNext());
        assertThat(asList(schemaRead.constraintsGetForLabel(label))).isEmpty();
        assertThat(asList(schemaRead.snapshot().constraintsGetForLabel(label))).isEmpty();
        assertThat(asList(before.constraintsGetForLabel(label))).isEmpty();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) Test(org.junit.jupiter.api.Test)

Example 22 with SchemaReadCore

use of org.neo4j.internal.kernel.api.SchemaReadCore in project neo4j by neo4j.

the class SchemaReadWriteTestBase method shouldSeeNodePropertyExistenceConstraintFromTransaction.

@Test
void shouldSeeNodePropertyExistenceConstraintFromTransaction() throws Exception {
    ConstraintDescriptor existing;
    try (KernelTransaction transaction = beginTransaction()) {
        existing = transaction.schemaWrite().nodePropertyExistenceConstraintCreate(forLabel(label, prop1), "existing constraint");
        transaction.commit();
    }
    try (KernelTransaction transaction = beginTransaction()) {
        SchemaReadCore before = transaction.schemaRead().snapshot();
        ConstraintDescriptor newConstraint = transaction.schemaWrite().nodePropertyExistenceConstraintCreate(forLabel(label, prop2), "new constraint");
        SchemaRead schemaRead = transaction.schemaRead();
        assertTrue(schemaRead.constraintExists(existing));
        assertTrue(schemaRead.constraintExists(newConstraint));
        assertThat(asList(schemaRead.constraintsGetForLabel(label))).contains(existing, newConstraint);
        assertThat(asList(schemaRead.snapshot().constraintsGetForLabel(label))).contains(existing, newConstraint);
        assertThat(asList(before.constraintsGetForLabel(label))).contains(existing, newConstraint);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) Test(org.junit.jupiter.api.Test)

Example 23 with SchemaReadCore

use of org.neo4j.internal.kernel.api.SchemaReadCore in project neo4j by neo4j.

the class SchemaReadWriteTestBase method shouldListConstraintsByLabel.

@Test
void shouldListConstraintsByLabel() throws Exception {
    int wrongLabel;
    ConstraintDescriptor inStore;
    ConstraintDescriptor droppedInTx;
    ConstraintDescriptor createdInTx;
    try (KernelTransaction tx = beginTransaction()) {
        wrongLabel = tx.tokenWrite().labelGetOrCreateForName("wrongLabel");
        tx.schemaWrite().uniquePropertyConstraintCreate(uniqueForSchema(forLabel(wrongLabel, prop1)).withName("first constraint"));
        inStore = tx.schemaWrite().uniquePropertyConstraintCreate(uniqueForSchema(forLabel(label, prop1)).withName("second constraint"));
        droppedInTx = tx.schemaWrite().uniquePropertyConstraintCreate(uniqueForSchema(forLabel(label, prop2)).withName("third constraint"));
        tx.commit();
    }
    try (KernelTransaction tx = beginTransaction()) {
        SchemaReadCore before = tx.schemaRead().snapshot();
        createdInTx = tx.schemaWrite().nodePropertyExistenceConstraintCreate(forLabel(label, prop1), "fourth constraint");
        tx.schemaWrite().nodePropertyExistenceConstraintCreate(forLabel(wrongLabel, prop1), "fifth constraint");
        tx.schemaWrite().constraintDrop(droppedInTx);
        Iterable<ConstraintDescriptor> allConstraints = () -> tx.schemaRead().constraintsGetForLabel(label);
        assertThat(allConstraints).contains(inStore, createdInTx);
        assertThat(before.constraintsGetForLabel(label)).toIterable().contains(inStore, createdInTx);
        tx.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) Test(org.junit.jupiter.api.Test)

Example 24 with SchemaReadCore

use of org.neo4j.internal.kernel.api.SchemaReadCore in project neo4j by neo4j.

the class SchemaReadWriteTestBase method oldSnapshotShouldNotSeeNewlyCommittedIndexes.

@Test
void oldSnapshotShouldNotSeeNewlyCommittedIndexes() throws Exception {
    try (KernelTransaction longRunning = beginTransaction()) {
        SchemaReadCore snapshot = longRunning.schemaRead().snapshot();
        try (KernelTransaction overlapping = beginTransaction()) {
            overlapping.schemaWrite().indexCreate(forLabel(label, prop1), "a");
            overlapping.schemaWrite().indexCreate(IndexPrototype.forSchema(fulltext(RELATIONSHIP, new int[] { type }, new int[] { prop2 })).withIndexType(IndexType.FULLTEXT).withName("b"));
            overlapping.commit();
        }
        assertThat(snapshot.indexGetForName("a")).isEqualTo(NO_INDEX);
        assertThat(snapshot.indexGetForName("b")).isEqualTo(NO_INDEX);
        assertFalse(snapshot.indexesGetAll().hasNext());
        assertFalse(snapshot.index(forLabel(label, prop1)).hasNext());
        assertFalse(snapshot.indexesGetForLabel(label).hasNext());
        assertFalse(snapshot.indexesGetForRelationshipType(type).hasNext());
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) Test(org.junit.jupiter.api.Test)

Example 25 with SchemaReadCore

use of org.neo4j.internal.kernel.api.SchemaReadCore in project neo4j by neo4j.

the class BuiltInProcedures method indexDetails.

@Deprecated(since = "4.2.0", forRemoval = true)
@SystemProcedure
@Description("Detailed description of specific index.")
@Procedure(name = "db.indexDetails", mode = READ, deprecatedBy = "SHOW INDEXES YIELD * command")
public Stream<IndexDetailResult> indexDetails(@Name("indexName") String indexName) throws ProcedureException {
    if (callContext.isSystemDatabase()) {
        return Stream.empty();
    }
    TokenRead tokenRead = kernelTransaction.tokenRead();
    IndexingService indexingService = resolver.resolveDependency(IndexingService.class);
    SchemaReadCore schemaRead = kernelTransaction.schemaRead().snapshot();
    List<IndexDescriptor> indexes = asList(schemaRead.indexesGetAll());
    IndexDescriptor index = null;
    for (IndexDescriptor candidate : indexes) {
        if (candidate.getName().equals(indexName)) {
            index = candidate;
            break;
        }
    }
    if (index == null) {
        throw new ProcedureException(Status.Schema.IndexNotFound, "Could not find index with name \"" + indexName + "\"");
    }
    final IndexDetailResult indexDetailResult = asIndexDetails(tokenRead, schemaRead, index);
    return Stream.of(indexDetailResult);
}
Also used : IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) TokenRead(org.neo4j.internal.kernel.api.TokenRead) SchemaReadCore(org.neo4j.internal.kernel.api.SchemaReadCore) Description(org.neo4j.procedure.Description) SystemProcedure(org.neo4j.kernel.api.procedure.SystemProcedure) SystemProcedure(org.neo4j.kernel.api.procedure.SystemProcedure) Procedure(org.neo4j.procedure.Procedure)

Aggregations

SchemaReadCore (org.neo4j.internal.kernel.api.SchemaReadCore)32 Test (org.junit.jupiter.api.Test)27 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)21 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)17 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)17 TokenRead (org.neo4j.internal.kernel.api.TokenRead)13 InternalIndexState (org.neo4j.internal.kernel.api.InternalIndexState)10 SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)9 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)5 SystemProcedure (org.neo4j.kernel.api.procedure.SystemProcedure)4 IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)4 Description (org.neo4j.procedure.Description)4 Procedure (org.neo4j.procedure.Procedure)4 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 DependencyResolver (org.neo4j.common.DependencyResolver)3 Config (org.neo4j.configuration.Config)3