Search in sources :

Example 41 with ConstraintDefinition

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

the class SchemaAcceptanceTest method shouldListAddedConstraints.

@Test
void shouldListAddedConstraints() {
    // GIVEN
    ConstraintDefinition constraint1 = createUniquenessConstraint(label, propertyKey);
    ConstraintDefinition constraint2 = createUniquenessConstraint(otherLabel, propertyKey);
    // WHEN THEN
    try (Transaction tx = db.beginTx()) {
        assertThat(tx.schema().getConstraints()).containsOnly(constraint1, constraint2);
    }
}
Also used : ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 42 with ConstraintDefinition

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

the class SchemaAcceptanceTest method cannotCreateIndexWithSameNameAsExistingConstraintWithGeneratedName.

@Test
void cannotCreateIndexWithSameNameAsExistingConstraintWithGeneratedName() {
    ConstraintDefinition constraint = createUniquenessConstraint(label, propertyKey);
    ConstraintViolationException exception = assertThrows(ConstraintViolationException.class, () -> createIndex(db, constraint.getName(), label, secondPropertyKey));
    assertThat(exception).hasMessageContaining(constraint.getName());
}
Also used : ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 43 with ConstraintDefinition

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

the class SchemaAcceptanceTest method uniquenessConstraintIndexesAreBtreeIndexTypeByDefault.

@Test
void uniquenessConstraintIndexesAreBtreeIndexTypeByDefault() {
    String name;
    try (Transaction tx = db.beginTx()) {
        ConstraintDefinition constraint = tx.schema().constraintFor(label).assertPropertyIsUnique(propertyKey).create();
        name = constraint.getName();
        IndexDefinition index = getIndex(tx, name);
        assertThat(index.getIndexType()).isEqualTo(BTREE);
        tx.commit();
    }
    try (Transaction tx = db.beginTx()) {
        IndexDefinition index = getIndex(tx, name);
        assertThat(index.getIndexType()).isEqualTo(BTREE);
    }
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 44 with ConstraintDefinition

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

the class SchemaImpl method asConstraintDefinitions.

private Iterable<ConstraintDefinition> asConstraintDefinitions(Iterator<? extends ConstraintDescriptor> constraints, TokenRead tokenRead) {
    // Intentionally create an eager list so that used statement can be closed
    List<ConstraintDefinition> definitions = new ArrayList<>();
    while (constraints.hasNext()) {
        ConstraintDescriptor constraint = constraints.next();
        definitions.add(asConstraintDefinition(constraint, tokenRead));
    }
    return definitions;
}
Also used : ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) ArrayList(java.util.ArrayList) ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition)

Example 45 with ConstraintDefinition

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

the class SchemaImpl method asConstraintDefinitions.

private Iterable<ConstraintDefinition> asConstraintDefinitions(Iterator<? extends ConstraintDescriptor> constraints, ReadOperations readOperations) {
    // Intentionally create an eager list so that used statement can be closed
    List<ConstraintDefinition> definitions = new ArrayList<>();
    while (constraints.hasNext()) {
        ConstraintDescriptor constraint = constraints.next();
        definitions.add(asConstraintDefinition(ConstraintBoundary.map(constraint), readOperations));
    }
    return definitions;
}
Also used : ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) ArrayList(java.util.ArrayList) ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition)

Aggregations

ConstraintDefinition (org.neo4j.graphdb.schema.ConstraintDefinition)70 Transaction (org.neo4j.graphdb.Transaction)26 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)14 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