Search in sources :

Example 71 with ReadOperations

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

the class PropertyIT method shouldBeAbleToSetAndReadLargeByteArray.

@Test
public void shouldBeAbleToSetAndReadLargeByteArray() throws Exception {
    // GIVEN
    Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
    long nodeId = statement.dataWriteOperations().nodeCreate();
    // WHEN
    int propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("clown");
    DefinedProperty property = byteArrayProperty(propertyKeyId, new byte[100_000]);
    statement.dataWriteOperations().nodeSetProperty(nodeId, property);
    // WHEN
    commit();
    ReadOperations readOperations = readOperationsInNewTransaction();
    // THEN
    readOperations.nodeGetProperty(nodeId, propertyKeyId);
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 72 with ReadOperations

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

the class PropertyIT method shouldUpdateNodePropertyValue.

@Test
public void shouldUpdateNodePropertyValue() throws Exception {
    // GIVEN
    Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
    long nodeId = statement.dataWriteOperations().nodeCreate();
    int propertyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("clown");
    statement.dataWriteOperations().nodeSetProperty(nodeId, stringProperty(propertyId, "bozo"));
    commit();
    // WHEN
    DataWriteOperations dataWriteOperations = dataWriteOperationsInNewTransaction();
    dataWriteOperations.nodeSetProperty(nodeId, Property.intProperty(propertyId, 42));
    commit();
    // THEN
    ReadOperations readOperations = readOperationsInNewTransaction();
    assertEquals(42, readOperations.nodeGetProperty(nodeId, propertyId));
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) DataWriteOperations(org.neo4j.kernel.api.DataWriteOperations) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 73 with ReadOperations

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

the class NodeProxySingleRelationshipTest method mockNodeWithRels.

private NodeProxy mockNodeWithRels(final long... relIds) throws EntityNotFoundException {
    NodeProxy.NodeActions nodeActions = mock(NodeProxy.NodeActions.class);
    final RelationshipProxy.RelationshipActions relActions = mock(RelationshipProxy.RelationshipActions.class);
    when(nodeActions.newRelationshipProxy(anyLong(), anyLong(), anyInt(), anyLong())).then(invocation -> {
        Long id = (Long) invocation.getArguments()[0];
        Long startNode = (Long) invocation.getArguments()[1];
        Integer type = (Integer) invocation.getArguments()[2];
        Long endNode = (Long) invocation.getArguments()[3];
        return new RelationshipProxy(relActions, id, startNode, type, endNode);
    });
    GraphDatabaseService gds = mock(GraphDatabaseService.class);
    when(gds.getRelationshipById(REL_ID)).thenReturn(mock(Relationship.class));
    when(gds.getRelationshipById(REL_ID + 1)).thenReturn(mock(Relationship.class));
    when(nodeActions.getGraphDatabase()).thenReturn(gds);
    NodeProxy nodeImpl = new NodeProxy(nodeActions, 1);
    Statement stmt = mock(Statement.class);
    ReadOperations readOps = mock(ReadOperations.class);
    when(stmt.readOperations()).thenReturn(readOps);
    when(nodeActions.statement()).thenReturn(stmt);
    when(readOps.relationshipTypeGetForName(loves.name())).thenReturn(2);
    when(readOps.nodeGetRelationships(eq(1L), eq(Direction.OUTGOING), eq(new int[] { 2 }))).thenAnswer(invocation -> new RelationshipIterator.BaseIterator() {

        int pos;

        long relId;

        @Override
        protected boolean fetchNext() {
            if (pos < relIds.length) {
                relId = relIds[pos++];
                return true;
            } else {
                return false;
            }
        }

        @Override
        public <EXCEPTION extends Exception> boolean relationshipVisit(long relationshipId, RelationshipVisitor<EXCEPTION> visitor) throws EXCEPTION {
            visitor.visit(relId, 2, 1, 10 * relId + 2);
            return false;
        }
    });
    return nodeImpl;
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) RelationshipIterator(org.neo4j.kernel.impl.api.store.RelationshipIterator) Statement(org.neo4j.kernel.api.Statement) ReadOperations(org.neo4j.kernel.api.ReadOperations) Relationship(org.neo4j.graphdb.Relationship) Matchers.anyLong(org.mockito.Matchers.anyLong)

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