Search in sources :

Example 26 with SchemaRead

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

the class SchemaImpl method getConstraints.

@Override
public Iterable<ConstraintDefinition> getConstraints(RelationshipType type) {
    transaction.assertOpen();
    TokenRead tokenRead = transaction.tokenRead();
    SchemaRead schemaRead = transaction.schemaRead();
    int typeId = tokenRead.relationshipType(type.name());
    if (typeId == TokenRead.NO_TOKEN) {
        return emptyList();
    }
    return asConstraintDefinitions(schemaRead.constraintsGetForRelationshipType(typeId), tokenRead);
}
Also used : SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) TokenRead(org.neo4j.internal.kernel.api.TokenRead)

Example 27 with SchemaRead

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

the class ConstraintIndexCreatorTest method schemaRead.

private SchemaRead schemaRead() {
    SchemaRead schemaRead = mock(SchemaRead.class);
    when(schemaRead.index(schema)).thenReturn(Iterators.emptyResourceIterator());
    return schemaRead;
}
Also used : SchemaRead(org.neo4j.internal.kernel.api.SchemaRead)

Example 28 with SchemaRead

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

the class SchemaReadWriteTestBase method shouldDropIndex.

@Test
void shouldDropIndex() throws Exception {
    IndexDescriptor index;
    try (KernelTransaction transaction = beginTransaction()) {
        index = transaction.schemaWrite().indexCreate(forLabel(label, prop1), "my index");
        transaction.commit();
    }
    try (KernelTransaction transaction = beginTransaction()) {
        transaction.schemaWrite().indexDrop(index);
        transaction.commit();
    }
    try (KernelTransaction transaction = beginTransaction()) {
        SchemaRead schemaRead = transaction.schemaRead();
        assertFalse(schemaRead.index(SchemaDescriptor.forLabel(label, prop1)).hasNext());
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 29 with SchemaRead

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

the class SchemaReadWriteTestBase method shouldSeeRelationshipPropertyExistenceConstraintFromTransaction.

@Test
void shouldSeeRelationshipPropertyExistenceConstraintFromTransaction() throws Exception {
    ConstraintDescriptor existing;
    try (KernelTransaction transaction = beginTransaction()) {
        existing = transaction.schemaWrite().relationshipPropertyExistenceConstraintCreate(forRelType(type, prop1), "existing constraint");
        transaction.commit();
    }
    try (KernelTransaction transaction = beginTransaction()) {
        SchemaReadCore before = transaction.schemaRead().snapshot();
        ConstraintDescriptor newConstraint = transaction.schemaWrite().relationshipPropertyExistenceConstraintCreate(forRelType(type, prop2), "new constraint");
        SchemaRead schemaRead = transaction.schemaRead();
        assertTrue(schemaRead.constraintExists(existing));
        assertTrue(schemaRead.constraintExists(newConstraint));
        assertThat(asList(schemaRead.constraintsGetForRelationshipType(type))).contains(existing, newConstraint);
        assertThat(asList(schemaRead.snapshot().constraintsGetForRelationshipType(type))).contains(existing, newConstraint);
        assertThat(asList(before.constraintsGetForRelationshipType(type))).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 30 with SchemaRead

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

the class SchemaReadWriteTestBase method shouldSeeIndexFromTransaction.

@Test
void shouldSeeIndexFromTransaction() throws Exception {
    try (KernelTransaction transaction = beginTransaction()) {
        transaction.schemaWrite().indexCreate(forLabel(label, prop1), "my index");
        transaction.commit();
    }
    try (KernelTransaction transaction = beginTransaction()) {
        LabelSchemaDescriptor schema = forLabel(label, prop2);
        transaction.schemaWrite().indexCreate(schema, "my other index");
        SchemaRead schemaRead = transaction.schemaRead();
        IndexDescriptor index = single(schemaRead.index(schema));
        assertThat(index.schema().getPropertyIds()).isEqualTo(new int[] { prop2 });
        assertThat(2).isEqualTo(Iterators.asList(schemaRead.indexesGetAll()).size());
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)52 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)36 Test (org.junit.jupiter.api.Test)28 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)26 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)22 TokenRead (org.neo4j.internal.kernel.api.TokenRead)12 SchemaReadCore (org.neo4j.internal.kernel.api.SchemaReadCore)9 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)8 ArrayList (java.util.ArrayList)7 Read (org.neo4j.internal.kernel.api.Read)5 HashMap (java.util.HashMap)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Arrays (java.util.Arrays)3 Iterator (java.util.Iterator)3 List (java.util.List)3 Map (java.util.Map)3 EntityType (org.neo4j.common.EntityType)3 KernelException (org.neo4j.exceptions.KernelException)3 Transaction (org.neo4j.graphdb.Transaction)3 Iterators (org.neo4j.internal.helpers.collection.Iterators)3