Search in sources :

Example 81 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 82 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 83 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 84 with IndexDefinition

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

the class DatabaseActionsTest method shouldCreateSchemaIndex.

@Test
public void shouldCreateSchemaIndex() throws Exception {
    // GIVEN
    String labelName = "person", propertyKey = "name";
    // WHEN
    actions.createSchemaIndex(labelName, Arrays.asList(propertyKey));
    // THEN
    try (Transaction transaction = graph.beginTx()) {
        Iterable<IndexDefinition> defs = graphdbHelper.getSchemaIndexes(labelName);
        assertEquals(1, Iterables.count(defs));
        assertEquals(propertyKey, firstOrNull(firstOrNull(defs).getPropertyKeys()));
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) NodeRepresentationTest(org.neo4j.server.rest.repr.NodeRepresentationTest) RelationshipRepresentationTest(org.neo4j.server.rest.repr.RelationshipRepresentationTest) 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