Search in sources :

Example 21 with IndexDefinition

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

the class SchemaIndexIT method drop_index.

@Documented("Drop index")
@Test
@GraphDescription.Graph(nodes = {})
public void drop_index() throws Exception {
    data.get();
    String labelName = labels.newInstance(), propertyKey = properties.newInstance();
    IndexDefinition schemaIndex = createIndex(labelName, propertyKey);
    assertThat(Neo4jMatchers.getIndexes(graphdb(), label(labelName)), containsOnly(schemaIndex));
    gen.get().expectedStatus(204).delete(getSchemaIndexLabelPropertyUri(labelName, propertyKey)).entity();
    assertThat(Neo4jMatchers.getIndexes(graphdb(), label(labelName)), not(containsOnly(schemaIndex)));
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 22 with IndexDefinition

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

the class GraphDbHelper method createSchemaIndex.

public IndexDefinition createSchemaIndex(String labelName, String propertyKey) {
    try (Transaction tx = database.getGraph().beginTransaction(implicit, AUTH_DISABLED)) {
        IndexDefinition index = database.getGraph().schema().indexFor(label(labelName)).on(propertyKey).create();
        tx.success();
        return index;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition)

Example 23 with IndexDefinition

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

the class IndexConstraintsTest method getIndex.

private IndexDefinition getIndex(Label label, String propertyKey) {
    try (Transaction tx = graphDb.beginTx()) {
        IndexDefinition found = null;
        for (IndexDefinition index : graphDb.schema().getIndexes(label)) {
            if (propertyKey.equals(single(index.getPropertyKeys()))) {
                assertNull("Found multiple indexes.", found);
                found = index;
            }
        }
        tx.success();
        return found;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition)

Example 24 with IndexDefinition

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

the class IndexConstraintsTest method convertIndexToConstraintWithExistingData.

@Test
public void convertIndexToConstraintWithExistingData() {
    try (Transaction tx = graphDb.beginTx()) {
        for (int i = 0; i < 2000; i++) {
            Node node = graphDb.createNode(LABEL);
            node.setProperty(PROPERTY_KEY, i);
        }
        tx.success();
    }
    try (Transaction tx = graphDb.beginTx()) {
        graphDb.schema().indexFor(LABEL).on(PROPERTY_KEY).create();
        tx.success();
    }
    try (Transaction tx = graphDb.beginTx()) {
        IndexDefinition index = firstOrNull(graphDb.schema().getIndexes(LABEL));
        index.drop();
        graphDb.schema().constraintFor(LABEL).assertPropertyIsUnique(PROPERTY_KEY).create();
        tx.success();
    }
// assert no exception is thrown
}
Also used : Transaction(org.neo4j.graphdb.Transaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 25 with IndexDefinition

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

the class DatabaseActions method dropSchemaIndex.

public boolean dropSchemaIndex(String labelName, String propertyKey) {
    boolean found = false;
    for (IndexDefinition index : graphDb.schema().getIndexes(label(labelName))) {
        // TODO Assumption about single property key
        if (propertyKey.equals(Iterables.single(index.getPropertyKeys()))) {
            index.drop();
            found = true;
            break;
        }
    }
    return found;
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition)

Aggregations

IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)84 Test (org.junit.Test)56 Transaction (org.neo4j.graphdb.Transaction)32 StringContains.containsString (org.hamcrest.core.StringContains.containsString)11 Node (org.neo4j.graphdb.Node)9 Statement (org.neo4j.kernel.api.Statement)7 ArrayList (java.util.ArrayList)4 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)4 Label (org.neo4j.graphdb.Label)4 ReadOperations (org.neo4j.kernel.api.ReadOperations)4 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)4 HighlyAvailableGraphDatabase (org.neo4j.kernel.ha.HighlyAvailableGraphDatabase)4 ManagedCluster (org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster)4 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)3 Iterator (java.util.Iterator)2 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)2 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)2 TransactionData (org.neo4j.graphdb.event.TransactionData)2 TransactionEventHandler (org.neo4j.graphdb.event.TransactionEventHandler)2 ConstraintDefinition (org.neo4j.graphdb.schema.ConstraintDefinition)2