Search in sources :

Example 11 with IndexDefinition

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

the class Schema method reportNodeIndexes.

private void reportNodeIndexes(Output out, org.neo4j.graphdb.schema.Schema schema, Label[] labels, String property, boolean verbose) throws RemoteException {
    ColumnPrinter printer = new ColumnPrinter(indent("ON "), "", "");
    Iterable<IndexDefinition> indexes = indexesByLabelAndProperty(schema, labels, property);
    int i = 0;
    for (IndexDefinition index : sort(indexes, LABEL_COMPARE_FUNCTION)) {
        if (i == 0) {
            out.println("Indexes");
        }
        String labelAndProperties = String.format(":%s(%s)", index.getLabel().name(), commaSeparate(index.getPropertyKeys()));
        IndexState state = schema.getIndexState(index);
        String uniqueOrNot = index.isConstraintIndex() ? "(for uniqueness constraint)" : "";
        printer.add(labelAndProperties, state, uniqueOrNot);
        if (verbose && state == IndexState.FAILED) {
            printer.addRaw(schema.getIndexFailure(index));
        }
        i++;
    }
    if (i == 0) {
        out.println("No indexes");
    } else {
        printer.print(out);
    }
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) ColumnPrinter(org.neo4j.shell.ColumnPrinter) IndexState(org.neo4j.graphdb.schema.Schema.IndexState)

Example 12 with IndexDefinition

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

the class AppsIT method canListIndexes.

@Test
public void canListIndexes() throws Exception {
    // GIVEN
    Label label = label("Person");
    beginTx();
    IndexDefinition index = db.schema().indexFor(label).on("name").create();
    finishTx();
    waitForIndex(db, index);
    // WHEN / THEN
    executeCommand("schema ls", ":Person", IndexState.ONLINE.name());
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Test(org.junit.Test)

Example 13 with IndexDefinition

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

the class AppsIT method failSamplingWhenProvidingBadProperty.

@Test
public void failSamplingWhenProvidingBadProperty() throws Exception {
    // GIVEN
    Label label = label("Person");
    String property = "name";
    beginTx();
    IndexDefinition index = db.schema().indexFor(label).on(property).create();
    finishTx();
    waitForIndex(db, index);
    // WHEN / THEN
    try {
        executeCommand("schema sample -l Person -p namn");
        fail("This should fail");
    } catch (ShellException e) {
        assertThat(e.getMessage(), containsString("No property associated with 'namn' was found"));
    }
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.Test)

Example 14 with IndexDefinition

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

the class AppsIT method canSampleAllIndexes.

@Test
public void canSampleAllIndexes() throws Exception {
    // GIVEN
    Label label = label("Person");
    String property = "name";
    beginTx();
    IndexDefinition index = db.schema().indexFor(label).on(property).create();
    finishTx();
    waitForIndex(db, index);
    // WHEN / THEN
    executeCommand("schema sample -a");
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.Test)

Example 15 with IndexDefinition

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

the class AppsIT method failSampleWhenNoOptionGiven.

@Test
public void failSampleWhenNoOptionGiven() throws Exception {
    // GIVEN
    Label label = label("Person");
    String property = "name";
    beginTx();
    IndexDefinition index = db.schema().indexFor(label).on(property).create();
    finishTx();
    waitForIndex(db, index);
    // WHEN / THEN
    try {
        executeCommand("schema sample");
        fail("This should fail");
    } catch (ShellException e) {
        assertThat(e.getMessage(), containsString("Invalid usage of sample"));
    }
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.Test)

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