Here are the examples of the java api class javax.jcr.lock.LockManager taken from open source projects.
1. JcrLockManagerTest#lockTokensShouldBeRemovedFromSessionUponLogout()
Project: modeshape
File: JcrLockManagerTest.java
File: JcrLockManagerTest.java
@Test @FixFor("MODE-2342") public void lockTokensShouldBeRemovedFromSessionUponLogout() throws Exception { final AbstractJcrNode testNode = session.getRootNode().addNode("test"); final String path = testNode.getPath(); testNode.addMixin("mix:lockable"); session.save(); final Lock lock = session.getWorkspace().getLockManager().lock(path, false, false, Long.MAX_VALUE, session.getUserID()); final String token = lock.getLockToken(); Assert.assertNotNull(token); session.logout(); Session session2 = repository.login(); final LockManager lockManager = session2.getWorkspace().getLockManager(); lockManager.addLockToken(token); Assert.assertTrue("New session should now own the lock.", lockManager.getLock(path).isLockOwningSession()); }
2. VersionManagementTest#testCheckInCheckoutLocked()
Project: jackrabbit-oak
File: VersionManagementTest.java
File: VersionManagementTest.java
@Test public void testCheckInCheckoutLocked() throws Exception { LockManager lockManager = superuser.getWorkspace().getLockManager(); VersionManager versionManager = superuser.getWorkspace().getVersionManager(); // create a versionable and lockable node Node n = createVersionableNode(superuser.getNode(path)); n.addMixin(mixLockable); superuser.save(); String nodePath = n.getPath(); // lock lockManager.lock(nodePath, true, false, 0, superuser.getUserID()); // create version versionManager.checkin(nodePath); versionManager.checkout(nodePath); }
3. VersionTest#testLockJcr2()
Project: jackrabbit
File: VersionTest.java
File: VersionTest.java
/** * 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) { } }
4. VersionHistoryTest#testLockJcr2()
Project: jackrabbit
File: VersionHistoryTest.java
File: VersionHistoryTest.java
/** * Tests if <code>VersionHistory.lock(boolean, boolean)</code> throws a * {@link javax.jcr.lock.LockException} */ public void testLockJcr2() throws Exception { LockManager lockManager = vHistory.getSession().getWorkspace().getLockManager(); String path = vHistory.getPath(); try { lockManager.lock(path, true, true, 60, ""); fail("VersionHistory should not be lockable: VersionHistory.lock(true,true) did not throw a LockException"); } catch (LockException success) { } try { lockManager.lock(path, true, false, 60, ""); fail("VersionHistory should not be lockable: VersionHistory.lock(true,false) did not throw a LockException"); } catch (LockException success) { } try { lockManager.lock(path, false, true, 60, ""); fail("VersionHistory should not be lockable: VersionHistory.lock(false,true) did not throw a LockException"); } catch (LockException success) { } try { lockManager.lock(path, false, false, 60, ""); fail("VersionHistory should not be lockable: VersionHistory.lock(false,false) did not throw a UnsupportedRepositoryOperationException"); } catch (LockException success) { } }
5. LockManagerTest#testLockTransfer3()
Project: jackrabbit
File: LockManagerTest.java
File: LockManagerTest.java
public void testLockTransfer3() throws Exception { assertLockable(testNode); 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.removeLockToken(ltoken); fail("Removing a token that has been transfered to another manager must fail."); } catch (LockException e) { } finally { otherLockMgr.removeLockToken(ltoken); lockMgr.addLockToken(ltoken); other.logout(); } }
6. LockManagerTest#testLockTransfer2()
Project: jackrabbit
File: LockManagerTest.java
File: LockManagerTest.java
public void testLockTransfer2() throws Exception { // TODO: for 283 add config option for simultaneous tokens.... assertLockable(testNode); 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) { } finally { otherLockMgr.removeLockToken(ltoken); lockMgr.addLockToken(ltoken); other.logout(); } }
7. LockManagerTest#testLockTransfer()
Project: jackrabbit
File: LockManagerTest.java
File: LockManagerTest.java
public void testLockTransfer() throws Exception { assertLockable(testNode); 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(); } }
8. ModeShapeTckTest#testShouldVerifyDeepLockAllowsSameSessionToChangeChildProperties()
Project: modeshape
File: ModeShapeTckTest.java
File: ModeShapeTckTest.java
@FixFor("MODE-1040") @SuppressWarnings("unused") public void testShouldVerifyDeepLockAllowsSameSessionToChangeChildProperties() throws Exception { Session session1 = getHelper().getSuperuserSession(); LockManager lm1 = session1.getWorkspace().getLockManager(); // Create node structure Node root1 = getTestRoot(session1); Node tmp = root1.addNode("tmp", "nt:unstructured"); Node node1 = tmp.addNode("node1", "nt:unstructured"); Node node2 = tmp.addNode("node1/node2", "nt:unstructured"); Node node3 = tmp.addNode("node1/node2/node3", "nt:unstructured"); session1.save(); // Create an open-scoped shallow lock on node2 node2.addMixin("mix:lockable"); session1.save(); lm1.lock(node2.getPath(), true, false, 100000, "Locked"); session1.save(); // Attempt to a child node of node2 Node toChange = node2; try { toChange.setProperty("newProp", "newValue"); session1.save(); } finally { tmp.remove(); session1.save(); session1.logout(); } }
9. ModeShapeTckTest#testShouldVerifyDeepLockPreventsOtherSessionsFromChangePropertiesOfChildOfLockedNode()
Project: modeshape
File: ModeShapeTckTest.java
File: ModeShapeTckTest.java
@FixFor("MODE-1040") @SuppressWarnings("unused") public void testShouldVerifyDeepLockPreventsOtherSessionsFromChangePropertiesOfChildOfLockedNode() throws Exception { Session session1 = getHelper().getSuperuserSession(); Session session2 = getHelper().getSuperuserSession(); LockManager lm1 = session1.getWorkspace().getLockManager(); // Create node structure Node root1 = getTestRoot(session1); Node tmp = root1.addNode("tmp", "nt:folder"); Node node1 = tmp.addNode("node1", "nt:folder"); Node node2 = tmp.addNode("node1/node2", "nt:folder"); Node node3 = tmp.addNode("node1/node2/node3", "nt:folder"); session1.save(); // Create an open-scoped shallow lock on node2 node2.addMixin("mix:lockable"); session1.save(); lm1.lock(node2.getPath(), true, false, 100000, "Locked"); session1.save(); // Attempt to a child node of node2 session2.refresh(true); Node toChange = session2.getNode(node3.getPath()); try { toChange.addMixin("mix:referenceable"); session2.save(); fail("Expected to see LockException"); } catch (LockException e) { } finally { tmp.remove(); session1.save(); session1.logout(); session2.logout(); } }
10. ModeShapeTckTest#testShouldVerifyDeepLockAllowsSameSessionToDeleteChildOfLockedNode()
Project: modeshape
File: ModeShapeTckTest.java
File: ModeShapeTckTest.java
@FixFor("MODE-1040") @SuppressWarnings("unused") public void testShouldVerifyDeepLockAllowsSameSessionToDeleteChildOfLockedNode() throws Exception { Session session1 = getHelper().getSuperuserSession(); Session session2 = getHelper().getSuperuserSession(); LockManager lm1 = session1.getWorkspace().getLockManager(); // Create node structure Node root1 = getTestRoot(session1); Node tmp = root1.addNode("tmp", "nt:folder"); Node node1 = tmp.addNode("node1", "nt:folder"); Node node2 = tmp.addNode("node1/node2", "nt:folder"); Node node3 = tmp.addNode("node1/node2/node3", "nt:folder"); session1.save(); // Create an open-scoped shallow lock on node2 node2.addMixin("mix:lockable"); session1.save(); lm1.lock(node2.getPath(), true, false, 10000, "Locked"); session1.save(); // Attempt to a child node of node2 try { node3.remove(); } finally { tmp.remove(); session1.save(); session1.logout(); session2.logout(); } }
11. ModeShapeTckTest#testShouldVerifyDeepLockPreventsOtherSessionsFromDeletingChildOfLockedNode()
Project: modeshape
File: ModeShapeTckTest.java
File: ModeShapeTckTest.java
@FixFor("MODE-1040") @SuppressWarnings("unused") public void testShouldVerifyDeepLockPreventsOtherSessionsFromDeletingChildOfLockedNode() throws Exception { Session session1 = getHelper().getSuperuserSession(); Session session2 = getHelper().getSuperuserSession(); LockManager lm1 = session1.getWorkspace().getLockManager(); // Create node structure Node root1 = getTestRoot(session1); Node tmp = root1.addNode("tmp", "nt:folder"); Node node1 = tmp.addNode("node1", "nt:folder"); Node node2 = tmp.addNode("node1/node2", "nt:folder"); Node node3 = tmp.addNode("node1/node2/node3", "nt:folder"); session1.save(); // Create an open-scoped shallow lock on node2 node2.addMixin("mix:lockable"); session1.save(); lm1.lock(node2.getPath(), true, false, 10000, "Locked"); session1.save(); // Attempt to a child node of node2 session2.refresh(true); Node toDelete = session2.getNode(node3.getPath()); try { toDelete.remove(); fail("Expected to see LockException"); } catch (LockException e) { } finally { tmp.remove(); session1.save(); session1.logout(); session2.logout(); } }
12. ModeShapeTckTest#testShouldVerifyDeepLockAllowsSameSessionToDeleteLockedNode()
Project: modeshape
File: ModeShapeTckTest.java
File: ModeShapeTckTest.java
@FixFor("MODE-1040") @SuppressWarnings("unused") public void testShouldVerifyDeepLockAllowsSameSessionToDeleteLockedNode() throws Exception { Session session1 = getHelper().getSuperuserSession(); LockManager lm1 = session1.getWorkspace().getLockManager(); // Create node structure Node root1 = getTestRoot(session1); Node tmp = root1.addNode("tmp", "nt:folder"); Node node1 = tmp.addNode("node1", "nt:folder"); Node node2 = tmp.addNode("node1/node2", "nt:folder"); Node node3 = tmp.addNode("node1/node2/node3", "nt:folder"); session1.save(); // Create an open-scoped shallow lock on node2 node2.addMixin("mix:lockable"); session1.save(); lm1.lock(node2.getPath(), true, false, 10000, "Locked"); session1.save(); // Attempt to a child node of node2 try { node3.remove(); } finally { tmp.remove(); session1.save(); session1.logout(); } }
13. ModeShapeTckTest#testShouldVerifyDeepLockAllowsOtherSessionsToDeleteLockedNode()
Project: modeshape
File: ModeShapeTckTest.java
File: ModeShapeTckTest.java
@FixFor("MODE-1040") @SuppressWarnings("unused") public void testShouldVerifyDeepLockAllowsOtherSessionsToDeleteLockedNode() throws Exception { Session session1 = getHelper().getSuperuserSession(); Session session2 = getHelper().getSuperuserSession(); LockManager lm1 = session1.getWorkspace().getLockManager(); // Create node structure Node root1 = getTestRoot(session1); Node tmp = root1.addNode("tmp", "nt:folder"); Node node1 = tmp.addNode("node1", "nt:folder"); Node node2 = tmp.addNode("node1/node2", "nt:folder"); Node node3 = tmp.addNode("node1/node2/node3", "nt:folder"); session1.save(); // Create an open-scoped shallow lock on node2 node2.addMixin("mix:lockable"); session1.save(); lm1.lock(node2.getPath(), true, false, 100000, "Locked"); session1.save(); // Attempt to a child node of node2 session2.refresh(true); Node toDelete = session2.getNode(node2.getPath()); try { // This is possible because removing node2 is an alteration of node1, upon which there is no lock toDelete.remove(); session2.save(); } finally { tmp.remove(); session1.save(); session1.logout(); session2.logout(); } }
14. ModeShapeTckTest#testShouldVerifyDeepLockPreventsOtherSessionsFromChangingPropertiesOnLockedNode()
Project: modeshape
File: ModeShapeTckTest.java
File: ModeShapeTckTest.java
@FixFor("MODE-1040") @SuppressWarnings("unused") public void testShouldVerifyDeepLockPreventsOtherSessionsFromChangingPropertiesOnLockedNode() throws Exception { Session session1 = getHelper().getSuperuserSession(); Session session2 = getHelper().getSuperuserSession(); LockManager lm1 = session1.getWorkspace().getLockManager(); // Create node structure Node root1 = getTestRoot(session1); Node tmp = root1.addNode("tmp", "nt:folder"); Node node1 = tmp.addNode("node1", "nt:folder"); Node node2 = tmp.addNode("node1/node2", "nt:folder"); Node node3 = tmp.addNode("node1/node2/node3", "nt:folder"); session1.save(); // Create an open-scoped shallow lock on node2 node2.addMixin("mix:lockable"); session1.save(); lm1.lock(node2.getPath(), true, false, 100000, "Locked"); session1.save(); // Attempt to a child node of node2 session2.refresh(true); Node toChange = session2.getNode(node2.getPath()); try { toChange.addMixin("mix:versionable"); fail("Expected to see LockException"); } catch (LockException e) { } finally { tmp.remove(); session1.save(); session1.logout(); session2.logout(); } }
15. ModeShapeTckTest#testShouldVerifyShallowLockAllowsSameSessionToChangeChildProperties()
Project: modeshape
File: ModeShapeTckTest.java
File: ModeShapeTckTest.java
@FixFor("MODE-1040") @SuppressWarnings("unused") public void testShouldVerifyShallowLockAllowsSameSessionToChangeChildProperties() throws Exception { Session session1 = getHelper().getSuperuserSession(); LockManager lm1 = session1.getWorkspace().getLockManager(); // Create node structure Node root1 = getTestRoot(session1); Node tmp = root1.addNode("tmp", "nt:unstructured"); Node node1 = tmp.addNode("node1", "nt:unstructured"); Node node2 = tmp.addNode("node1/node2", "nt:unstructured"); Node node3 = tmp.addNode("node1/node2/node3", "nt:unstructured"); session1.save(); // Create an open-scoped shallow lock on node2 node2.addMixin("mix:lockable"); session1.save(); lm1.lock(node2.getPath(), false, false, 100000, "Locked"); session1.save(); // Attempt to a child node of node2 Node toChange = node2; try { toChange.setProperty("newProp", "newValue"); session1.save(); } finally { tmp.remove(); session1.save(); session1.logout(); } }
16. ModeShapeTckTest#testShouldVerifyShallowLockAllowOtherSessionsToChangePropertiesOfChildOfLockedNode()
Project: modeshape
File: ModeShapeTckTest.java
File: ModeShapeTckTest.java
@FixFor("MODE-1040") @SuppressWarnings("unused") public void testShouldVerifyShallowLockAllowOtherSessionsToChangePropertiesOfChildOfLockedNode() throws Exception { Session session1 = getHelper().getSuperuserSession(); Session session2 = getHelper().getSuperuserSession(); LockManager lm1 = session1.getWorkspace().getLockManager(); // Create node structure Node root1 = getTestRoot(session1); Node tmp = root1.addNode("tmp", "nt:folder"); Node node1 = tmp.addNode("node1", "nt:folder"); Node node2 = tmp.addNode("node1/node2", "nt:folder"); Node node3 = tmp.addNode("node1/node2/node3", "nt:folder"); session1.save(); // Create an open-scoped shallow lock on node2 node2.addMixin("mix:lockable"); session1.save(); lm1.lock(node2.getPath(), false, false, 100000, "Locked"); session1.save(); // Attempt to a child node of node2 session2.refresh(true); Node toChange = session2.getNode(node3.getPath()); try { toChange.addMixin("mix:referenceable"); session2.save(); } finally { tmp.remove(); session1.save(); session1.logout(); session2.logout(); } }
17. ModeShapeTckTest#testShouldVerifyShallowLockAllowsSameSessionToDeleteChildOfLockedNode()
Project: modeshape
File: ModeShapeTckTest.java
File: ModeShapeTckTest.java
@FixFor("MODE-1040") @SuppressWarnings("unused") public void testShouldVerifyShallowLockAllowsSameSessionToDeleteChildOfLockedNode() throws Exception { Session session1 = getHelper().getSuperuserSession(); Session session2 = getHelper().getSuperuserSession(); LockManager lm1 = session1.getWorkspace().getLockManager(); // Create node structure Node root1 = getTestRoot(session1); Node tmp = root1.addNode("tmp", "nt:folder"); Node node1 = tmp.addNode("node1", "nt:folder"); Node node2 = tmp.addNode("node1/node2", "nt:folder"); Node node3 = tmp.addNode("node1/node2/node3", "nt:folder"); session1.save(); // Create an open-scoped shallow lock on node2 node2.addMixin("mix:lockable"); session1.save(); lm1.lock(node2.getPath(), false, false, 10000, "Locked"); session1.save(); // Attempt to a child node of node2 try { node3.remove(); } finally { tmp.remove(); session1.save(); session1.logout(); session2.logout(); } }
18. ModeShapeTckTest#testShouldVerifyShallowLockPreventsOtherSessionsFromDeletingChildOfLockedNode()
Project: modeshape
File: ModeShapeTckTest.java
File: ModeShapeTckTest.java
@FixFor("MODE-1040") @SuppressWarnings("unused") public void testShouldVerifyShallowLockPreventsOtherSessionsFromDeletingChildOfLockedNode() throws Exception { Session session1 = getHelper().getSuperuserSession(); Session session2 = getHelper().getSuperuserSession(); LockManager lm1 = session1.getWorkspace().getLockManager(); // Create node structure Node root1 = getTestRoot(session1); Node tmp = root1.addNode("tmp", "nt:folder"); Node node1 = tmp.addNode("node1", "nt:folder"); Node node2 = tmp.addNode("node1/node2", "nt:folder"); Node node3 = tmp.addNode("node1/node2/node3", "nt:folder"); session1.save(); // Create an open-scoped shallow lock on node2 node2.addMixin("mix:lockable"); session1.save(); lm1.lock(node2.getPath(), false, false, 10000, "Locked"); session1.save(); // Attempt to a child node of node2 session2.refresh(true); Node toDelete = session2.getNode(node3.getPath()); try { toDelete.remove(); fail("Expected to see LockException"); } catch (LockException e) { } finally { tmp.remove(); session1.save(); session1.logout(); session2.logout(); } }
19. ModeShapeTckTest#testShouldVerifyShallowLockAllowsSameSessionToDeleteLockedNode()
Project: modeshape
File: ModeShapeTckTest.java
File: ModeShapeTckTest.java
@FixFor("MODE-1040") @SuppressWarnings("unused") public void testShouldVerifyShallowLockAllowsSameSessionToDeleteLockedNode() throws Exception { Session session1 = getHelper().getSuperuserSession(); LockManager lm1 = session1.getWorkspace().getLockManager(); // Create node structure Node root1 = getTestRoot(session1); Node tmp = root1.addNode("tmp", "nt:folder"); Node node1 = tmp.addNode("node1", "nt:folder"); Node node2 = tmp.addNode("node1/node2", "nt:folder"); Node node3 = tmp.addNode("node1/node2/node3", "nt:folder"); session1.save(); // Create an open-scoped shallow lock on node2 node2.addMixin("mix:lockable"); session1.save(); lm1.lock(node2.getPath(), false, false, 10000, "Locked"); session1.save(); // Attempt to a child node of node2 try { node3.remove(); } finally { tmp.remove(); session1.save(); session1.logout(); } }
20. ModeShapeTckTest#testShouldVerifyShallowLockAllowsOtherSessionsToDeleteLockedNode()
Project: modeshape
File: ModeShapeTckTest.java
File: ModeShapeTckTest.java
@FixFor("MODE-1040") @SuppressWarnings("unused") public void testShouldVerifyShallowLockAllowsOtherSessionsToDeleteLockedNode() throws Exception { Session session1 = getHelper().getSuperuserSession(); Session session2 = getHelper().getSuperuserSession(); LockManager lm1 = session1.getWorkspace().getLockManager(); // Create node structure Node root1 = getTestRoot(session1); Node tmp = root1.addNode("tmp", "nt:folder"); Node node1 = tmp.addNode("node1", "nt:folder"); Node node2 = tmp.addNode("node1/node2", "nt:folder"); Node node3 = tmp.addNode("node1/node2/node3", "nt:folder"); session1.save(); // Create an open-scoped shallow lock on node2 node2.addMixin("mix:lockable"); session1.save(); lm1.lock(node2.getPath(), false, false, 100000, "Locked"); session1.save(); // Attempt to a child node of node2 session2.refresh(true); Node toDelete = session2.getNode(node2.getPath()); try { // This is possible because removing node2 is an alteration of node1, upon which there is no lock toDelete.remove(); session2.save(); } finally { tmp.remove(); session1.save(); session1.logout(); session2.logout(); } }
21. ModeShapeTckTest#testShouldVerifyShallowLockPreventsOtherSessionsFromChangingPropertiesOnLockedNode()
Project: modeshape
File: ModeShapeTckTest.java
File: ModeShapeTckTest.java
@FixFor("MODE-1040") @SuppressWarnings("unused") public void testShouldVerifyShallowLockPreventsOtherSessionsFromChangingPropertiesOnLockedNode() throws Exception { Session session1 = getHelper().getSuperuserSession(); Session session2 = getHelper().getSuperuserSession(); LockManager lm1 = session1.getWorkspace().getLockManager(); // Create node structure Node root1 = getTestRoot(session1); Node tmp = root1.addNode("tmp", "nt:folder"); Node node1 = tmp.addNode("node1", "nt:folder"); Node node2 = tmp.addNode("node1/node2", "nt:folder"); Node node3 = tmp.addNode("node1/node2/node3", "nt:folder"); session1.save(); // subgraph(root1); // Create an open-scoped shallow lock on node2 node2.addMixin("mix:lockable"); session1.save(); lm1.lock(node2.getPath(), false, false, 100000, "Locked"); session1.save(); // Attempt to a child node of node2 session2.refresh(true); Node toChange = session2.getNode(node2.getPath()); try { toChange.addMixin("mix:versionable"); fail("Expected to see LockException"); } catch (LockException e) { } finally { tmp.remove(); session1.save(); session1.logout(); session2.logout(); } }
22. OpenScopedLockTest#testIsLockedWhileAnotherLockIsPresent()
Project: jackrabbit
File: OpenScopedLockTest.java
File: OpenScopedLockTest.java
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); } } }
23. NodeImpl#isLocked()
Project: jackrabbit
File: NodeImpl.java
File: NodeImpl.java
/** * {@inheritDoc} */ public boolean isLocked() throws RepositoryException { // check state of this instance sanityCheck(); LockManager lockMgr = getSession().getWorkspace().getLockManager(); return lockMgr.isLocked(getPath()); }
24. NodeImpl#holdsLock()
Project: jackrabbit
File: NodeImpl.java
File: NodeImpl.java
/** * {@inheritDoc} */ public boolean holdsLock() throws RepositoryException { // check state of this instance sanityCheck(); LockManager lockMgr = getSession().getWorkspace().getLockManager(); return lockMgr.holdsLock(getPath()); }
25. NodeImpl#unlock()
Project: jackrabbit
File: NodeImpl.java
File: NodeImpl.java
/** * {@inheritDoc} */ public void unlock() throws UnsupportedRepositoryOperationException, LockException, AccessDeniedException, InvalidItemStateException, RepositoryException { // check state of this instance sanityCheck(); LockManager lockMgr = getSession().getWorkspace().getLockManager(); lockMgr.unlock(getPath()); }
26. NodeImpl#getLock()
Project: jackrabbit
File: NodeImpl.java
File: NodeImpl.java
/** * {@inheritDoc} */ public Lock getLock() throws UnsupportedRepositoryOperationException, LockException, AccessDeniedException, RepositoryException { // check state of this instance sanityCheck(); LockManager lockMgr = getSession().getWorkspace().getLockManager(); return lockMgr.getLock(getPath()); }
27. NodeImpl#lock()
Project: jackrabbit
File: NodeImpl.java
File: NodeImpl.java
//------------------------------------------------------< locking support > /** * {@inheritDoc} */ public Lock lock(boolean isDeep, boolean isSessionScoped) throws UnsupportedRepositoryOperationException, LockException, AccessDeniedException, InvalidItemStateException, RepositoryException { // check state of this instance sanityCheck(); LockManager lockMgr = getSession().getWorkspace().getLockManager(); return lockMgr.lock(getPath(), isDeep, isSessionScoped, sessionContext.getWorkspace().getConfig().getDefaultLockTimeout(), null); }
28. ModeShapeTckTest#testShouldVerifyAddingMixinAndSavingRequiredBeforeLockingNode()
Project: modeshape
File: ModeShapeTckTest.java
File: ModeShapeTckTest.java
@FixFor("MODE-1040") @SuppressWarnings("unused") public void testShouldVerifyAddingMixinAndSavingRequiredBeforeLockingNode() throws Exception { Session session1 = getHelper().getSuperuserSession(); LockManager lm1 = session1.getWorkspace().getLockManager(); // Create node structure Node root1 = getTestRoot(session1); Node tmp = root1.addNode("tmp", "nt:folder"); Node node1 = tmp.addNode("node1", "nt:folder"); Node node2 = tmp.addNode("node1/node2", "nt:folder"); Node node3 = tmp.addNode("node1/node2/node3", "nt:folder"); session1.save(); // Create an open-scoped shallow lock on node2 try { node2.addMixin("mix:lockable"); lm1.lock(node2.getPath(), false, false, 10000, "Locked"); session1.save(); } catch (InvalidItemStateException e) { } finally { tmp.remove(); session1.save(); session1.logout(); } }
29. AbstractLockManagementTest#testLockBreaking()
Project: jackrabbit
File: AbstractLockManagementTest.java
File: AbstractLockManagementTest.java
public void testLockBreaking() throws RepositoryException, NotExecutableException { String locktoken = null; LockManager sulm = superuser.getWorkspace().getLockManager(); String lockedpath = null; try { Node trn = getTestNode(); modifyPrivileges(trn.getPath(), Privilege.JCR_READ, true); modifyPrivileges(trn.getPath(), PrivilegeRegistry.REP_WRITE, true); modifyPrivileges(trn.getPath(), Privilege.JCR_LOCK_MANAGEMENT, true); Session lockingSession = trn.getSession(); assertFalse("super user and test user should have different user ids: " + lockingSession.getUserID() + " vs " + superuser.getUserID(), lockingSession.getUserID().equals(superuser.getUserID())); trn.addNode("locktest", "nt:unstructured"); trn.addMixin("mix:lockable"); lockingSession.save(); // let the "other" user lock the node LockManager oulm = lockingSession.getWorkspace().getLockManager(); Lock l = oulm.lock(trn.getPath(), true, false, Long.MAX_VALUE, null); lockedpath = trn.getPath(); locktoken = l.getLockToken(); lockingSession.logout(); // transfer the lock token to the super user and try the unlock Node lockednode = superuser.getNode(lockedpath); assertTrue(lockednode.isLocked()); Lock sl = sulm.getLock(lockedpath); assertNotNull(sl.getLockToken()); sulm.addLockToken(sl.getLockToken()); sulm.unlock(lockedpath); locktoken = null; } finally { if (locktoken != null && lockedpath != null) { sulm.addLockToken(locktoken); sulm.unlock(lockedpath); } } }