@Override public RelationshipProxy newRelationshipProxy( long id, long startNodeId, int typeId, long endNodeId ) { return new RelationshipProxy( this, id, startNodeId, typeId, endNodeId ); }
@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() ); }
private void verifyIds( EmbeddedProxySPI actions, long relationshipId, long nodeId1, int typeId, long nodeId2 ) { RelationshipProxy proxy = new RelationshipProxy( actions, relationshipId, nodeId1, typeId, nodeId2 ); assertEquals( relationshipId, proxy.getId() ); // our mock above is known to return RelationshipTypeToken assertEquals( nodeId1, proxy.getStartNode().getId() ); assertEquals( nodeId1, proxy.getStartNodeId() ); assertEquals( nodeId2, proxy.getEndNode().getId() ); assertEquals( nodeId2, proxy.getEndNodeId() ); assertEquals( nodeId2, proxy.getOtherNode( nodeWithId( nodeId1 ) ).getId() ); assertEquals( nodeId2, proxy.getOtherNodeId( nodeId1 ) ); assertEquals( nodeId1, proxy.getOtherNode( nodeWithId( nodeId2 ) ).getId() ); assertEquals( nodeId1, proxy.getOtherNodeId( nodeId2 ) ); }
@Override public Node getOtherNode( Node node ) { spi.assertInUnterminatedTransaction(); return spi.newNodeProxy( getOtherNodeId( node.getId() ) ); }
@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() ); }
@Override public Node getOtherNode( Node node ) { spi.assertInUnterminatedTransaction(); return spi.newNodeProxy( getOtherNodeId( node.getId() ) ); }
private RelationshipProxy relationship( int offset ) { int type = directedTypes[offset]; if ( type >= 0 ) { return new RelationshipProxy( proxySPI, relationships[offset], nodes[offset], type, nodes[offset + 1] ); } else { return new RelationshipProxy( proxySPI, relationships[offset], nodes[offset + 1], ~type, nodes[offset] ); } }
@Override public boolean equals( Object o ) { return o instanceof Relationship && this.getId() == ((Relationship) o).getId(); }
@Override public RelationshipProxy newRelationshipProxy( long id ) { return new RelationshipProxy( this, id ); }
public int compareTo( Object rel ) { Relationship r = (Relationship) rel; return Long.compare( this.getId(), r.getId() ); }
@Override public RelationshipProxy newRelationshipProxy( long id ) { return new RelationshipProxy( this, id ); }
@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 ); }
private RelationshipProxy createRelationshipProxy( int startNodeId, int endNodeId ) { return new RelationshipProxy( spi, 1L, startNodeId, 1, endNodeId ); }
@Override public void delete() { KernelTransaction transaction = spi.kernelTransaction(); try { boolean deleted = transaction.dataWrite().relationshipDelete( id ); if ( !deleted ) { throw new NotFoundException( "Unable to delete relationship[" + getId() + "] since it is already deleted." ); } } catch ( InvalidTransactionTypeKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } catch ( AutoIndexingKernelException e ) { throw new IllegalStateException( "Auto indexing encountered a failure while deleting the relationship: " + e.getMessage(), e ); } }
@Override public Relationship mapRelationship( VirtualRelationshipValue value ) { assert !(value instanceof RelationshipReference); if ( value instanceof RelationshipProxyWrappingValue ) { // this is the back door through which "virtual relationships" slip return ((RelationshipProxyWrappingValue) value).relationshipProxy(); } return new RelationshipProxy( proxySPI, value.id() ); }
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 ); } }