MutableCachedNode lockedNode = lockingSession.mutable(nodeKey);
PropertyFactory propertyFactory = session.propertyFactory();
lockedNode.setProperty(lockingSession, propertyFactory.create(JcrLexicon.LOCK_OWNER, owner));
lockedNode.setProperty(lockingSession, propertyFactory.create(JcrLexicon.LOCK_IS_DEEP, isDeep));
lockedNode.lock(isSessionScoped);
// Now save both sessions. This will fail with a LockFailureException if the locking failed ...
lockingSession.save(systemSession, null);
} catch (LockFailureException e) {
// Someone must have snuck in and locked the node, and we just didn't receive notification of it yet ...