Search in sources :

Example 11 with LockManager

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);
}
Also used : LockManager(javax.jcr.lock.LockManager)

Example 12 with LockManager

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());
}
Also used : LockManager(javax.jcr.lock.LockManager)

Example 13 with LockManager

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();
    }
}
Also used : LockManager(javax.jcr.lock.LockManager) LockException(javax.jcr.lock.LockException) Lock(javax.jcr.lock.Lock) Session(javax.jcr.Session)

Example 14 with LockManager

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();
    }
}
Also used : LockManager(javax.jcr.lock.LockManager) LockException(javax.jcr.lock.LockException) Lock(javax.jcr.lock.Lock) Session(javax.jcr.Session)

Example 15 with LockManager

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();
    }
}
Also used : LockManager(javax.jcr.lock.LockManager) Lock(javax.jcr.lock.Lock) Session(javax.jcr.Session)

Aggregations

LockManager (javax.jcr.lock.LockManager)16 Session (javax.jcr.Session)7 Lock (javax.jcr.lock.Lock)7 LockException (javax.jcr.lock.LockException)6 Node (javax.jcr.Node)4 RepositoryException (javax.jcr.RepositoryException)1 VersionManager (javax.jcr.version.VersionManager)1 RemoteLockManager (org.apache.jackrabbit.rmi.remote.RemoteLockManager)1 Test (org.junit.Test)1