use of javax.jcr.lock.LockManager in project jackrabbit by apache.
the class NodeImpl method lock.
//------------------------------------------------------< locking support >
/**
* {@inheritDoc}
*/
public Lock lock(boolean isDeep, boolean isSessionScoped) throws UnsupportedRepositoryOperationException, LockException, AccessDeniedException, InvalidItemStateException, RepositoryException {
// check state of this instance
sanityCheck();
LockManager lockMgr = getSession().getWorkspace().getLockManager();
return lockMgr.lock(getPath(), isDeep, isSessionScoped, sessionContext.getWorkspace().getConfig().getDefaultLockTimeout(), null);
}
use of javax.jcr.lock.LockManager in project jackrabbit by apache.
the class NodeImpl method isLocked.
/**
* {@inheritDoc}
*/
public boolean isLocked() throws RepositoryException {
// check state of this instance
sanityCheck();
LockManager lockMgr = getSession().getWorkspace().getLockManager();
return lockMgr.isLocked(getPath());
}
use of javax.jcr.lock.LockManager in project jackrabbit by apache.
the class LockManagerTest method testLockTransfer3.
public void testLockTransfer3() 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.removeLockToken(ltoken);
fail("Removing a token that has been transfered to another manager must fail.");
} catch (LockException e) {
// success
} finally {
otherLockMgr.removeLockToken(ltoken);
lockMgr.addLockToken(ltoken);
other.logout();
}
}
use of javax.jcr.lock.LockManager in project jackrabbit by apache.
the class LockManagerTest method testAddLockTokenToAnotherSession.
public void testAddLockTokenToAnotherSession() throws RepositoryException, NotExecutableException {
assertLockable(testNode);
boolean sessionScoped = false;
Lock l = lockMgr.lock(testPath, true, sessionScoped, Long.MAX_VALUE, null);
String ltoken = l.getLockToken();
Session other = getHelper().getReadWriteSession();
try {
LockManager otherLockMgr = getLockManager(other);
assertFalse(containsLockToken(otherLockMgr, ltoken));
try {
otherLockMgr.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 {
other.logout();
}
}
use of javax.jcr.lock.LockManager in project jackrabbit by apache.
the class LockManagerTest method testLockTransfer.
public void testLockTransfer() 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);
assertTrue("The new holding manager must contain the token.", containsLockToken(otherLockMgr, ltoken));
Lock otherL = otherLockMgr.getLock(testPath);
assertNotNull("Token must be exposed to new lock holder.", otherL.getLockToken());
assertEquals("Token must be the same again.", ltoken, otherL.getLockToken());
} finally {
otherLockMgr.removeLockToken(ltoken);
lockMgr.addLockToken(ltoken);
other.logout();
}
}
Aggregations