use of org.neo4j.internal.kernel.api.SchemaRead in project neo4j by neo4j.
the class SchemaReadWriteTestBase method shouldCreateRelationshipPropertyExistenceConstraint.
@Test
void shouldCreateRelationshipPropertyExistenceConstraint() throws Exception {
ConstraintDescriptor constraint;
try (KernelTransaction transaction = beginTransaction()) {
constraint = transaction.schemaWrite().relationshipPropertyExistenceConstraintCreate(forRelType(type, prop1), "constraint name");
transaction.commit();
}
try (KernelTransaction transaction = beginTransaction()) {
SchemaRead schemaRead = transaction.schemaRead();
assertTrue(schemaRead.constraintExists(constraint));
assertThat(asList(schemaRead.constraintsGetForRelationshipType(type))).isEqualTo(singletonList(constraint));
assertThat(asList(schemaRead.snapshot().constraintsGetForRelationshipType(type))).isEqualTo(singletonList(constraint));
}
}
use of org.neo4j.internal.kernel.api.SchemaRead 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);
}
}
use of org.neo4j.internal.kernel.api.SchemaRead in project neo4j by neo4j.
the class SchemaReadWriteTestBase method shouldCreateIndex.
@Test
void shouldCreateIndex() throws Exception {
IndexDescriptor index;
try (KernelTransaction transaction = beginTransaction()) {
index = transaction.schemaWrite().indexCreate(forLabel(label, prop1), "my index");
transaction.commit();
}
try (KernelTransaction transaction = beginTransaction()) {
SchemaRead schemaRead = transaction.schemaRead();
assertThat(single(schemaRead.index(SchemaDescriptor.forLabel(label, prop1)))).isEqualTo(index);
}
}
use of org.neo4j.internal.kernel.api.SchemaRead in project neo4j by neo4j.
the class SchemaReadWriteTestBase method shouldCreateNodeKeyConstraint.
@Test
void shouldCreateNodeKeyConstraint() throws Exception {
ConstraintDescriptor constraint;
try (KernelTransaction transaction = beginTransaction()) {
constraint = transaction.schemaWrite().nodeKeyConstraintCreate(uniqueForSchema(forLabel(label, prop1)));
transaction.commit();
}
try (KernelTransaction transaction = beginTransaction()) {
SchemaRead schemaRead = transaction.schemaRead();
assertTrue(schemaRead.constraintExists(constraint));
assertThat(asList(schemaRead.constraintsGetForLabel(label))).isEqualTo(singletonList(constraint));
assertThat(asList(schemaRead.snapshot().constraintsGetForLabel(label))).isEqualTo(singletonList(constraint));
}
}
use of org.neo4j.internal.kernel.api.SchemaRead in project neo4j by neo4j.
the class GraphDbStructureGuide method showIndices.
private static void showIndices(DbStructureVisitor visitor, KernelTransaction ktx, TokenNameLookup nameLookup) throws IndexNotFoundKernelException {
SchemaRead schemaRead = ktx.schemaRead();
for (IndexDescriptor reference : loop(IndexDescriptor.sortByType(schemaRead.indexesGetAll()))) {
String userDescription = reference.schema().userDescription(nameLookup);
double uniqueValuesPercentage = schemaRead.indexUniqueValuesSelectivity(reference);
long size = schemaRead.indexSize(reference);
visitor.visitIndex(reference, userDescription, uniqueValuesPercentage, size);
}
}
Aggregations