Search in sources :

Example 76 with IndexDefinition

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

the class DatabaseActions method getSchemaIndexes.

public ListRepresentation getSchemaIndexes(String labelName) {
    Iterable<IndexDefinition> definitions = graphDb.schema().getIndexes(label(labelName));
    Iterable<IndexDefinitionRepresentation> representations = map(new Function<IndexDefinition, IndexDefinitionRepresentation>() {

        @Override
        public IndexDefinitionRepresentation apply(IndexDefinition definition) {
            return new IndexDefinitionRepresentation(definition, graphDb.schema().getIndexState(definition), graphDb.schema().getIndexPopulationProgress(definition));
        }
    }, definitions);
    return new ListRepresentation(RepresentationType.INDEX_DEFINITION, representations);
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) IndexDefinitionRepresentation(org.neo4j.server.rest.repr.IndexDefinitionRepresentation) ListRepresentation(org.neo4j.server.rest.repr.ListRepresentation)

Example 77 with IndexDefinition

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

the class SchemaIndexIT method createIndex.

private IndexDefinition createIndex(String labelName, String propertyKey) {
    try (Transaction tx = graphdb().beginTx()) {
        IndexDefinition indexDefinition = graphdb().schema().indexFor(label(labelName)).on(propertyKey).create();
        tx.success();
        return indexDefinition;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition)

Example 78 with IndexDefinition

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

the class SchemaIndexRepresentationTest method shouldIncludeLabel.

@Test
public void shouldIncludeLabel() throws Exception {
    // GIVEN
    String labelName = "person", propertyKey = "name";
    IndexDefinition definition = mock(IndexDefinition.class);
    when(definition.getLabel()).thenReturn(label(labelName));
    when(definition.getPropertyKeys()).thenReturn(asList(propertyKey));
    IndexDefinitionRepresentation representation = new IndexDefinitionRepresentation(definition);
    Map<String, Object> serialized = RepresentationTestAccess.serialize(representation);
    // THEN
    assertEquals(asList(propertyKey), serialized.get("property_keys"));
    assertEquals(labelName, serialized.get("label"));
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Test(org.junit.Test)

Example 79 with IndexDefinition

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

the class DatabaseActionsTest method shouldDropSchemaIndex.

@Test
public void shouldDropSchemaIndex() throws Exception {
    // GIVEN
    String labelName = "user", propertyKey = "login";
    IndexDefinition index = graphdbHelper.createSchemaIndex(labelName, propertyKey);
    // WHEN
    actions.dropSchemaIndex(labelName, propertyKey);
    // THEN
    try (Transaction transaction = graph.beginTx()) {
        assertFalse("Index should have been dropped", Iterables.asSet(graphdbHelper.getSchemaIndexes(labelName)).contains(index));
    }
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Transaction(org.neo4j.graphdb.Transaction) NodeRepresentationTest(org.neo4j.server.rest.repr.NodeRepresentationTest) RelationshipRepresentationTest(org.neo4j.server.rest.repr.RelationshipRepresentationTest) Test(org.junit.Test)

Example 80 with IndexDefinition

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

the class IndexRecoveryIT method createIndex.

private IndexDefinition createIndex(Label label) {
    try (Transaction tx = db.beginTx()) {
        IndexDefinition index = db.schema().indexFor(label).on(key).create();
        tx.success();
        return index;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) 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