Search in sources :

Example 11 with IndexCreator

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

the class SchemaAcceptanceTest method constraintAndIndexNamesInTransactionStateMustBeUnique.

@Test
void constraintAndIndexNamesInTransactionStateMustBeUnique() {
    try (Transaction tx = db.beginTx()) {
        tx.schema().constraintFor(label).assertPropertyIsUnique(propertyKey).withName("MySchema").create();
        IndexCreator creator = tx.schema().indexFor(otherLabel).on(secondPropertyKey).withName("MySchema");
        ConstraintViolationException exception = assertThrows(ConstraintViolationException.class, creator::create);
        assertThat(exception).hasMessageContaining("MySchema");
        tx.commit();
    }
}
Also used : IndexCreator(org.neo4j.graphdb.schema.IndexCreator) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with IndexCreator

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

the class SchemaAcceptanceTest method indexCreatorThrowsOnUnsupportedIndexType.

@Test
void indexCreatorThrowsOnUnsupportedIndexType() {
    try (var tx = db.beginTx()) {
        IndexCreator indexCreator = tx.schema().indexFor(label).withName("my_index").on(propertyKey);
        assertThatThrownBy(() -> indexCreator.withIndexType(IndexType.LOOKUP).create()).isInstanceOf(ConstraintViolationException.class).hasMessageContaining("Index type LOOKUP is not supported for property indexes.");
    }
}
Also used : IndexCreator(org.neo4j.graphdb.schema.IndexCreator) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with IndexCreator

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

the class SchemaAcceptanceTest method createIndex.

public static IndexDefinition createIndex(GraphDatabaseService db, AnyTokens tokens, String name) {
    IndexDefinition index;
    try (var tx = db.beginTx()) {
        IndexCreator creator = tx.schema().indexFor(tokens);
        if (name != null) {
            creator = creator.withName(name);
        }
        index = creator.create();
        tx.commit();
    }
    waitForIndex(db, index);
    return index;
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) IndexCreator(org.neo4j.graphdb.schema.IndexCreator)

Example 14 with IndexCreator

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

the class SchemaAcceptanceTest method indexNamesCanContainBackTicks.

@Test
void indexNamesCanContainBackTicks() {
    try (Transaction tx = db.beginTx()) {
        IndexCreator creator = tx.schema().indexFor(label).withName("`a`b``").on(propertyKey);
        creator.create();
        tx.commit();
    }
    try (Transaction tx = db.beginTx()) {
        final Iterable<IndexDefinition> indexes = tx.schema().getIndexes();
        assertThat(count(indexes)).isEqualTo(1L);
        assertEquals("`a`b``", indexes.iterator().next().getName());
        assertThat(count(tx.schema().getConstraints())).isEqualTo(0L);
        tx.commit();
    }
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) IndexCreator(org.neo4j.graphdb.schema.IndexCreator) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with IndexCreator

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

the class SchemaAcceptanceTest method indexNamesInTransactionStateMustBeUnique.

@Test
void indexNamesInTransactionStateMustBeUnique() {
    try (Transaction tx = db.beginTx()) {
        final String indexName = "MyIndex";
        tx.schema().indexFor(label).on(propertyKey).withName(indexName).create();
        IndexCreator creator = tx.schema().indexFor(otherLabel).on(secondPropertyKey).withName(indexName);
        ConstraintViolationException exception = assertThrows(ConstraintViolationException.class, creator::create);
        assertThat(exception).hasMessageContaining(alreadyExistsIndexMessage(indexName));
        tx.commit();
    }
}
Also used : IndexCreator(org.neo4j.graphdb.schema.IndexCreator) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

IndexCreator (org.neo4j.graphdb.schema.IndexCreator)29 Test (org.junit.jupiter.api.Test)17 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)15 RepeatedTest (org.junit.jupiter.api.RepeatedTest)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 Transaction (org.neo4j.graphdb.Transaction)10 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)5 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)5 ResourceLock (org.junit.jupiter.api.parallel.ResourceLock)4 Schema (org.neo4j.graphdb.schema.Schema)4 Label (org.neo4j.graphdb.Label)2 SystemProcedure (org.neo4j.kernel.api.procedure.SystemProcedure)2 Description (org.neo4j.procedure.Description)2 Procedure (org.neo4j.procedure.Procedure)2 ExecutionException (java.util.concurrent.ExecutionException)1 Test (org.junit.Test)1 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)1 RelationshipType (org.neo4j.graphdb.RelationshipType)1 ConstraintCreator (org.neo4j.graphdb.schema.ConstraintCreator)1 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)1