public int compareTo( Object rel ) { Relationship r = (Relationship) rel; return Long.compare( this.getId(), r.getId() ); }
@Override public boolean equals( Object o ) { return o instanceof Relationship && this.getId() == ((Relationship) o).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 long getOtherNodeId( long id ) { long start = sourceId(); long end = targetId(); if ( start == id ) { return end; } if ( end == id ) { return start; } throw new NotFoundException( "Node[" + id + "] not connected to this relationship[" + getId() + "]" ); }
@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 ); }
@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 ); } }
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 boolean equals( Object o ) { return o instanceof Relationship && this.getId() == ((Relationship) o).getId(); }
public int compareTo( Object rel ) { Relationship r = (Relationship) rel; return Long.compare( this.getId(), r.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 long getOtherNodeId( long id ) { long start = sourceId(); long end = targetId(); if ( start == id ) { return end; } if ( end == id ) { return start; } throw new NotFoundException( "Node[" + id + "] not connected to this relationship[" + getId() + "]" ); }
@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 ); } }