Search in sources :

Example 16 with IndexCreator

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

the class Neo4jMatchers method createIndexNoWait.

public static IndexDefinition createIndexNoWait(GraphDatabaseService beansAPI, Label label, String... properties) {
    IndexDefinition indexDef;
    try (Transaction tx = beansAPI.beginTx()) {
        IndexCreator indexCreator = beansAPI.schema().indexFor(label);
        for (String property : properties) {
            indexCreator = indexCreator.on(property);
        }
        indexDef = indexCreator.create();
        tx.success();
    }
    return indexDef;
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Transaction(org.neo4j.graphdb.Transaction) IndexCreator(org.neo4j.graphdb.schema.IndexCreator)

Example 17 with IndexCreator

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

the class StringLengthIndexValidationIT method createIndex.

private long createIndex(String... keys) {
    long indexId;
    try (Transaction tx = db.beginTx()) {
        IndexCreator indexCreator = tx.schema().indexFor(LABEL_ONE);
        for (String key : keys) {
            indexCreator = indexCreator.on(key);
        }
        var index = indexCreator.create();
        indexId = getIndexIdFrom(index);
        tx.commit();
    }
    try (Transaction tx = db.beginTx()) {
        tx.schema().awaitIndexesOnline(2, MINUTES);
        tx.commit();
    }
    return indexId;
}
Also used : Transaction(org.neo4j.graphdb.Transaction) IndexCreator(org.neo4j.graphdb.schema.IndexCreator)

Example 18 with IndexCreator

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

the class SchemaAcceptanceTest method tokenIndexCreatorThrowsOnProperty.

@Test
void tokenIndexCreatorThrowsOnProperty() {
    try (var tx = db.beginTx()) {
        IndexCreator indexCreator = tx.schema().indexFor(AnyTokens.ANY_LABELS);
        assertThatThrownBy(() -> indexCreator.on("property")).isInstanceOf(ConstraintViolationException.class).hasMessageContaining("LOOKUP indexes doesn't support inclusion of property keys.");
    }
}
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 19 with IndexCreator

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

the class SchemaAcceptanceTest method tokenIndexCreatorThrowsOnUnsupportedIndexTypes.

@Test
void tokenIndexCreatorThrowsOnUnsupportedIndexTypes() {
    try (var tx = db.beginTx()) {
        IndexCreator indexCreator = tx.schema().indexFor(AnyTokens.ANY_LABELS);
        assertThatThrownBy(() -> indexCreator.withIndexType(IndexType.BTREE)).isInstanceOf(ConstraintViolationException.class).hasMessageContaining("Only LOOKUP index type supported for token indexes.");
        assertThatThrownBy(() -> indexCreator.withIndexType(IndexType.FULLTEXT)).isInstanceOf(ConstraintViolationException.class).hasMessageContaining("Only LOOKUP index type supported for token 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 20 with IndexCreator

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

the class IndexProviderApprovalTest method createIndex.

private static void createIndex(GraphDatabaseService db, Label label, String... properties) {
    IndexDefinition indexDef;
    try (Transaction tx = db.beginTx()) {
        IndexCreator indexCreator = tx.schema().indexFor(label);
        for (String property : properties) {
            indexCreator = indexCreator.on(property);
        }
        indexDef = indexCreator.create();
        tx.commit();
    }
    try (Transaction tx = db.beginTx()) {
        tx.schema().awaitIndexOnline(indexDef, 1, MINUTES);
    }
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Transaction(org.neo4j.graphdb.Transaction) IndexCreator(org.neo4j.graphdb.schema.IndexCreator)

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