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);
}
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;
}
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());
}
}
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);
}
}
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());
}
}
Aggregations