@Override protected Node newNodeProxyById( long id ) { return EmbeddedProxySPI.newNodeProxy( id ); }
@Override public Node[] getNodes() { spi.assertInUnterminatedTransaction(); return new Node[]{ spi.newNodeProxy( sourceId() ), spi.newNodeProxy( targetId() )}; }
@Override public Node getStartNode() { spi.assertInUnterminatedTransaction(); return spi.newNodeProxy( sourceId() ); }
@Override public Node getEndNode() { spi.assertInUnterminatedTransaction(); return spi.newNodeProxy( targetId() ); }
@Override public AnyValue mapNode( VirtualNodeValue value ) { if ( value instanceof NodeValue ) { return value; } return ValueUtils.fromNodeProxy( proxySpi.newNodeProxy( value.id() ) ); }
public static NodeValue materializeNodeValue( EmbeddedProxySPI proxySpi, Object anyValue ) { // Null check has to be done outside by the generated code if ( anyValue instanceof NodeValue ) { return (NodeValue) anyValue; } else if ( anyValue instanceof VirtualNodeValue ) { return ValueUtils.fromNodeProxy( proxySpi.newNodeProxy( ((VirtualNodeValue) anyValue).id() ) ); } else if ( anyValue instanceof Node ) { return ValueUtils.fromNodeProxy( (Node) anyValue ); } throw new IllegalArgumentException( "Do not know how to materialize node value from type " + anyValue.getClass().getName() ); }
@Override public Node getOtherNode( Node node ) { spi.assertInUnterminatedTransaction(); return spi.newNodeProxy( getOtherNodeId( node.getId() ) ); }
private TxStateTransactionDataSnapshot snapshot() { EmbeddedProxySPI spi = mock( EmbeddedProxySPI.class ); when( spi.newNodeProxy( anyLong() ) ).thenAnswer( invocation -> new NodeProxy( spi, invocation.getArgument( 0 ) ) ); when( spi.newRelationshipProxy( anyLong() ) ).thenAnswer( invocation -> new RelationshipProxy( spi, invocation.getArgument( 0 ) ) ); when( spi.newRelationshipProxy( anyLong(), anyLong(), anyInt(), anyLong() ) ).thenAnswer( invocation -> new RelationshipProxy( spi, invocation.getArgument( 0 ), invocation.getArgument( 1 ), invocation.getArgument( 2 ), invocation.getArgument( 3 ) ) ); return new TxStateTransactionDataSnapshot( state, spi, ops, transaction ); } }
@Before public void setup() { EmbeddedProxySPI manager = mock( EmbeddedProxySPI.class ); when( manager.newNodeProxy( anyLong() ) ).thenAnswer( invocationOnMock -> { long id = invocationOnMock.getArgument( 0 ); NodeProxy mock = mock( NodeProxy.class ); when( mock.getId() ).thenReturn( id ); return mock; } ); when( manager.newRelationshipProxy( anyLong() ) ).thenAnswer( invocationOnMock -> { long id = invocationOnMock.getArgument( 0 ); RelationshipProxy mock = mock( RelationshipProxy.class ); when( mock.getId() ).thenReturn( id ); return mock; } ); converter = new ParameterConverter( manager ); }
.mapToObj( id -> (AnyValue) ValueUtils.fromNodeProxy( proxySpi.newNodeProxy( id ) ) ) .collect( Collectors.toList() ) );
for ( int i = 0; i < nodes.length; i++ ) nodeProxies[i] = proxySpi.newNodeProxy( nodes[i].id() );
when( actions.newNodeProxy( anyLong() ) ).then( invocation -> nodeWithId( invocation.getArgument( 0 ) ) ); when( actions.getRelationshipTypeById( anyInt() ) ).then(
public static AnyValue materializeAnyValueResult( EmbeddedProxySPI proxySpi, Object anyValue ) { if ( anyValue instanceof VirtualNodeValue ) { if ( anyValue instanceof NodeValue ) { return (AnyValue) anyValue; } return ValueUtils.fromNodeProxy( proxySpi.newNodeProxy( ((VirtualNodeValue) anyValue).id() ) ); } if ( anyValue instanceof VirtualRelationshipValue ) { if ( anyValue instanceof RelationshipValue ) { return (AnyValue) anyValue; } return ValueUtils.fromRelationshipProxy( proxySpi.newRelationshipProxy( ((VirtualRelationshipValue) anyValue).id() ) ); } // If it is a list or map, run it through a ValueMapper that will create proxy objects for entities if needed. // This will first do a dry run and return as it is if no conversion is needed. // If in the future we will always create proxy objects directly whenever we create values we can skip this // Doing this conversion lazily instead, by wrapping with TransformedListValue or TransformedMapValue is probably not a // good idea because of the complexities involved (see TOMBSTONE in VirtualValues about why TransformedListValue was killed). // NOTE: There is also a case where a ListValue can be storable (ArrayValueListValue) where no conversion is needed if ( (anyValue instanceof ListValue && !((ListValue) anyValue).storable()) || anyValue instanceof MapValue ) { return CompiledMaterializeValueMapper.mapAnyValue( proxySpi, (AnyValue) anyValue ); } return (AnyValue) anyValue; }
@Test void testPathReverseNodes() { when( spi.newNodeProxy( Mockito.anyLong() ) ).thenAnswer( new NodeProxyAnswer() ); Path path = new PathImpl.Builder( createNodeProxy( 1 ) ) .push( createRelationshipProxy( 1, 2 ) ) .push( createRelationshipProxy( 2, 3 ) ) .build( new PathImpl.Builder( createNodeProxy( 3 ) ) ); Iterable<Node> nodes = path.reverseNodes(); List<Node> nodeList = Iterables.asList( nodes ); assertEquals( 3, nodeList.size() ); assertEquals( 3, nodeList.get( 0 ).getId() ); assertEquals( 2, nodeList.get( 1 ).getId() ); assertEquals( 1, nodeList.get( 2 ).getId() ); }
@Test void testPathNodes() { when( spi.newNodeProxy( Mockito.anyLong() ) ).thenAnswer( new NodeProxyAnswer() ); Path path = new PathImpl.Builder( createNodeProxy( 1 ) ) .push( createRelationshipProxy( 1, 2 ) ) .push( createRelationshipProxy( 2, 3 ) ) .build( new PathImpl.Builder( createNodeProxy( 3 ) ) ); Iterable<Node> nodes = path.nodes(); List<Node> nodeList = Iterables.asList( nodes ); assertEquals( 3, nodeList.size() ); assertEquals( 1, nodeList.get( 0 ).getId() ); assertEquals( 2, nodeList.get( 1 ).getId() ); assertEquals( 3, nodeList.get( 2 ).getId() ); }
@Override protected Node newNodeProxyById( long id ) { return EmbeddedProxySPI.newNodeProxy( id ); }
@Override public Node[] getNodes() { spi.assertInUnterminatedTransaction(); return new Node[]{ spi.newNodeProxy( sourceId() ), spi.newNodeProxy( targetId() )}; }
@Override public AnyValue mapNode( VirtualNodeValue value ) { if ( value instanceof NodeValue ) { return value; } return ValueUtils.fromNodeProxy( proxySpi.newNodeProxy( value.id() ) ); }
@Override public Node getEndNode() { spi.assertInUnterminatedTransaction(); return spi.newNodeProxy( targetId() ); }
@Override public Node getOtherNode( Node node ) { spi.assertInUnterminatedTransaction(); return spi.newNodeProxy( getOtherNodeId( node.getId() ) ); }