public Lock exclusiveLock( KernelTransaction ktx, PropertyContainer container ) { try ( Statement ignore = ktx.acquireStatement() ) { if ( container instanceof Node ) { long id = ((Node) container).getId(); ktx.locks().acquireExclusiveNodeLock( id ); return new CoreAPILock( () -> ktx.locks().releaseExclusiveNodeLock( id ) ); } else if ( container instanceof Relationship ) { long id = ((Relationship) container).getId(); ktx.locks().acquireExclusiveRelationshipLock( id ); return new CoreAPILock( () -> ktx.locks().releaseExclusiveRelationshipLock( id ) ); } else { throw new UnsupportedOperationException( "Only relationships and nodes can be locked." ); } } }
public Lock sharedLock( KernelTransaction ktx, PropertyContainer container ) { try ( Statement ignore = ktx.acquireStatement() ) { if ( container instanceof Node ) { long id = ((Node) container).getId(); ktx.locks().acquireSharedNodeLock( id ); return new CoreAPILock( () -> ktx.locks().releaseSharedNodeLock( id ) ); } else if ( container instanceof Relationship ) { long id = ((Relationship) container).getId(); ktx.locks().acquireSharedRelationshipLock( id ); return new CoreAPILock( () -> ktx.locks().releaseSharedRelationshipLock( id ) ); } else { throw new UnsupportedOperationException( "Only relationships and nodes can be locked." ); } } }
@Before public void before() { ThreadToStatementContextBridge bridge = mock( ThreadToStatementContextBridge.class ); Statement statement = mock( Statement.class ); when( bridge.get() ).thenReturn( statement ); kernelTransaction = spy( KernelTransaction.class ); locks = mock( Locks.class ); when(kernelTransaction.locks()).thenReturn( locks ); placeboTx = new PlaceboTransaction( kernelTransaction ); resource = mock( Node.class ); when( resource.getId() ).thenReturn( 1L ); }
@Override public KernelTransaction kernelTransaction() { if ( recordingLocks == null ) { recordingLocks = new RecordingLocks( delegate.kernelTransaction().locks(), asList( listeners ), recordedLocks ); } return new DelegatingTransaction( delegate.kernelTransaction(), recordingLocks ); }
public Lock exclusiveLock( KernelTransaction ktx, PropertyContainer container ) { try ( Statement ignore = ktx.acquireStatement() ) { if ( container instanceof Node ) { long id = ((Node) container).getId(); ktx.locks().acquireExclusiveNodeLock( id ); return new CoreAPILock( () -> ktx.locks().releaseExclusiveNodeLock( id ) ); } else if ( container instanceof Relationship ) { long id = ((Relationship) container).getId(); ktx.locks().acquireExclusiveRelationshipLock( id ); return new CoreAPILock( () -> ktx.locks().releaseExclusiveRelationshipLock( id ) ); } else { throw new UnsupportedOperationException( "Only relationships and nodes can be locked." ); } } }
public Lock sharedLock( KernelTransaction ktx, PropertyContainer container ) { try ( Statement ignore = ktx.acquireStatement() ) { if ( container instanceof Node ) { long id = ((Node) container).getId(); ktx.locks().acquireSharedNodeLock( id ); return new CoreAPILock( () -> ktx.locks().releaseSharedNodeLock( id ) ); } else if ( container instanceof Relationship ) { long id = ((Relationship) container).getId(); ktx.locks().acquireSharedRelationshipLock( id ); return new CoreAPILock( () -> ktx.locks().releaseSharedRelationshipLock( id ) ); } else { throw new UnsupportedOperationException( "Only relationships and nodes can be locked." ); } } }