Search in sources :

Example 26 with LockException

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

the class AbstractLockTest method testUnlockByOtherSession.

/**
     * Test {@link LockManager#unlock(String)} for a session that is not
     * lock owner.
     * 
     * @throws RepositoryException
     * @throws NotExecutableException
     */
public void testUnlockByOtherSession() throws RepositoryException, NotExecutableException {
    Session otherSession = getHelper().getReadWriteSession();
    try {
        getLockManager(otherSession).unlock(lockedNode.getPath());
        fail("Another session must not be allowed to unlock.");
    } catch (LockException e) {
        // success
        // make sure the node is still locked and the lock properties are
        // still present.
        assertTrue(lockMgr.isLocked(lockedNode.getPath()));
        assertTrue(lockedNode.hasProperty(jcrlockIsDeep));
        assertTrue(lockedNode.hasProperty(jcrLockOwner));
    } finally {
        otherSession.logout();
    }
}
Also used : LockException(javax.jcr.lock.LockException) Session(javax.jcr.Session)

Example 27 with LockException

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

the class LockManagerTest method testRemoveLockToken3.

public void testRemoveLockToken3() throws Exception {
    assertLockable(testNode);
    boolean sessionScoped = false;
    Lock l = lockMgr.lock(testPath, true, sessionScoped, Long.MAX_VALUE, null);
    String ltoken = l.getLockToken();
    try {
        lockMgr.removeLockToken(ltoken);
        // the locked node.
        try {
            testNode.addNode(nodeName2, testNodeType);
            fail("Session must not be allowed to modify node");
        } catch (LockException e) {
        // expected
        }
    } finally {
        // make sure lock token is added even if test fail
        lockMgr.addLockToken(ltoken);
    }
}
Also used : LockException(javax.jcr.lock.LockException) Lock(javax.jcr.lock.Lock)

Example 28 with LockException

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

the class LockTest method testParentChildDeepLock.

/**
     * Test parent/child lock
     */
public void testParentChildDeepLock() throws Exception {
    // create new nodes
    Node n1 = testRootNode.addNode(nodeName1, testNodeType);
    ensureMixinType(n1, mixLockable);
    Node n2 = n1.addNode(nodeName2, testNodeType);
    ensureMixinType(n2, mixLockable);
    testRootNode.getSession().save();
    // lock child node
    n2.lock(false, true);
    // assert: unable to deep lock parent node
    try {
        n1.lock(true, true);
        fail("unable to deep lock parent node");
    } catch (LockException e) {
    // expected
    }
}
Also used : LockException(javax.jcr.lock.LockException) Node(javax.jcr.Node)

Example 29 with LockException

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

the class MergeNodeTest method disable_testMergeLocked.

/**
     * Tests if a {@link LockException} is thrown when merge is called on a
     * locked node.
     * @throws NotExecutableException if repository does not support locking.
     */
@SuppressWarnings("deprecation")
public void disable_testMergeLocked() throws NotExecutableException, RepositoryException {
    if (!isSupported(Repository.OPTION_LOCKING_SUPPORTED)) {
        throw new NotExecutableException("Locking is not supported.");
    }
    // try to make nodeToMerge lockable if it is not
    ensureMixinType(nodeToMerge, mixLockable);
    nodeToMerge.getParent().save();
    // lock the node
    // remove first slash of path to get rel path to root
    String pathRelToRoot = nodeToMerge.getPath().substring(1);
    // access node through another session to lock it
    Session session2 = getHelper().getSuperuserSession();
    try {
        Node node2 = session2.getRootNode().getNode(pathRelToRoot);
        node2.lock(false, false);
        try {
            nodeToMerge.merge(workspace.getName(), false);
            fail("merge must throw a LockException if applied on a " + "locked node");
        } catch (LockException e) {
        // success
        }
        node2.unlock();
    } finally {
        session2.logout();
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) LockException(javax.jcr.lock.LockException) Node(javax.jcr.Node) Session(javax.jcr.Session)

Example 30 with LockException

use of javax.jcr.lock.LockException in project jackrabbit-oak by apache.

the class NodeDelegate method unlock.

public void unlock() throws RepositoryException {
    String path = getPath();
    Root root = sessionDelegate.getContentSession().getLatestRoot();
    Tree tree = root.getTree(path);
    if (!tree.exists()) {
        throw new ItemNotFoundException("Node " + path + " does not exist");
    } else if (!isNodeType(tree, MIX_LOCKABLE, root)) {
        throw new LockException("Node " + path + " is not lockable");
    } else if (!tree.hasProperty(JCR_LOCKISDEEP)) {
        throw new LockException("Node " + path + " is not locked");
    }
    try {
        tree.removeProperty(JCR_LOCKISDEEP);
        tree.removeProperty(JCR_LOCKOWNER);
        sessionDelegate.commit(root);
    } catch (CommitFailedException e) {
        if (e.isAccessViolation()) {
            throw new AccessControlException("Access denied to unlock node " + path, e);
        } else {
            throw new RepositoryException("Unable to unlock node " + path, e);
        }
    }
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) LockException(javax.jcr.lock.LockException) Tree(org.apache.jackrabbit.oak.api.Tree) AccessControlException(javax.jcr.security.AccessControlException) RepositoryException(javax.jcr.RepositoryException) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) ItemNotFoundException(javax.jcr.ItemNotFoundException)

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