Search in sources :

Example 16 with LockException

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

the class AddNodeTest method testAddNodeOnLocked.

/**
     * Writing to a locked node must throw LockException even if the lock
     * isn't detected withing Jcr2Spi.
     *
     * @throws Exception
     * @see <a href="https://issues.apache.org/jira/browse/JCR-2585">JCR-2585</a>
     */
public void testAddNodeOnLocked() throws Exception {
    Session s = getHelper().getSuperuserSession();
    try {
        Node node = s.getNode(testRootNode.getPath());
        Node n = node.addNode(nodeName1);
        n.setProperty(propertyName1, "value");
        testRootNode.lock(true, true);
        s.save();
    } catch (LockException e) {
    // success
    } finally {
        s.logout();
    }
}
Also used : LockException(javax.jcr.lock.LockException) Node(javax.jcr.Node) Session(javax.jcr.Session)

Example 17 with LockException

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

the class SaveTest method testLockException.

/**
     * Tests if a {@link javax.jcr.lock.LockException} is thrown if a query is
     * stored under a node locked by another <code>Session</code>.
     * <p>
     * The test creates a node <code>nodeName1</code> of type <code>testNodeType</code>
     * under <code>testRoot</code> and locks the node with the superuser session.
     * Then the test tries to store a query as <code>nodeName2</code> under
     * <code>nodeName1</code> with the readWrite <code>Session</code>.
     * @throws NotExecutableException if nt:query is not supported.
     */
public void testLockException() throws RepositoryException, NotExecutableException {
    checkNtQuery();
    // check if repository supports locking
    if (!isSupported(Repository.OPTION_LOCKING_SUPPORTED)) {
        throw new NotExecutableException();
    }
    // create a node that is lockable
    Node lockable = testRootNode.addNode(nodeName1, testNodeType);
    // or try to make it lockable if it is not
    ensureMixinType(lockable, mixLockable);
    testRootNode.getSession().save();
    lockable.lock(false, true);
    Session readWrite = getHelper().getReadWriteSession();
    try {
        Query query = readWrite.getWorkspace().getQueryManager().createQuery(statement, Query.XPATH);
        query.storeAsNode(testRoot + "/" + nodeName1 + "/" + nodeName2);
        fail("Query.storeAsNode() must throw LockException, parent node is locked.");
    } catch (LockException e) {
    // expected behaviour
    } finally {
        readWrite.logout();
        lockable.unlock();
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Query(javax.jcr.query.Query) LockException(javax.jcr.lock.LockException) Node(javax.jcr.Node) Session(javax.jcr.Session)

Example 18 with LockException

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

the class LockManagerImpl method getLock.

/**
     * {@inheritDoc}
     */
public Lock getLock(NodeImpl node) throws LockException, RepositoryException {
    acquire();
    try {
        SessionImpl session = (SessionImpl) node.getSession();
        Path path = getPath(session, node.getId());
        PathMap.Element<LockInfo> element = lockMap.map(path, false);
        LockInfo info = element.get();
        if (info != null && (element.hasPath(path) || info.isDeep())) {
            NodeImpl lockHolder = (NodeImpl) session.getItemManager().getItem(info.getId());
            return new LockImpl(info, lockHolder);
        } else {
            throw new LockException("Node not locked: " + node);
        }
    } catch (ItemNotFoundException e) {
        throw new LockException("Node not locked: " + node);
    } finally {
        release();
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) NodeImpl(org.apache.jackrabbit.core.NodeImpl) LockException(javax.jcr.lock.LockException) SessionImpl(org.apache.jackrabbit.core.SessionImpl) PathMap(org.apache.jackrabbit.spi.commons.name.PathMap) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 19 with LockException

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

the class SessionLockManager method unlock.

/**
     * @see javax.jcr.lock.LockManager#unlock(String)
     */
public void unlock(String absPath) throws UnsupportedRepositoryOperationException, LockException, AccessDeniedException, InvalidItemStateException, RepositoryException {
    NodeImpl node = (NodeImpl) session.getNode(absPath);
    int options = ItemValidator.CHECK_HOLD | ItemValidator.CHECK_PENDING_CHANGES_ON_NODE;
    context.getItemValidator().checkModify(node, options, Permission.LOCK_MNGMT);
    checkLockable(node);
    synchronized (systemLockMgr) {
        // basic checks if unlock can be called on the node.
        if (!systemLockMgr.holdsLock(node)) {
            throw new LockException("Node not locked: " + node);
        }
        systemLockMgr.checkUnlock(session, node);
        systemLockMgr.unlock(node);
    }
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) LockException(javax.jcr.lock.LockException)

Example 20 with LockException

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

the class XALockManager method getLock.

/**
     * {@inheritDoc}
     */
public Lock getLock(NodeImpl node) throws LockException, RepositoryException {
    LockInfo info;
    if (isInXA()) {
        info = xaEnv.getLockInfo(node);
    } else {
        info = lockMgr.getLockInfo(node.getNodeId());
    }
    if (info == null) {
        throw new LockException("Node not locked: " + node);
    }
    SessionImpl session = (SessionImpl) node.getSession();
    NodeImpl holder = (NodeImpl) session.getItemManager().getItem(info.getId());
    return new XALockImpl(this, info, holder);
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) LockException(javax.jcr.lock.LockException) SessionImpl(org.apache.jackrabbit.core.SessionImpl)

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