Search in sources :

Example 1 with ConstraintDefinitionRepresentation

use of org.neo4j.server.rest.repr.ConstraintDefinitionRepresentation 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);
}
Also used : ConstraintCreator(org.neo4j.graphdb.schema.ConstraintCreator) ConstraintDefinitionRepresentation(org.neo4j.server.rest.repr.ConstraintDefinitionRepresentation) ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition)

Example 2 with ConstraintDefinitionRepresentation

use of org.neo4j.server.rest.repr.ConstraintDefinitionRepresentation in project neo4j by neo4j.

the class TransactionWrappedDatabaseActions method createPropertyUniquenessConstraint.

@Override
public ConstraintDefinitionRepresentation createPropertyUniquenessConstraint(String labelName, Iterable<String> propertyKeys) {
    try (Transaction transaction = graph.beginTx()) {
        ConstraintDefinitionRepresentation constraintDefinitionRepresentation = super.createPropertyUniquenessConstraint(labelName, propertyKeys);
        transaction.success();
        return constraintDefinitionRepresentation;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) ConstraintDefinitionRepresentation(org.neo4j.server.rest.repr.ConstraintDefinitionRepresentation)

Aggregations

ConstraintDefinitionRepresentation (org.neo4j.server.rest.repr.ConstraintDefinitionRepresentation)2 Transaction (org.neo4j.graphdb.Transaction)1 ConstraintCreator (org.neo4j.graphdb.schema.ConstraintCreator)1 ConstraintDefinition (org.neo4j.graphdb.schema.ConstraintDefinition)1