Package javax.jcr.lock

Examples of javax.jcr.lock.Lock


        Node n = testRootNode.addNode(nodeName1);
        n.addMixin(mixLockable);
        n.addMixin(mixReferenceable);
        testRootNode.save();

        Lock lock = n.lock(false, true);

        // get user transaction object, start
        UserTransaction utx = new UserTransactionImpl(superuser);
        utx.begin();

        // unlock
        n.unlock();

        Node n2 = (Node) otherSuperuser.getItem(n.getPath());
        assertTrue(n2.isLocked());
        assertTrue(n2.hasProperty(jcrLockOwner));
        assertTrue(n2.hasProperty(jcrlockIsDeep));
        Lock lock2 = n2.getLock();

        // complete transaction
        utx.commit();

        // unlock must now be visible to other session
        n2.refresh(false);
        assertFalse(lock2.isLive());
        assertFalse(n2.isLocked());
        assertFalse(n2.hasProperty(jcrLockOwner));
        assertFalse(n2.hasProperty(jcrlockIsDeep));
    }
View Full Code Here


        rootNode.save();

        String uuid = n.getUUID();
       
        // lock this new node
        Lock lock = n.lock(true, false);
        String lockToken = lock.getLockToken();
       
        // assert: session must get a non-null lock token
        assertNotNull("session must get a non-null lock token", lockToken);

        // assert: session must hold lock token
        assertTrue("session must hold lock token", containsLockToken(superuser, lockToken));

        superuser.removeLockToken(lockToken);
        assertNull("session must get a null lock token", lock.getLockToken());
       
        // commit
        utx.commit();
       
        // refresh Lock Info
        lock = n.getLock();

        assertNull("session must get a null lock token", lock.getLockToken());

        Session other = getHelper().getSuperuserSession();
        // start new Transaction and try to add lock token unlock the node and then remove it
        utx = new UserTransactionImpl(other);
        utx.begin();
       
        Node otherNode = other.getNodeByUUID(uuid);
        assertTrue("Node not locked", otherNode.isLocked());
        // add lock token
        other.addLockToken(lockToken);
     
        // refresh Lock Info
        lock = otherNode.getLock();

        // assert: session must hold lock token
        assertTrue("session must hold lock token", containsLockToken(other, lock.getLockToken()));       
       
        otherNode.unlock();
       
        assertFalse("Node is locked", otherNode.isLocked());
       
View Full Code Here

        rootNode.save();

        String uuid = n.getUUID();
       
        // lock this new node
        Lock lock = n.lock(true, false);
        String lockToken = lock.getLockToken();
       
        // commit
        utx.commit();
       
       
View Full Code Here

        if (Type.WRITE.equals(type)) {
            try {
                if (!exists()) {
                    log.warn("Unable to retrieve lock: no item found at '" + getResourcePath() + "'");
                } else if (((Node) item).isLocked()) {
                    Lock jcrLock = ((Node) item).getLock();
                    lock = new JcrActiveLock(jcrLock);
                }
            } catch (AccessDeniedException e) {
                log.error("Error while accessing resource lock: "+e.getMessage());
            } catch (UnsupportedRepositoryOperationException e) {
View Full Code Here

                log.warn("Cannot create a write lock for non-existing JCR node (" + getResourcePath() + ")");
                throw new DavException(DavServletResponse.SC_NOT_FOUND);
            }
            try {
                boolean sessionScoped = EXCLUSIVE_SESSION.equals(reqLockInfo.getScope());
                Lock jcrLock = ((Node)item).lock(reqLockInfo.isDeep(), sessionScoped);
                ActiveLock lock = new JcrActiveLock(jcrLock);
                 // add reference to DAVSession for this lock
                getSession().addReference(lock.getToken());
                return lock;
            } catch (RepositoryException e) {
View Full Code Here

            throw new DavException(DavServletResponse.SC_PRECONDITION_FAILED, "No lock with the given scope/type present on this resource.");
        }

        if (Type.WRITE.equals(lock.getType())) {
            try {
                Lock jcrLock = ((Node) item).getLock();
                jcrLock.refresh();
                return new JcrActiveLock(jcrLock);
            } catch (RepositoryException e) {
                /*
                  NOTE: LockException is only thrown by Lock.refresh()
                        the lock exception thrown by Node.getLock() was circumvented
View Full Code Here

        ActiveLock lock = null;
        if (exists() && Type.WRITE.equals(type) && Scope.EXCLUSIVE.equals(scope)) {
            // try to retrieve the repository lock information first
            try {
                if (node.isLocked()) {
                    Lock jcrLock = node.getLock();
                    if (jcrLock != null && jcrLock.isLive()) {
                        lock = new JcrActiveLock(jcrLock);
                    }
                }
            } catch (RepositoryException e) {
                // LockException (no lock applies) >> should never occur
View Full Code Here

        if (isLockable(lockInfo.getType(), lockInfo.getScope())) {
            // TODO: deal with existing locks, that may have been created, before the node was jcr-lockable...
            if (isJsrLockable()) {
                try {
                    // try to execute the lock operation
                    Lock jcrLock = node.lock(lockInfo.isDeep(), false);
                    if (jcrLock != null) {
                        lock = new JcrActiveLock(jcrLock);
                    }
                } catch (RepositoryException e) {
                    throw new JcrDavException(e);
View Full Code Here

        Node lockedNode2 = testRoot2.addNode(nodeName2, testNodeType);
        lockedNode2.addMixin(mixLockable);
        testRoot2.save();

        Lock lock2 = lockedNode2.lock(false, isSessionScoped());

        // force reloading of the testroot in order to be aware of the
        // locked node added by another session
        testRootNode.refresh(false);
        Node n2 = (Node) superuser.getItem(lockedNode2.getPath());
        try {
            String lockToken = lock2.getLockToken();
            otherSession.removeLockToken(lockToken);
            superuser.addLockToken(lockToken);
            otherSession.logout();

            assertTrue("After logout a open-scoped node must still be locked.", lock2.isLive());
            assertTrue("After logout a open-scoped node must still be locked.", n2.isLocked());
        } finally {
            n2.unlock();
        }
    }
View Full Code Here

  }

  @Override
  public boolean lock(int timeout) throws CaoException {
    try {
      Lock lock = null;
      LockManager manager = node.getSession().getWorkspace().getLockManager();
        try {
          lock = manager.getLock(node.getPath());
          if (lock.getLockToken() != null) {
            return true;
          }
        } catch (LockException e) {
        }
        lock = null;
View Full Code Here

TOP

Related Classes of javax.jcr.lock.Lock

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.