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);
}
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));
}
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;
}
Aggregations