Search in sources :

Example 41 with ReadOperations

use of org.neo4j.kernel.api.ReadOperations in project neo4j by neo4j.

the class SchemaImpl method getIndexPopulationProgress.

@Override
public IndexPopulationProgress getIndexPopulationProgress(IndexDefinition index) {
    actions.assertInOpenTransaction();
    try (Statement statement = statementContextSupplier.get()) {
        ReadOperations readOps = statement.readOperations();
        NewIndexDescriptor descriptor = getIndexDescriptor(readOps, index);
        PopulationProgress progress = readOps.indexGetPopulationProgress(descriptor);
        return new IndexPopulationProgress(progress.getCompleted(), progress.getTotal());
    } catch (SchemaRuleNotFoundException | IndexNotFoundKernelException e) {
        throw new NotFoundException(format("No index for label %s on property %s", index.getLabel().name(), index.getPropertyKeys()));
    }
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) KeyReadOperations(org.neo4j.kernel.impl.api.operations.KeyReadOperations) IndexPopulationProgress(org.neo4j.graphdb.index.IndexPopulationProgress) PopulationProgress(org.neo4j.storageengine.api.schema.PopulationProgress) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Statement(org.neo4j.kernel.api.Statement) IndexPopulationProgress(org.neo4j.graphdb.index.IndexPopulationProgress) NotFoundException(org.neo4j.graphdb.NotFoundException) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)

Example 42 with ReadOperations

use of org.neo4j.kernel.api.ReadOperations in project neo4j by neo4j.

the class SchemaImpl method getIndexState.

@Override
public IndexState getIndexState(final IndexDefinition index) {
    actions.assertInOpenTransaction();
    try (Statement statement = statementContextSupplier.get()) {
        ReadOperations readOps = statement.readOperations();
        NewIndexDescriptor descriptor = getIndexDescriptor(readOps, index);
        InternalIndexState indexState = readOps.indexGetState(descriptor);
        switch(indexState) {
            case POPULATING:
                return POPULATING;
            case ONLINE:
                return ONLINE;
            case FAILED:
                return FAILED;
            default:
                throw new IllegalArgumentException(String.format("Illegal index state %s", indexState));
        }
    } catch (SchemaRuleNotFoundException | IndexNotFoundKernelException e) {
        throw new NotFoundException(format("No index for label %s on property %s", index.getLabel().name(), index.getPropertyKeys()));
    }
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) KeyReadOperations(org.neo4j.kernel.impl.api.operations.KeyReadOperations) InternalIndexState(org.neo4j.kernel.api.index.InternalIndexState) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Statement(org.neo4j.kernel.api.Statement) NotFoundException(org.neo4j.graphdb.NotFoundException) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)

Example 43 with ReadOperations

use of org.neo4j.kernel.api.ReadOperations in project neo4j by neo4j.

the class SchemaImpl method getIndexFailure.

@Override
public String getIndexFailure(IndexDefinition index) {
    actions.assertInOpenTransaction();
    try (Statement statement = statementContextSupplier.get()) {
        ReadOperations readOps = statement.readOperations();
        NewIndexDescriptor descriptor = getIndexDescriptor(readOps, index);
        return readOps.indexGetFailure(descriptor);
    } catch (SchemaRuleNotFoundException | IndexNotFoundKernelException e) {
        throw new NotFoundException(format("No index for label %s on property %s", index.getLabel().name(), index.getPropertyKeys()));
    }
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) KeyReadOperations(org.neo4j.kernel.impl.api.operations.KeyReadOperations) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Statement(org.neo4j.kernel.api.Statement) NotFoundException(org.neo4j.graphdb.NotFoundException) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)

Example 44 with ReadOperations

use of org.neo4j.kernel.api.ReadOperations in project neo4j by neo4j.

the class IndexingAcceptanceTest method shouldConsiderNodesChangedInSameTxInIndexPrefixSearch.

