@Override public void getWriteLock(Object resource, Transaction tx) throws DeadlockDetectedException, IllegalResourceException { // Code copied from getReadLock. Fix! LockGrabber grabber = null; if (resource instanceof Node) grabber = LockGrabber.NODE_WRITE; else if (resource instanceof Relationship) grabber = LockGrabber.RELATIONSHIP_WRITE; else if (resource instanceof GraphProperties) grabber = LockGrabber.GRAPH_WRITE; else if (resource instanceof IndexLock) grabber = LockGrabber.INDEX_WRITE; try { if (grabber == null) { super.getWriteLock(resource, tx); return; } initializeTxIfFirst(); LockResult result = null; do { int eventIdentifier = getLocalTxId(); result = databaseOperations.receive( grabber.acquireLock( broker.getMaster().first(), databaseOperations.getSlaveContext(eventIdentifier), resource)); switch (result.getStatus()) { case OK_LOCKED: super.getWriteLock(resource, tx); return; case DEAD_LOCKED: throw new DeadlockDetectedException(result.getDeadlockMessage()); } } while (result.getStatus() == LockStatus.NOT_LOCKED); } catch (RuntimeException e) { databaseOperations.exceptionHappened(e); throw e; } }
private Response<LockResult> acquireLock( RequestContext context, LockGrabber lockGrabber, Object... entities) { Transaction otherTx = suspendOtherAndResumeThis(context, false); try { LockManager lockManager = graphDb.getLockManager(); TransactionState state = ((AbstractTransactionManager) graphDb.getTxManager()).getTransactionState(); for (Object entity : entities) { lockGrabber.grab(lockManager, state, entity); } return packResponse(context, new LockResult(LockStatus.OK_LOCKED)); } catch (DeadlockDetectedException e) { return packResponse(context, new LockResult(e.getMessage())); } catch (IllegalResourceException e) { return packResponse(context, new LockResult(LockStatus.NOT_LOCKED)); } finally { suspendThisAndResumeOther(otherTx, context); } }