Search in sources :

Example 6 with LockManager

use of javax.jcr.lock.LockManager in project jackrabbit by apache.

the class NodeImpl method unlock.

/**
     * {@inheritDoc}
     */
public void unlock() throws UnsupportedRepositoryOperationException, LockException, AccessDeniedException, InvalidItemStateException, RepositoryException {
    // check state of this instance
    sanityCheck();
    LockManager lockMgr = getSession().getWorkspace().getLockManager();
    lockMgr.unlock(getPath());
}
Also used : LockManager(javax.jcr.lock.LockManager)

Example 7 with LockManager

use of javax.jcr.lock.LockManager in project jackrabbit by apache.

the class AbstractLockManagementTest method testLockBreaking.

public void testLockBreaking() throws RepositoryException, NotExecutableException {
    String locktoken = null;
    LockManager sulm = superuser.getWorkspace().getLockManager();
    String lockedpath = null;
    try {
        Node trn = getTestNode();
        modifyPrivileges(trn.getPath(), Privilege.JCR_READ, true);
        modifyPrivileges(trn.getPath(), PrivilegeRegistry.REP_WRITE, true);
        modifyPrivileges(trn.getPath(), Privilege.JCR_LOCK_MANAGEMENT, true);
        Session lockingSession = trn.getSession();
        assertFalse("super user and test user should have different user ids: " + lockingSession.getUserID() + " vs " + superuser.getUserID(), lockingSession.getUserID().equals(superuser.getUserID()));
        trn.addNode("locktest", "nt:unstructured");
        trn.addMixin("mix:lockable");
        lockingSession.save();
        // let the "other" user lock the node
        LockManager oulm = lockingSession.getWorkspace().getLockManager();
        Lock l = oulm.lock(trn.getPath(), true, false, Long.MAX_VALUE, null);
        lockedpath = trn.getPath();
        locktoken = l.getLockToken();
        lockingSession.logout();
        // transfer the lock token to the super user and try the unlock
        Node lockednode = superuser.getNode(lockedpath);
        assertTrue(lockednode.isLocked());
        Lock sl = sulm.getLock(lockedpath);
        assertNotNull(sl.getLockToken());
        sulm.addLockToken(sl.getLockToken());
        sulm.unlock(lockedpath);
        locktoken = null;
    } finally {
        if (locktoken != null && lockedpath != null) {
            sulm.addLockToken(locktoken);
            sulm.unlock(lockedpath);
        }
    }
}
Also used : LockManager(javax.jcr.lock.LockManager) Node(javax.jcr.Node) Session(javax.jcr.Session) Lock(javax.jcr.lock.Lock)

Example 8 with LockManager

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

Example 9 with LockManager

use of javax.jcr.lock.LockManager in project jackrabbit by apache.

the class NodeImpl method getLock.

/**
     * {@inheritDoc}
     */
public Lock getLock() throws UnsupportedRepositoryOperationException, LockException, AccessDeniedException, RepositoryException {
    // check state of this instance
    sanityCheck();
    LockManager lockMgr = getSession().getWorkspace().getLockManager();
    return lockMgr.getLock(getPath());
}
Also used : LockManager(javax.jcr.lock.LockManager)

Example 10 with LockManager

use of javax.jcr.lock.LockManager in project jackrabbit by apache.

the class ServerWorkspace method getLockManager.

/** {@inheritDoc} */
public RemoteLockManager getLockManager() throws RepositoryException, RemoteException {
    try {
        if (remoteLockManager == null) {
            LockManager lockManager = workspace.getLockManager();
            remoteLockManager = getFactory().getRemoteLockManager(lockManager);
        }
        return remoteLockManager;
    } catch (RepositoryException ex) {
        throw getRepositoryException(ex);
    }
}
Also used : LockManager(javax.jcr.lock.LockManager) RemoteLockManager(org.apache.jackrabbit.rmi.remote.RemoteLockManager) RepositoryException(javax.jcr.RepositoryException)

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