Search in sources :

Example 21 with ReadOperations

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

the class PropertyIT method shouldRemoveSetNodePropertyAcrossTransactions.

@Test
public void shouldRemoveSetNodePropertyAcrossTransactions() throws Exception {
    // GIVEN
    int propertyKeyId;
    long nodeId;
    {
        Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
        nodeId = statement.dataWriteOperations().nodeCreate();
        propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("clown");
        statement.dataWriteOperations().nodeSetProperty(nodeId, stringProperty(propertyKeyId, "bozo"));
        commit();
    }
    {
        Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
        // WHEN
        Object previous = statement.dataWriteOperations().nodeRemoveProperty(nodeId, propertyKeyId).value();
        // THEN
        assertEquals("bozo", previous);
        assertThat(statement.readOperations().nodeGetProperty(nodeId, propertyKeyId), nullValue());
        // WHEN
        commit();
    }
    // THEN
    ReadOperations readOperations = readOperationsInNewTransaction();
    assertThat(readOperations.nodeGetProperty(nodeId, propertyKeyId), nullValue());
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 22 with ReadOperations

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

the class MultiIndexPopulationConcurrentUpdatesIT method getLabelIdsByName.

private Map<String, Integer> getLabelIdsByName(String... names) {
    ThreadToStatementContextBridge transactionStatementContextBridge = getTransactionStatementContextBridge();
    ReadOperations readOperations = transactionStatementContextBridge.get().readOperations();
    Map<String, Integer> labelNameIdMap = new HashMap<>();
    for (String name : names) {
        labelNameIdMap.put(name, readOperations.labelGetForName(name));
    }
    return labelNameIdMap;
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) HashMap(java.util.HashMap) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)

Example 23 with ReadOperations

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

the class MultiIndexPopulationConcurrentUpdatesIT method getPropertyIdByName.

private int getPropertyIdByName(String name) {
    ThreadToStatementContextBridge transactionStatementContextBridge = getTransactionStatementContextBridge();
    ReadOperations readOperations = transactionStatementContextBridge.get().readOperations();
    return readOperations.propertyKeyGetForName(name);
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)

Example 24 with ReadOperations

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

the class IndexSamplingIntegrationTest method indexId.

private long indexId(GraphDatabaseAPI api) throws IndexNotFoundKernelException {
    try (Transaction tx = api.beginTx()) {
        IndexingService indexingService = api.getDependencyResolver().resolveDependency(IndexingService.class);
        ReadOperations readOperations = api.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class).get().readOperations();
        int labelId = readOperations.labelGetForName(label.name());
        int propertyKeyId = readOperations.propertyKeyGetForName(property);
        long indexId = indexingService.getIndexId(SchemaDescriptorFactory.forLabel(labelId, propertyKeyId));
        tx.success();
        return indexId;
    }
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) Transaction(org.neo4j.graphdb.Transaction) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService)

Example 25 with ReadOperations

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

the class CompiledExpandUtilsTest method shouldUseGivenOrderIfItHasLowerDegreeWithTypes.

@Test
public void shouldUseGivenOrderIfItHasLowerDegreeWithTypes() throws EntityNotFoundException {
    // GIVEN
    ReadOperations readOperations = mock(ReadOperations.class);
    when(readOperations.nodeGetDegree(1L, Direction.OUTGOING, 1)).thenReturn(1);
    when(readOperations.nodeGetDegree(2L, Direction.INCOMING, 1)).thenReturn(3);
    // WHEN
    connectingRelationships(readOperations, 1L, Direction.OUTGOING, 2L, new int[] { 1 });
    // THEN
    verify(readOperations, times(1)).nodeGetRelationships(1L, Direction.OUTGOING, new int[] { 1 });
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) 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