use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class SubGraphExporter method exportConstraints.
private Collection<String> exportConstraints() {
final List<String> result = new ArrayList<>();
for (ConstraintDefinition constraint : graph.getConstraints()) {
if (!constraint.isConstraintType(ConstraintType.UNIQUENESS)) {
throw new RuntimeException("Exporting constraints other than uniqueness is not implemented yet");
}
Iterator<String> propertyKeys = constraint.getPropertyKeys().iterator();
if (!propertyKeys.hasNext()) {
throw new IllegalStateException("Constraints should have at least one property key");
}
String key = quote(propertyKeys.next());
if (propertyKeys.hasNext()) {
throw new RuntimeException("Exporting compound constraints is not implemented yet");
}
String label = quote(constraint.getLabel().name());
result.add("create constraint on (n:" + label + ") assert n." + key + " is unique");
}
Collections.sort(result);
return result;
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class SchemaImpl method asConstraintDefinitions.
private Iterable<ConstraintDefinition> asConstraintDefinitions(Iterator<? extends ConstraintDescriptor> constraints, ReadOperations readOperations) {
// 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(ConstraintBoundary.map(constraint), readOperations));
}
return definitions;
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class SchemaAcceptanceTest method shouldListAddedConstraintsByLabel.
@Test
public void shouldListAddedConstraintsByLabel() throws Exception {
// GIVEN
ConstraintDefinition constraint1 = createUniquenessConstraint(label, propertyKey);
createUniquenessConstraint(Labels.MY_OTHER_LABEL, propertyKey);
// WHEN THEN
assertThat(getConstraints(db, label), containsOnly(constraint1));
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class SchemaAcceptanceTest method createUniquenessConstraint.
private ConstraintDefinition createUniquenessConstraint(Label label, String prop) {
try (Transaction tx = db.beginTx()) {
ConstraintDefinition constraint = db.schema().constraintFor(label).assertPropertyIsUnique(prop).create();
tx.success();
return constraint;
}
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class SchemaWithPECAcceptanceTest method shouldListAddedConstraintsByRelationshipType.
@Test
public void shouldListAddedConstraintsByRelationshipType() throws Exception {
// GIVEN
ConstraintDefinition constraint1 = createRelationshipPropertyExistenceConstraint(Types.MY_TYPE, propertyKey);
createRelationshipPropertyExistenceConstraint(Types.MY_OTHER_TYPE, propertyKey);
// WHEN THEN
assertThat(getConstraints(db, Types.MY_TYPE), containsOnly(constraint1));
}
Aggregations