use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class IndexConstraintsTest method getConstraint.
private ConstraintDefinition getConstraint(Label label, String propertyKey) {
try (Transaction tx = graphDb.beginTx()) {
ConstraintDefinition found = null;
for (ConstraintDefinition constraint : graphDb.schema().getConstraints(label)) {
if (propertyKey.equals(single(constraint.getPropertyKeys()))) {
assertNull("Found multiple constraints.", found);
found = constraint;
}
}
tx.success();
return found;
}
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class DatabaseActions method filteredRelationshipConstraints.
private Iterable<ConstraintDefinition> filteredRelationshipConstraints(String typeName, Predicate<ConstraintDefinition> filter) {
RelationshipType type = RelationshipType.withName(typeName);
Iterable<ConstraintDefinition> constraints = graphDb.schema().getConstraints(type);
return filter(filter, constraints);
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class DatabaseActions method dropNodePropertyExistenceConstraint.
public boolean dropNodePropertyExistenceConstraint(String labelName, Iterable<String> propertyKeys) {
final Set<String> propertyKeysSet = Iterables.asSet(propertyKeys);
ConstraintDefinition constraint = Iterables.singleOrNull(filteredNodeConstraints(labelName, nodePropertyExistenceFilter(propertyKeysSet)));
if (constraint != null) {
constraint.drop();
}
return constraint != null;
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class DatabaseActions method dropPropertyUniquenessConstraint.
public boolean dropPropertyUniquenessConstraint(String labelName, Iterable<String> propertyKeys) {
final Set<String> propertyKeysSet = Iterables.asSet(propertyKeys);
ConstraintDefinition constraint = Iterables.singleOrNull(filteredNodeConstraints(labelName, propertyUniquenessFilter(propertyKeysSet)));
if (constraint != null) {
constraint.drop();
}
return constraint != null;
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class DatabaseActions method createPropertyUniquenessConstraint.
public ConstraintDefinitionRepresentation createPropertyUniquenessConstraint(String labelName, Iterable<String> propertyKeys) {
ConstraintCreator constraintCreator = graphDb.schema().constraintFor(label(labelName));
for (String key : propertyKeys) {
constraintCreator = constraintCreator.assertPropertyIsUnique(key);
}
ConstraintDefinition constraintDefinition = constraintCreator.create();
return new ConstraintDefinitionRepresentation(constraintDefinition);
}
Aggregations