@Override public String toString() { return "Node[" + this.getId() + "]"; }
@Override public boolean equals( Object o ) { return o instanceof Node && this.getId() == ((Node) o).getId(); }
public int compareTo( Object node ) { Node n = (Node) node; return Long.compare( this.getId(), n.getId() ); }
private Node nodeWithId( long id ) { NodeProxy node = mock( NodeProxy.class ); when( node.getId() ).thenReturn( id ); return node; } }
@Override public void removeLabel( Label label ) { KernelTransaction transaction = spi.kernelTransaction(); try ( Statement ignore = transaction.acquireStatement() ) { int labelId = transaction.tokenRead().nodeLabel( label.name() ); if ( labelId != TokenRead.NO_TOKEN ) { transaction.dataWrite().nodeRemoveLabel( getId(), labelId ); } } catch ( EntityNotFoundException e ) { throw new NotFoundException( "No node with id " + getId() + " found.", e ); } catch ( KernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } }
@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 = safeAcquireTransaction(); try { boolean deleted = transaction.dataWrite().nodeDelete( getId() ); if ( !deleted ) { throw new NotFoundException( "Unable to delete Node[" + nodeId + "] since it has already been deleted." ); } } catch ( InvalidTransactionTypeKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } catch ( AutoIndexingKernelException e ) { throw new IllegalStateException( "Auto indexing encountered a failure while deleting the node: " + e.getMessage(), e ); } }
private ResourceIterator<Relationship> getRelationshipSelectionIterator( KernelTransaction transaction, Direction direction, int[] typeIds ) { NodeCursor node = transaction.ambientNodeCursor(); transaction.dataRead().singleNode( getId(), node ); if ( !node.next() ) { throw new NotFoundException( format( "Node %d not found", nodeId ) ); } switch ( direction ) { case OUTGOING: return outgoingIterator( transaction.cursors(), node, typeIds, this ); case INCOMING: return incomingIterator( transaction.cursors(), node, typeIds, this ); case BOTH: return allIterator( transaction.cursors(), node, typeIds, this ); default: throw new IllegalStateException( "Unknown direction " + direction ); } }
@Override public String toString() { return "Node[" + this.getId() + "]"; }
@Override public boolean equals( Object o ) { return o instanceof Node && this.getId() == ((Node) o).getId(); }
public int compareTo( Object node ) { Node n = (Node) node; return Long.compare( this.getId(), n.getId() ); }
@Override public void removeLabel( Label label ) { KernelTransaction transaction = spi.kernelTransaction(); try ( Statement ignore = transaction.acquireStatement() ) { int labelId = transaction.tokenRead().nodeLabel( label.name() ); if ( labelId != TokenRead.NO_TOKEN ) { transaction.dataWrite().nodeRemoveLabel( getId(), labelId ); } } catch ( EntityNotFoundException e ) { throw new NotFoundException( "No node with id " + getId() + " found.", e ); } catch ( KernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } }
@Override public void delete() { KernelTransaction transaction = safeAcquireTransaction(); try { boolean deleted = transaction.dataWrite().nodeDelete( getId() ); if ( !deleted ) { throw new NotFoundException( "Unable to delete Node[" + nodeId + "] since it has already been deleted." ); } } catch ( InvalidTransactionTypeKernelException e ) { throw new ConstraintViolationException( e.getMessage(), e ); } catch ( AutoIndexingKernelException e ) { throw new IllegalStateException( "Auto indexing encountered a failure while deleting the node: " + e.getMessage(), e ); } }
private ResourceIterator<Relationship> getRelationshipSelectionIterator( KernelTransaction transaction, Direction direction, int[] typeIds ) { NodeCursor node = transaction.ambientNodeCursor(); transaction.dataRead().singleNode( getId(), node ); if ( !node.next() ) { throw new NotFoundException( format( "Node %d not found", nodeId ) ); } switch ( direction ) { case OUTGOING: return outgoingIterator( transaction.cursors(), node, typeIds, this ); case INCOMING: return incomingIterator( transaction.cursors(), node, typeIds, this ); case BOTH: return allIterator( transaction.cursors(), node, typeIds, this ); default: throw new IllegalStateException( "Unknown direction " + direction ); } }