Search in sources :

Example 16 with ConstraintDefinition

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;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition)

Example 17 with ConstraintDefinition

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);
}
Also used : RelationshipType(org.neo4j.graphdb.RelationshipType) ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition)

Example 18 with ConstraintDefinition

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;
}
Also used : ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition)

Example 19 with ConstraintDefinition

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;
}
Also used : ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition)

Example 20 with ConstraintDefinition

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

Aggregations

ConstraintDefinition (org.neo4j.graphdb.schema.ConstraintDefinition)34 Test (org.junit.Test)16 Transaction (org.neo4j.graphdb.Transaction)12 NodePropertyExistenceConstraintDefinition (org.neo4j.kernel.impl.coreapi.schema.NodePropertyExistenceConstraintDefinition)5 RelationshipPropertyExistenceConstraintDefinition (org.neo4j.kernel.impl.coreapi.schema.RelationshipPropertyExistenceConstraintDefinition)5 UniquenessConstraintDefinition (org.neo4j.kernel.impl.coreapi.schema.UniquenessConstraintDefinition)5 NodeRepresentationTest (org.neo4j.server.rest.repr.NodeRepresentationTest)3 RelationshipRepresentationTest (org.neo4j.server.rest.repr.RelationshipRepresentationTest)3 ArrayList (java.util.ArrayList)2 ConstraintCreator (org.neo4j.graphdb.schema.ConstraintCreator)2 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)2 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)2 BatchInserter (org.neo4j.unsafe.batchinsert.BatchInserter)2 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)1 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)1 Label (org.neo4j.graphdb.Label)1 RelationshipType (org.neo4j.graphdb.RelationshipType)1 Schema (org.neo4j.graphdb.schema.Schema)1 ConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor)1 Documented (org.neo4j.kernel.impl.annotations.Documented)1