Search in sources :

Example 36 with IndexDefinition

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

the class IndexRecoveryIT method createIndexAndAwaitPopulation.

private void createIndexAndAwaitPopulation(Label label) {
    IndexDefinition index = createIndex(label);
    try (Transaction tx = db.beginTx()) {
        db.schema().awaitIndexOnline(index, 10, SECONDS);
        tx.success();
    }
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Transaction(org.neo4j.graphdb.Transaction)

Example 37 with IndexDefinition

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

the class IndexRestartIT method createIndex.

private IndexDefinition createIndex() {
    try (Transaction tx = db.beginTx()) {
        IndexDefinition index = db.schema().indexFor(myLabel).on("number_of_bananas_owned").create();
        tx.success();
        return index;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition)

Example 38 with IndexDefinition

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

the class IndexSamplingCancellationTest method indexOn.

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

Example 39 with IndexDefinition

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

the class IndexIT method shouldListConstraintIndexesInTheBeansAPI.

@Test
public void shouldListConstraintIndexesInTheBeansAPI() throws Exception {
    // given
    Statement statement = statementInNewTransaction(SecurityContext.AUTH_DISABLED);
    statement.schemaWriteOperations().uniquePropertyConstraintCreate(SchemaDescriptorFactory.forLabel(statement.tokenWriteOperations().labelGetOrCreateForName("Label1"), statement.tokenWriteOperations().propertyKeyGetOrCreateForName("property1")));
    commit();
    // when
    try (Transaction tx = db.beginTx()) {
        Set<IndexDefinition> indexes;
        IndexDefinition index;
        indexes = Iterables.asSet(db.schema().getIndexes());
        // then
        assertEquals(1, indexes.size());
        index = indexes.iterator().next();
        assertEquals("Label1", index.getLabel().name());
        assertEquals(asSet("property1"), Iterables.asSet(index.getPropertyKeys()));
        assertTrue("index should be a constraint index", index.isConstraintIndex());
        // when
        try {
            index.drop();
            fail("expected exception");
        }// then
         catch (IllegalStateException e) {
            assertEquals("Constraint indexes cannot be dropped directly, " + "instead drop the owning uniqueness constraint.", e.getMessage());
        }
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 40 with IndexDefinition

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

the class IndexStatisticsIT method indexAliensBySpecimen.

private IndexDefinition indexAliensBySpecimen() {
    try (Transaction tx = db.beginTx()) {
        IndexDefinition definition = db.schema().indexFor(ALIEN).on(SPECIMEN).create();
        tx.success();
        return definition;
    }
}
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