@Override public Node getStartNode() { spi.assertInUnterminatedTransaction(); return spi.newNodeProxy( sourceId() ); }
@Override protected Relationship newRelationshipProxyById( long id ) { return EmbeddedProxySPI.newRelationshipProxy( id ); }
@Override public RelationshipType getType() { spi.assertInUnterminatedTransaction(); return spi.getRelationshipTypeById( typeId() ); }
for ( int i = 0; i < nodes.length; i++ ) nodeProxies[i] = proxySpi.newNodeProxy( nodes[i].id() ); relationship[i] = proxySpi.newRelationshipProxy( relationships[i].id() );
@Override protected Node newNodeProxyById( long id ) { return EmbeddedProxySPI.newNodeProxy( id ); }
when( actions.newNodeProxy( anyLong() ) ).then( invocation -> nodeWithId( invocation.getArgument( 0 ) ) ); when( actions.getRelationshipTypeById( anyInt() ) ).then( invocation -> new NamedToken( "whatever", invocation.getArgument( 0 ) ) );
private GraphProperties graphProperties() { return db.getDependencyResolver().resolveDependency( EmbeddedProxySPI.class ).newGraphPropertiesProxy(); } }
@Override public String toString() { StringBuilder string = new StringBuilder(); string.append( '(' ).append( nodes[0] ).append( ')' ); boolean inTx = true; for ( int i = 0; i < relationships.length; i++ ) { int type = directedTypes[i]; string.append( type < 0 ? "<-[" : "-[" ); string.append( relationships[i] ); if ( inTx ) { try { String name = proxySPI.getRelationshipTypeById( type < 0 ? ~type : type ).name(); string.append( ':' ).append( name ); } catch ( Exception e ) { inTx = false; } } string.append( type < 0 ? "]-(" : "]->(" ).append( nodes[i + 1] ).append( ')' ); } return string.toString(); }
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 ); } }
@Override public AnyValue mapNode( VirtualNodeValue value ) { if ( value instanceof NodeValue ) { return value; } return ValueUtils.fromNodeProxy( proxySpi.newNodeProxy( value.id() ) ); }
@Override public PropertyContainer graphProperties() { return ((GraphDatabaseAPI) db) .getDependencyResolver() .resolveDependency( EmbeddedProxySPI.class ) .newGraphPropertiesProxy(); }
@Override public String toString() { String relType; try { relType = spi.getRelationshipTypeById( typeId() ).name(); return format( "(%d)-[%s,%d]->(%d)", sourceId(), relType, getId(), targetId() ); } catch ( NotInTransactionException | DatabaseShutdownException e ) { // We don't keep the rel-name lookup if the database is shut down. Source ID and target ID also requires // database access in a transaction. However, failing on toString would be uncomfortably evil, so we fall // back to noting the relationship type id. } relType = "RELTYPE(" + type + ")"; return format( "(?)-[%s,%d]->(?)", relType, getId() ); }
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; }
@Override public Node getEndNode() { spi.assertInUnterminatedTransaction(); return spi.newNodeProxy( targetId() ); }
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 Relationship relationship( long id, long startNodeId, int typeId, long endNodeId ) { return spi.newRelationshipProxy( id, startNodeId, typeId, endNodeId ); } }
private static PropertyContainer properties( GraphDatabaseAPI db ) { return db.getDependencyResolver().resolveDependency( EmbeddedProxySPI.class ).newGraphPropertiesProxy(); }
@Override public boolean isType( RelationshipType type ) { spi.assertInUnterminatedTransaction(); return spi.getRelationshipTypeById( typeId() ).name().equals( type.name() ); }
@Override public String toString() { StringBuilder string = new StringBuilder(); string.append( '(' ).append( nodes[0] ).append( ')' ); boolean inTx = true; for ( int i = 0; i < relationships.length; i++ ) { int type = directedTypes[i]; string.append( type < 0 ? "<-[" : "-[" ); string.append( relationships[i] ); if ( inTx ) { try { String name = proxySPI.getRelationshipTypeById( type < 0 ? ~type : type ).name(); string.append( ':' ).append( name ); } catch ( Exception e ) { inTx = false; } } string.append( type < 0 ? "]-(" : "]->(" ).append( nodes[i + 1] ).append( ')' ); } return string.toString(); }
@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 ); }