use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class SchemaReadWriteTestBase method shouldDropNodePropertyExistenceConstraint.
@Test
void shouldDropNodePropertyExistenceConstraint() throws Exception {
ConstraintDescriptor constraint;
try (KernelTransaction transaction = beginTransaction()) {
constraint = transaction.schemaWrite().nodePropertyExistenceConstraintCreate(forLabel(label, prop1), "constraint name");
transaction.commit();
}
try (KernelTransaction transaction = beginTransaction()) {
transaction.schemaWrite().constraintDrop(constraint);
transaction.commit();
}
try (KernelTransaction transaction = beginTransaction()) {
SchemaRead schemaRead = transaction.schemaRead();
assertFalse(schemaRead.constraintExists(constraint));
assertThat(asList(schemaRead.constraintsGetForLabel(label))).isEmpty();
assertThat(asList(schemaRead.snapshot().constraintsGetForLabel(label))).isEmpty();
}
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class SchemaReadWriteTestBase method shouldCreateUniquePropertyConstraint.
@Test
void shouldCreateUniquePropertyConstraint() throws Exception {
ConstraintDescriptor constraint;
try (KernelTransaction transaction = beginTransaction()) {
constraint = transaction.schemaWrite().uniquePropertyConstraintCreate(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.schema.ConstraintDescriptor in project neo4j by neo4j.
the class SchemaReadWriteTestBase method shouldListAllConstraintsInSnapshot.
@Test
void shouldListAllConstraintsInSnapshot() throws Exception {
ConstraintDescriptor toRetain;
ConstraintDescriptor toRetain2;
ConstraintDescriptor toDrop;
ConstraintDescriptor created;
try (KernelTransaction tx = beginTransaction()) {
toRetain = tx.schemaWrite().uniquePropertyConstraintCreate(uniqueForSchema(forLabel(label, prop1)).withName("first constraint"));
toRetain2 = tx.schemaWrite().uniquePropertyConstraintCreate(uniqueForSchema(forLabel(label2, prop1)).withName("second constraint"));
toDrop = tx.schemaWrite().uniquePropertyConstraintCreate(uniqueForSchema(forLabel(label, prop2)).withName("third constraint"));
tx.commit();
}
try (KernelTransaction tx = beginTransaction()) {
SchemaReadCore before = tx.schemaRead().snapshot();
created = tx.schemaWrite().nodePropertyExistenceConstraintCreate(forLabel(label, prop1), "new constraint");
tx.schemaWrite().constraintDrop(toDrop);
Iterable<ConstraintDescriptor> allConstraints = () -> tx.schemaRead().snapshot().constraintsGetAll();
assertThat(allConstraints).contains(toRetain, toRetain2, created);
assertThat(before.constraintsGetAll()).toIterable().contains(toRetain, toRetain2, created);
tx.commit();
}
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class GraphCountsSection method constraints.
private static List<Map<String, Object>> constraints(TokenRead tokens, SchemaRead schemaRead, Anonymizer anonymizer) {
List<Map<String, Object>> constraints = new ArrayList<>();
Iterator<ConstraintDescriptor> iterator = schemaRead.constraintsGetAll();
while (iterator.hasNext()) {
ConstraintDescriptor constraint = iterator.next();
EntityType entityType = constraint.schema().entityType();
Map<String, Object> data = new HashMap<>();
data.put("properties", map(constraint.schema().getPropertyIds(), id -> anonymizer.propertyKey(tokens.propertyKeyGetName(id), id)));
data.put("type", constraintType(constraint));
int entityTokenId = constraint.schema().getEntityTokenIds()[0];
switch(entityType) {
case NODE:
data.put("label", anonymizer.label(tokens.labelGetName(entityTokenId), entityTokenId));
constraints.add(data);
break;
case RELATIONSHIP:
data.put("relationshipType", anonymizer.relationshipType(tokens.relationshipTypeGetName(entityTokenId), entityTokenId));
constraints.add(data);
break;
default:
}
}
return constraints;
}
use of org.neo4j.internal.schema.ConstraintDescriptor in project neo4j by neo4j.
the class SchemaImpl method asConstraintDefinitions.
private Iterable<ConstraintDefinition> asConstraintDefinitions(Iterator<? extends ConstraintDescriptor> constraints, TokenRead tokenRead) {
// Intentionally create an eager list so that used statement can be closed
List<ConstraintDefinition> definitions = new ArrayList<>();
while (constraints.hasNext()) {
ConstraintDescriptor constraint = constraints.next();
definitions.add(asConstraintDefinition(constraint, tokenRead));
}
return definitions;
}
Aggregations