Search in sources :

Example 1 with ConstraintDefinition

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

Example 2 with ConstraintDefinition

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

Example 3 with ConstraintDefinition

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

Example 4 with 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;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition)

Example 5 with ConstraintDefinition

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());
}
Also used : ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Aggregations

ConstraintDefinition (org.neo4j.graphdb.schema.ConstraintDefinition)69 Transaction (org.neo4j.graphdb.Transaction)25 Test (org.junit.Test)18 Test (org.junit.jupiter.api.Test)18 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)18 RepeatedTest (org.junit.jupiter.api.RepeatedTest)16 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)13 ConstraintCreator (org.neo4j.graphdb.schema.ConstraintCreator)7 ArrayList (java.util.ArrayList)5 Schema (org.neo4j.graphdb.schema.Schema)5 NodePropertyExistenceConstraintDefinition (org.neo4j.kernel.impl.coreapi.schema.NodePropertyExistenceConstraintDefinition)5 RelationshipPropertyExistenceConstraintDefinition (org.neo4j.kernel.impl.coreapi.schema.RelationshipPropertyExistenceConstraintDefinition)5 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)4 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)4 UniquenessConstraintDefinition (org.neo4j.kernel.impl.coreapi.schema.UniquenessConstraintDefinition)4 Label (org.neo4j.graphdb.Label)3 NodeRepresentationTest (org.neo4j.server.rest.repr.NodeRepresentationTest)3 RelationshipRepresentationTest (org.neo4j.server.rest.repr.RelationshipRepresentationTest)3 AssertSchemaResult (apoc.result.AssertSchemaResult)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2