Search in sources :

Example 21 with LockException

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();
    }
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) LockException(javax.jcr.lock.LockException) NodeId(org.apache.jackrabbit.core.id.NodeId) PathMap(org.apache.jackrabbit.spi.commons.name.PathMap)

Example 22 with LockException

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);
    }
}
Also used : LockException(javax.jcr.lock.LockException) NodeId(org.apache.jackrabbit.core.id.NodeId)

Example 23 with LockException

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

Example 24 with LockException

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

Example 25 with LockException

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

Aggregations

LockException (javax.jcr.lock.LockException)61 Node (javax.jcr.Node)33 Session (javax.jcr.Session)24 Lock (javax.jcr.lock.Lock)13 RepositoryException (javax.jcr.RepositoryException)11 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)11 NodeImpl (org.apache.jackrabbit.core.NodeImpl)7 LockManager (javax.jcr.lock.LockManager)6 NodeId (org.apache.jackrabbit.core.id.NodeId)6 ItemNotFoundException (javax.jcr.ItemNotFoundException)5 PathMap (org.apache.jackrabbit.spi.commons.name.PathMap)5 RetentionManager (javax.jcr.retention.RetentionManager)4 SessionImpl (org.apache.jackrabbit.core.SessionImpl)4 Value (javax.jcr.Value)3 Path (org.apache.jackrabbit.spi.Path)3 IOException (java.io.IOException)2 InvalidItemStateException (javax.jcr.InvalidItemStateException)2 PathNotFoundException (javax.jcr.PathNotFoundException)2 Property (javax.jcr.Property)2 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)2