@Test
public void shouldConsiderNodesChangedInSameTxInIndexPrefixSearch() throws SchemaRuleNotFoundException, IndexNotFoundKernelException, IndexNotApplicableKernelException {
    // GIVEN
    GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
    IndexDefinition index = Neo4jMatchers.createIndex(db, LABEL1, "name");
    createNodes(db, LABEL1, "name", "Mattias");
    PrimitiveLongSet toChangeToMatch = createNodes(db, LABEL1, "name", "Mats");
    PrimitiveLongSet toChangeToNotMatch = createNodes(db, LABEL1, "name", "Karlsson");
    PrimitiveLongSet expected = createNodes(db, LABEL1, "name", "Karl");
    String prefix = "Karl";
    // WHEN
    PrimitiveLongSet found = Primitive.longSet();
    try (Transaction tx = db.beginTx()) {
        PrimitiveLongIterator toMatching = toChangeToMatch.iterator();
        while (toMatching.hasNext()) {
            long id = toMatching.next();
            db.getNodeById(id).setProperty("name", prefix + "X" + id);
            expected.add(id);
        }
        PrimitiveLongIterator toNotMatching = toChangeToNotMatch.iterator();
        while (toNotMatching.hasNext()) {
            long id = toNotMatching.next();
            db.getNodeById(id).setProperty("name", "X" + id);
            expected.remove(id);
        }
        Statement statement = getStatement((GraphDatabaseAPI) db);
        ReadOperations readOperations = statement.readOperations();
        NewIndexDescriptor descriptor = indexDescriptor(readOperations, index);
        int propertyKeyId = descriptor.schema().getPropertyId();
        found.addAll(readOperations.indexQuery(descriptor, stringPrefix(propertyKeyId, prefix)));
    }
    // THEN
    assertThat(found, equalTo(expected));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) ReadOperations(org.neo4j.kernel.api.ReadOperations) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 45 with ReadOperations

use of org.neo4j.kernel.api.ReadOperations in project neo4j by neo4j.

the class IndexingAcceptanceTest method shouldIncludeNodesCreatedInSameTxInIndexSeekByPrefix.

@Test
public void shouldIncludeNodesCreatedInSameTxInIndexSeekByPrefix() throws SchemaRuleNotFoundException, IndexNotFoundKernelException, IndexNotApplicableKernelException {
    // GIVEN
    GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
    IndexDefinition index = Neo4jMatchers.createIndex(db, LABEL1, "name");
    createNodes(db, LABEL1, "name", "Mattias", "Mats");
    PrimitiveLongSet expected = createNodes(db, LABEL1, "name", "Carl", "Carlsson");
    // WHEN
    PrimitiveLongSet found = Primitive.longSet();
    try (Transaction tx = db.beginTx()) {
        expected.add(createNode(db, map("name", "Carlchen"), LABEL1).getId());
        createNode(db, map("name", "Karla"), LABEL1);
        Statement statement = getStatement((GraphDatabaseAPI) db);
        ReadOperations readOperations = statement.readOperations();
        NewIndexDescriptor descriptor = indexDescriptor(readOperations, index);
        int propertyKeyId = descriptor.schema().getPropertyId();
        found.addAll(readOperations.indexQuery(descriptor, stringPrefix(propertyKeyId, "Carl")));
    }
    // THEN
    assertThat(found, equalTo(expected));
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Aggregations

ReadOperations (org.neo4j.kernel.api.ReadOperations)73 Test (org.junit.Test)52 Statement (org.neo4j.kernel.api.Statement)37 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)22 SchemaWriteOperations (org.neo4j.kernel.api.SchemaWriteOperations)9 KeyReadOperations (org.neo4j.kernel.impl.api.operations.KeyReadOperations)8 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)7 NotFoundException (org.neo4j.graphdb.NotFoundException)5 Transaction (org.neo4j.graphdb.Transaction)5 HashMap (java.util.HashMap)4 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)4 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)4 DataWriteOperations (org.neo4j.kernel.api.DataWriteOperations)4 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)4 ArrayList (java.util.ArrayList)3 Set (java.util.Set)3 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)3 Label (org.neo4j.graphdb.Label)3 RelationshipType (org.neo4j.graphdb.RelationshipType)3 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)3