use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class Schema method reportConstraints.
private void reportConstraints(Output out, Iterable<ConstraintDefinition> constraints) throws RemoteException {
int j = 0;
for (ConstraintDefinition constraint : constraints) {
if (j == 0) {
out.println();
out.println("Constraints");
}
out.println(indent(constraint.toString()));
j++;
}
if (j == 0) {
out.println();
out.println("No constraints");
}
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class LucenePartitionedIndexStressTesting method dropAllIndexes.
private void dropAllIndexes() {
try (Transaction transaction = db.beginTx()) {
Schema schema = db.schema();
schema.getConstraints().forEach(ConstraintDefinition::drop);
schema.getIndexes().forEach(IndexDefinition::drop);
transaction.success();
}
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class PropertyExistenceConstraintsIT method createLabelUniquenessPropertyConstraint.
private ConstraintDefinition createLabelUniquenessPropertyConstraint(String labelName, String propertyKey) {
try (Transaction tx = graphdb().beginTx()) {
ConstraintDefinition constraintDefinition = graphdb().schema().constraintFor(label(labelName)).assertPropertyIsUnique(propertyKey).create();
tx.success();
return constraintDefinition;
}
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class GraphDbHelper method getPropertyUniquenessConstraints.
public Iterable<ConstraintDefinition> getPropertyUniquenessConstraints(String labelName, final String propertyKey) {
try (Transaction tx = database.getGraph().beginTransaction(implicit, AnonymousContext.read())) {
Iterable<ConstraintDefinition> definitions = Iterables.filter(item -> {
if (item.isConstraintType(ConstraintType.UNIQUENESS)) {
Iterable<String> keys = item.getPropertyKeys();
return single(keys).equals(propertyKey);
} else {
return false;
}
}, database.getGraph().schema().getConstraints(label(labelName)));
tx.success();
return definitions;
}
}
use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.
the class SchemaConstraintsIT method drop_constraint.
@Documented("Drop uniqueness constraint.\n" + "Drop uniqueness constraint for a label and a property.")
@Test
@GraphDescription.Graph(nodes = {})
public void drop_constraint() throws Exception {
data.get();
String labelName = labels.newInstance(), propertyKey = properties.newInstance();
ConstraintDefinition constraintDefinition = createLabelUniquenessPropertyConstraint(labelName, propertyKey);
assertThat(getConstraints(graphdb(), label(labelName)), containsOnly(constraintDefinition));
gen.get().expectedStatus(204).delete(getSchemaConstraintLabelUniquenessPropertyUri(labelName, propertyKey)).entity();
assertThat(getConstraints(graphdb(), label(labelName)), isEmpty());
}
Aggregations