use of javax.jcr.lock.LockException in project jackrabbit by apache.
the class AddNodeTest method testAddNodeOnLocked.
/**
* Writing to a locked node must throw LockException even if the lock
* isn't detected withing Jcr2Spi.
*
* @throws Exception
* @see <a href="https://issues.apache.org/jira/browse/JCR-2585">JCR-2585</a>
*/
public void testAddNodeOnLocked() throws Exception {
Session s = getHelper().getSuperuserSession();
try {
Node node = s.getNode(testRootNode.getPath());
Node n = node.addNode(nodeName1);
n.setProperty(propertyName1, "value");
testRootNode.lock(true, true);
s.save();
} catch (LockException e) {
// success
} finally {
s.logout();
}
}
use of javax.jcr.lock.LockException in project jackrabbit by apache.
the class SaveTest method testLockException.
/**
* Tests if a {@link javax.jcr.lock.LockException} is thrown if a query is
* stored under a node locked by another <code>Session</code>.
* <p>
* The test creates a node <code>nodeName1</code> of type <code>testNodeType</code>
* under <code>testRoot</code> and locks the node with the superuser session.
* Then the test tries to store a query as <code>nodeName2</code> under
* <code>nodeName1</code> with the readWrite <code>Session</code>.
* @throws NotExecutableException if nt:query is not supported.
*/
public void testLockException() throws RepositoryException, NotExecutableException {
checkNtQuery();
// check if repository supports locking
if (!isSupported(Repository.OPTION_LOCKING_SUPPORTED)) {
throw new NotExecutableException();
}
// create a node that is lockable
Node lockable = testRootNode.addNode(nodeName1, testNodeType);
// or try to make it lockable if it is not
ensureMixinType(lockable, mixLockable);
testRootNode.getSession().save();
lockable.lock(false, true);
Session readWrite = getHelper().getReadWriteSession();
try {
Query query = readWrite.getWorkspace().getQueryManager().createQuery(statement, Query.XPATH);
query.storeAsNode(testRoot + "/" + nodeName1 + "/" + nodeName2);
fail("Query.storeAsNode() must throw LockException, parent node is locked.");
} catch (LockException e) {
// expected behaviour
} finally {
readWrite.logout();
lockable.unlock();
}
}
use of javax.jcr.lock.LockException in project jackrabbit by apache.
the class LockManagerImpl method getLock.
/**
* {@inheritDoc}
*/
public Lock getLock(NodeImpl node) throws LockException, RepositoryException {
acquire();
try {
SessionImpl session = (SessionImpl) node.getSession();
Path path = getPath(session, node.getId());
PathMap.Element<LockInfo> element = lockMap.map(path, false);
LockInfo info = element.get();
if (info != null && (element.hasPath(path) || info.isDeep())) {
NodeImpl lockHolder = (NodeImpl) session.getItemManager().getItem(info.getId());
return new LockImpl(info, lockHolder);
} else {
throw new LockException("Node not locked: " + node);
}
} catch (ItemNotFoundException e) {
throw new LockException("Node not locked: " + node);
} finally {
release();
}
}
use of javax.jcr.lock.LockException in project jackrabbit by apache.
the class SessionLockManager method unlock.
/**
* @see javax.jcr.lock.LockManager#unlock(String)
*/
public void unlock(String absPath) throws UnsupportedRepositoryOperationException, LockException, AccessDeniedException, InvalidItemStateException, RepositoryException {
NodeImpl node = (NodeImpl) session.getNode(absPath);
int options = ItemValidator.CHECK_HOLD | ItemValidator.CHECK_PENDING_CHANGES_ON_NODE;
context.getItemValidator().checkModify(node, options, Permission.LOCK_MNGMT);
checkLockable(node);
synchronized (systemLockMgr) {
// basic checks if unlock can be called on the node.
if (!systemLockMgr.holdsLock(node)) {
throw new LockException("Node not locked: " + node);
}
systemLockMgr.checkUnlock(session, node);
systemLockMgr.unlock(node);
}
}
use of javax.jcr.lock.LockException in project jackrabbit by apache.
the class XALockManager method getLock.
/**
* {@inheritDoc}
*/
public Lock getLock(NodeImpl node) throws LockException, RepositoryException {
LockInfo info;
if (isInXA()) {
info = xaEnv.getLockInfo(node);
} else {
info = lockMgr.getLockInfo(node.getNodeId());
}
if (info == null) {
throw new LockException("Node not locked: " + node);
}
SessionImpl session = (SessionImpl) node.getSession();
NodeImpl holder = (NodeImpl) session.getItemManager().getItem(info.getId());
return new XALockImpl(this, info, holder);
}
Aggregations