Search in sources :

Example 11 with ConstraintDefinition

use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.

the class SchemaWithPECAcceptanceTest method shouldListAddedConstraints.

@Test
public void shouldListAddedConstraints() throws Exception {
    // GIVEN
    ConstraintDefinition constraint1 = createUniquenessConstraint(label, propertyKey);
    ConstraintDefinition constraint2 = createNodePropertyExistenceConstraint(label, propertyKey);
    ConstraintDefinition constraint3 = createRelationshipPropertyExistenceConstraint(Types.MY_TYPE, propertyKey);
    // WHEN THEN
    assertThat(getConstraints(db), containsOnly(constraint1, constraint2, constraint3));
}
Also used : UniquenessConstraintDefinition(org.neo4j.kernel.impl.coreapi.schema.UniquenessConstraintDefinition) RelationshipPropertyExistenceConstraintDefinition(org.neo4j.kernel.impl.coreapi.schema.RelationshipPropertyExistenceConstraintDefinition) ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition) NodePropertyExistenceConstraintDefinition(org.neo4j.kernel.impl.coreapi.schema.NodePropertyExistenceConstraintDefinition) Test(org.junit.Test)

Example 12 with ConstraintDefinition

use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.

the class SchemaWithPECAcceptanceTest method shouldCreateRelationshipPropertyExistenceConstraint.

@Test
public void shouldCreateRelationshipPropertyExistenceConstraint() {
    // When
    ConstraintDefinition constraint = createRelationshipPropertyExistenceConstraint(Types.MY_TYPE, propertyKey);
    // Then
    assertThat(getConstraints(db), containsOnly(constraint));
}
Also used : UniquenessConstraintDefinition(org.neo4j.kernel.impl.coreapi.schema.UniquenessConstraintDefinition) RelationshipPropertyExistenceConstraintDefinition(org.neo4j.kernel.impl.coreapi.schema.RelationshipPropertyExistenceConstraintDefinition) ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition) NodePropertyExistenceConstraintDefinition(org.neo4j.kernel.impl.coreapi.schema.NodePropertyExistenceConstraintDefinition) Test(org.junit.Test)

Example 13 with ConstraintDefinition

use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.

the class SchemaWithPECAcceptanceTest method shouldListAddedConstraintsByLabel.

@Test
public void shouldListAddedConstraintsByLabel() throws Exception {
    // GIVEN
    ConstraintDefinition constraint1 = createUniquenessConstraint(label, propertyKey);
    ConstraintDefinition constraint2 = createNodePropertyExistenceConstraint(label, propertyKey);
    createNodePropertyExistenceConstraint(Labels.MY_OTHER_LABEL, propertyKey);
    // WHEN THEN
    assertThat(getConstraints(db, label), containsOnly(constraint1, constraint2));
}
Also used : UniquenessConstraintDefinition(org.neo4j.kernel.impl.coreapi.schema.UniquenessConstraintDefinition) RelationshipPropertyExistenceConstraintDefinition(org.neo4j.kernel.impl.coreapi.schema.RelationshipPropertyExistenceConstraintDefinition) ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition) NodePropertyExistenceConstraintDefinition(org.neo4j.kernel.impl.coreapi.schema.NodePropertyExistenceConstraintDefinition) Test(org.junit.Test)

Example 14 with ConstraintDefinition

use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.

the class SchemaWithPECAcceptanceTest method shouldCreateNodePropertyExistenceConstraint.

@Test
public void shouldCreateNodePropertyExistenceConstraint() {
    // When
    ConstraintDefinition constraint = createNodePropertyExistenceConstraint(label, propertyKey);
    // Then
    assertThat(getConstraints(db), containsOnly(constraint));
}
Also used : UniquenessConstraintDefinition(org.neo4j.kernel.impl.coreapi.schema.UniquenessConstraintDefinition) RelationshipPropertyExistenceConstraintDefinition(org.neo4j.kernel.impl.coreapi.schema.RelationshipPropertyExistenceConstraintDefinition) ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition) NodePropertyExistenceConstraintDefinition(org.neo4j.kernel.impl.coreapi.schema.NodePropertyExistenceConstraintDefinition) Test(org.junit.Test)

Example 15 with ConstraintDefinition

use of org.neo4j.graphdb.schema.ConstraintDefinition in project neo4j by neo4j.

the class IndexConstraintsTest method convertConstraintToIndex.

@Test
public void convertConstraintToIndex() {
    try (Transaction tx = graphDb.beginTx()) {
        graphDb.schema().constraintFor(LABEL).assertPropertyIsUnique(PROPERTY_KEY).create();
        tx.success();
    }
    try (Transaction tx = graphDb.beginTx()) {
        ConstraintDefinition constraint = firstOrNull(graphDb.schema().getConstraints(LABEL));
        constraint.drop();
        graphDb.schema().indexFor(LABEL).on(PROPERTY_KEY).create();
        tx.success();
    }
// assert no exception is thrown
}
Also used : Transaction(org.neo4j.graphdb.Transaction) ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition) Test(org.junit.Test)

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