Package javax.jcr.lock

Examples of javax.jcr.lock.LockManager


    public Lock getLock()
            throws UnsupportedRepositoryOperationException, LockException,
            AccessDeniedException, RepositoryException {
        // check state of this instance
        sanityCheck();
        LockManager lockMgr = session.getWorkspace().getLockManager();
        return lockMgr.getLock(getPath());
    }
View Full Code Here


            throws UnsupportedRepositoryOperationException, LockException,
            AccessDeniedException, InvalidItemStateException,
            RepositoryException {
        // check state of this instance
        sanityCheck();
        LockManager lockMgr = session.getWorkspace().getLockManager();
        lockMgr.unlock(getPath());
    }
View Full Code Here

     * {@inheritDoc}
     */
    public boolean holdsLock() throws RepositoryException {
        // check state of this instance
        sanityCheck();
        LockManager lockMgr = session.getWorkspace().getLockManager();
        return lockMgr.holdsLock(getPath());
    }
View Full Code Here

     * {@inheritDoc}
     */
    public boolean isLocked() throws RepositoryException {
        // check state of this instance
        sanityCheck();
        LockManager lockMgr = session.getWorkspace().getLockManager();
        return lockMgr.isLocked(getPath());
    }
View Full Code Here

    /**
     * Tests if <code>Version.lock(boolean, boolean)</code> throws a {@link
     * LockException}
     */
    public void testLockJcr2() throws Exception {
        LockManager lockManager = version.getSession().getWorkspace().getLockManager();
        String path = version.getPath();
        try {
            lockManager.lock(path, true, true, 60, "");
            fail("Version should not be lockable: Version.lock(true,true) did not throw a LockException");
        } catch (LockException success) {
        }
        try {
            lockManager.lock(path, true, false, 60, "");
            fail("Version should not be lockable: Version.lock(true,false) did not throw a LockException");
        } catch (LockException success) {
        }
        try {
            lockManager.lock(path, false, true, 60, "");
            fail("Version should not be lockable: Version.lock(false,true) did not throw a LockException");
        } catch (LockException success) {
        }
        try {
            lockManager.lock(path, false, false, 60, "");
            fail("Version should not be lockable: Version.lock(false,false) did not throw a LockException");
        } catch (LockException success) {
        }
    }
View Full Code Here

    /** {@inheritDoc} */
    public RemoteLockManager getLockManager()
            throws RepositoryException, RemoteException {
        try {
            if (remoteLockManager == null) {
                LockManager lockManager = workspace.getLockManager();
                remoteLockManager =
                    getFactory().getRemoteLockManager(lockManager);
            }
            return remoteLockManager;
        } catch (RepositoryException ex) {
View Full Code Here

    }

    public void testIsLockedWhileAnotherLockIsPresent() throws Exception {

        Session s = lockedNode.getSession();
        LockManager lm = s.getWorkspace().getLockManager();

        String l2token = null;
        String l2path = null;

        String path = lockedNode.getPath();
        String lockToken = lock.getLockToken();
        assertTrue(lm.isLocked(path));
        assertTrue(lm.holdsLock(path));
        lm.removeLockToken(lockToken);

        Session anotherSession = null;
        try {
            // check lock is seen by new session
            anotherSession = getHelper().getSuperuserSession();
            LockManager anotherLockManager = anotherSession.getWorkspace().getLockManager();
            assertTrue(anotherLockManager.isLocked(path));
            assertTrue(anotherLockManager.holdsLock(path));

            // create a second lock
            Node l2node = anotherSession.getNode(path).getParent().addNode("second-lock");
            l2node.addMixin(NodeType.MIX_LOCKABLE);
            anotherSession.save();
            l2path = l2node.getPath();

            Lock l2 = anotherLockManager.lock(l2path, false, false, Long.MAX_VALUE, "foobar");
            l2token = l2.getLockToken();
            assertNotNull(l2token);
            anotherSession.save();

            anotherSession.refresh(false);
            assertTrue(anotherLockManager.isLocked(path));
            assertTrue(anotherLockManager.holdsLock(path));

            // try to unlock the lock obtained from the other session
            anotherLockManager.addLockToken(lockToken);
            anotherLockManager.unlock(path);
            anotherSession.save();

            // unlock "my" lock
            anotherLockManager.unlock(l2path);
            anotherSession.save();
            l2path = null;
        }
        finally {
            if (anotherSession != null) {
                anotherSession.logout();
            }
            if (l2path != null && l2token != null) {
                superuser.refresh(false);
                LockManager sulm = superuser.getWorkspace().getLockManager();
                sulm.addLockToken(l2token);
                sulm.unlock(l2path);
            }
        }
    }
View Full Code Here

        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);
                fail("Adding token to another session must fail.");
            } catch (LockException e) {
                // success
            }
        } finally {
View Full Code Here

        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();
        }
    }
View Full Code Here

        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);
            fail("Adding the token to another session must fail.");
        } catch (LockException e) {
            // success
        } finally {
            otherLockMgr.removeLockToken(ltoken);
            lockMgr.addLockToken(ltoken);
            other.logout();
        }
    }
View Full Code Here

TOP

Related Classes of javax.jcr.lock.LockManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.