use of javax.jcr.lock.LockException in project jackrabbit by apache.
the class LockManagerImpl method removeLockToken.
/**
* {@inheritDoc}
*/
public void removeLockToken(SessionImpl session, String lt) throws LockException, RepositoryException {
try {
acquire();
NodeId id = LockInfo.parseLockToken(lt);
NodeImpl node = (NodeImpl) sysSession.getItemManager().getItem(id);
PathMap.Element<LockInfo> element = lockMap.map(node.getPrimaryPath(), true);
if (element != null) {
LockInfo info = element.get();
if (info != null) {
if (info.isLockHolder(session)) {
info.setLockHolder(null);
} else if (info.getLockHolder() != null) {
String msg = "Cannot remove lock token: lock held by other session.";
log.warn(msg);
info.throwLockException(msg, session);
}
}
}
// inform SessionLockManager
getSessionLockManager(session).lockTokenRemoved(lt);
} catch (IllegalArgumentException e) {
String msg = "Bad lock token: " + e.getMessage();
log.warn(msg);
throw new LockException(msg);
} finally {
release();
}
}
use of javax.jcr.lock.LockException in project jackrabbit by apache.
the class XAEnvironment method unlock.
/**
* Unlock some node.
* @param node node to unlock
* @throws LockException if the node is not locked
* @throws RepositoryException if an error occurs
*/
public void unlock(NodeImpl node) throws LockException, RepositoryException {
NodeId id = node.getNodeId();
// check positive set first
LockInfo info = lockedNodesMap.get(id);
if (info != null) {
lockedNodesMap.remove(id);
operations.remove(info);
info.setLive(false);
} else {
info = getLockInfo(node);
if (info == null || !info.getId().equals(id)) {
throw new LockException("Node not locked.");
} else if (!info.isLockHolder(node.getSession())) {
throw new LockException("Node not locked by this session.");
}
XALockInfo xaInfo = new XALockInfo(node, info);
unlockedNodesMap.put(id, xaInfo);
operations.add(xaInfo);
}
}
use of javax.jcr.lock.LockException in project jackrabbit by apache.
the class AbstractLockTest method testGetLockOnNewChild.
public void testGetLockOnNewChild() throws RepositoryException {
Node newChild = lockedNode.addNode(nodeName3, testNodeType);
if (isDeep()) {
// get lock must succeed even if child is not lockable.
Lock lock = newChild.getLock();
assertNotNull(lock);
assertTrue("Lock.getNode() must return the lock holding node", lockedNode.isSame(lock.getNode()));
Lock lock2 = lockMgr.getLock(newChild.getPath());
assertNotNull(lock2);
assertTrue("Lock.getNode() must return the lock holding node", lockedNode.isSame(lock2.getNode()));
} else {
try {
newChild.getLock();
fail("Node.getLock() must throw if node is not locked.");
} catch (LockException e) {
// success
}
try {
lockMgr.getLock(newChild.getPath());
fail("LockManager.getLock(String) must throw if node is not locked.");
} catch (LockException e) {
// success
}
}
}
use of javax.jcr.lock.LockException in project jackrabbit by apache.
the class DeepLockTest method testRemoveLockedChild.
public void testRemoveLockedChild() throws RepositoryException {
Session otherSession = getHelper().getReadWriteSession();
try {
Node child = (Node) otherSession.getItem(childNode.getPath());
child.remove();
otherSession.save();
fail("A node below a deeply locked node cannot be removed by another Session.");
} catch (LockException e) {
// success
} finally {
otherSession.logout();
}
}
use of javax.jcr.lock.LockException in project jackrabbit by apache.
the class LockManagerTest method testLockTransfer2.
public void testLockTransfer2() throws Exception {
assertLockable(testNode);
boolean sessionScoped = false;
Lock l = lockMgr.lock(testPath, true, sessionScoped, Long.MAX_VALUE, null);
String ltoken = l.getLockToken();
Session other = getHelper().getReadWriteSession();
LockManager otherLockMgr = getLockManager(other);
try {
lockMgr.removeLockToken(ltoken);
otherLockMgr.addLockToken(ltoken);
lockMgr.addLockToken(ltoken);
if (!openScopedLockMultiple) {
fail("Adding token to another session must fail (see config property " + RepositoryStub.PROP_OPEN_SCOPED_LOCK_MULTIPLE + ".");
}
} catch (LockException e) {
if (openScopedLockMultiple) {
fail("Adding token to another session must not fail (see config property " + RepositoryStub.PROP_OPEN_SCOPED_LOCK_MULTIPLE + ".");
}
} finally {
otherLockMgr.removeLockToken(ltoken);
lockMgr.addLockToken(ltoken);
other.logout();
}
}
Aggregations