/** * Unlocks all locks corresponding to the tokens held by the supplied session. * * @param session the session on behalf of which the lock operation is being performed * @return a {@link Set} of the lock tokens that have been cleaned (removed from the system area and the corresponding nodes * unlocked) * @throws RepositoryException if the session is not live */ Set<String> cleanLocks( JcrSession session ) throws RepositoryException { Set<String> lockTokens = session.lockManager().lockTokens(); List<ModeShapeLock> locks = null; for (ModeShapeLock lock : locksByNodeKey.values()) { if (lock.isSessionScoped() && lockTokens.contains(lock.getLockToken())) { if (locks == null) locks = new LinkedList<ModeShapeLock>(); locks.add(lock); } } Set<String> cleanedTokens = null; if (locks != null) { cleanedTokens = new HashSet<>(locks.size()); // clear the locks which have been unlocked unlock(session, locks); for (ModeShapeLock lock : locks) { locksByNodeKey.remove(lock.getLockedNodeKey()); cleanedTokens.add(lock.getLockToken()); } } return cleanedTokens != null ? cleanedTokens : Collections.<String>emptySet(); }
/** * Unlocks all locks corresponding to the tokens held by the supplied session. * * @param session the session on behalf of which the lock operation is being performed * @return a {@link Set} of the lock tokens that have been cleaned (removed from the system area and the corresponding nodes * unlocked) * @throws RepositoryException if the session is not live */ Set<String> cleanLocks( JcrSession session ) throws RepositoryException { Set<String> lockTokens = session.lockManager().lockTokens(); List<ModeShapeLock> locks = null; for (ModeShapeLock lock : locksByNodeKey.values()) { if (lock.isSessionScoped() && lockTokens.contains(lock.getLockToken())) { if (locks == null) locks = new LinkedList<ModeShapeLock>(); locks.add(lock); } } Set<String> cleanedTokens = null; if (locks != null) { cleanedTokens = new HashSet<>(locks.size()); // clear the locks which have been unlocked unlock(session, locks); for (ModeShapeLock lock : locks) { locksByNodeKey.remove(lock.getLockedNodeKey()); cleanedTokens.add(lock.getLockToken()); } } return cleanedTokens != null ? cleanedTokens : Collections.<String>emptySet(); }
String unlock( JcrSession session, NodeKey lockedNodeKey ) throws LockException { ModeShapeLock existing = locksByNodeKey.remove(lockedNodeKey); if (existing == null) { NodeCache cache = session.cache(); String location = session.stringFactory().create(cache.getNode(lockedNodeKey).getPath(cache)); throw new LockException(JcrI18n.notLocked.text(location)); } unlock(session, Collections.singleton(existing)); return existing.getLockToken(); }
String unlock( JcrSession session, NodeKey lockedNodeKey ) throws LockException { ModeShapeLock existing = locksByNodeKey.remove(lockedNodeKey); if (existing == null) { NodeCache cache = session.cache(); String location = session.stringFactory().create(cache.getNode(lockedNodeKey).getPath(cache)); throw new LockException(JcrI18n.notLocked.text(location)); } unlock(session, Collections.singleton(existing)); return existing.getLockToken(); }
public void unlock( AbstractJcrNode node ) throws PathNotFoundException, LockException, AccessDeniedException, InvalidItemStateException, RepositoryException { if (node.isModified()) { throw new InvalidItemStateException(JcrI18n.changedNodeCannotBeUnlocked.text(node.getPath())); } ModeShapeLock lock = lockManager.findLockFor(node.key()); if (lock != null && !lockTokens.contains(lock.getLockToken())) { // Someone else holds the lock, so see if the user has the permission to break someone else's lock ... try { session.checkPermission(session.workspaceName(), node.path(), ModeShapePermissions.UNLOCK_ANY); } catch (AccessDeniedException e) { //expected by the TCK throw new LockException(e); } } // Remove the lock ... String lockToken = lockManager.unlock(session, node.key()); lockTokens.remove(lockToken); }
public void unlock( AbstractJcrNode node ) throws PathNotFoundException, LockException, AccessDeniedException, InvalidItemStateException, RepositoryException { if (node.isModified()) { throw new InvalidItemStateException(JcrI18n.changedNodeCannotBeUnlocked.text(node.getPath())); } ModeShapeLock lock = lockManager.findLockFor(node.key()); if (lock != null && !lockTokens.contains(lock.getLockToken())) { // Someone else holds the lock, so see if the user has the permission to break someone else's lock ... try { session.checkPermission(session.workspaceName(), node.path(), ModeShapePermissions.UNLOCK_ANY); } catch (AccessDeniedException e) { //expected by the TCK throw new LockException(e); } } // Remove the lock ... String lockToken = lockManager.unlock(session, node.key()); lockTokens.remove(lockToken); }
unlock(session, existing.lockedNodeKey);
unlock(session, existing.lockedNodeKey);