jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r156989 - in incubator/jackrabbit/trunk/src: java/org/apache/jackrabbit/core/SessionImpl.java java/org/apache/jackrabbit/core/lock/LockManagerImpl.java java/org/apache/jackrabbit/core/lock/PathMap.java test/org/apache/jackrabbit/test/api/lock/LockTest.java
Date Thu, 10 Mar 2005 21:06:16 GMT
Author: tripod
Date: Thu Mar 10 13:06:12 2005
New Revision: 156989

URL: http://svn.apache.org/viewcvs?view=rev&rev=156989
Log:
- fixing some minor locking issues

Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/lock/PathMap.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/lock/LockTest.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java?view=diff&r1=156988&r2=156989
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/SessionImpl.java Thu Mar
10 13:06:12 2005
@@ -170,7 +170,7 @@
     /**
      * Lock tokens
      */
-    protected final List lockTokens = new ArrayList();
+    protected final Set lockTokens = new HashSet();
 
     /**
      * Protected constructor.
@@ -1131,9 +1131,7 @@
      */
     public void addLockToken(String lt, boolean notify) {
         synchronized (lockTokens) {
-            lockTokens.add(lt);
-
-            if (notify) {
+            if (lockTokens.add(lt) && notify) {
                 try {
                     wsp.getLockManager().lockTokenAdded(this, lt);
                 } catch (RepositoryException e) {
@@ -1168,9 +1166,7 @@
      */
     public void removeLockToken(String lt, boolean notify) {
         synchronized (lockTokens) {
-            lockTokens.remove(lt);
-
-            if (notify) {
+            if (lockTokens.remove(lt) && notify) {
                 try {
                     wsp.getLockManager().lockTokenRemoved(this, lt);
                 } catch (RepositoryException e) {

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java?view=diff&r1=156988&r2=156989
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java
Thu Mar 10 13:06:12 2005
@@ -207,7 +207,7 @@
         LockInfo info = (LockInfo) child.get();
         if (info != null) {
             if (child.hasPath(path)) {
-                throw new LockException("Node already locked: " + path);
+                throw new LockException("Node already locked: " + node.safeGetJCRPath());
             } else if (info.deep) {
                 throw new LockException("Parent node has deep lock.");
             }
@@ -239,12 +239,12 @@
         PathMap.Child child = lockMap.map(path, false);
         LockInfo info = (LockInfo) child.get();
         if (info == null) {
-            throw new LockException("Node not locked: " + path);
+            throw new LockException("Node not locked: " + node.safeGetJCRPath());
         }
         if (child.hasPath(path) || info.deep) {
             return new LockImpl(info, node);
         } else {
-            throw new LockException("Node not locked: " + path);
+            throw new LockException("Node not locked: " + node.safeGetJCRPath());
         }
     }
 
@@ -258,17 +258,17 @@
 
         PathMap.Child child = lockMap.map(path, true);
         if (child == null) {
-            throw new LockException("Node not locked: " + path);
+            throw new LockException("Node not locked: " + node.safeGetJCRPath());
         }
 
         LockInfo info = (LockInfo) child.get();
         if (info == null) {
-            throw new LockException("Node not locked: " + path);
+            throw new LockException("Node not locked: " + node.safeGetJCRPath());
         }
         if (!node.getSession().equals(info.getLockHolder())) {
-            throw new LockException("Node not locked by session: " + path);
+            throw new LockException("Node not locked by session: " + node.safeGetJCRPath());
         }
-        child.remove();
+        child.set(null);
 
         info.setLive(false);
         info.setLockHolder(null);

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/lock/PathMap.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/lock/PathMap.java?view=diff&r1=156988&r2=156989
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/lock/PathMap.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/lock/PathMap.java Thu Mar
10 13:06:12 2005
@@ -272,6 +272,10 @@
          */
         public void set(Object obj) {
             this.obj = obj;
+
+            if (obj == null && childrenCount == 0) {
+                remove();
+            }
         }
 
         /**

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/lock/LockTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/lock/LockTest.java?view=diff&r1=156988&r2=156989
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/lock/LockTest.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/lock/LockTest.java
Thu Mar 10 13:06:12 2005
@@ -96,5 +96,57 @@
         // assertion: isLive must return false
         assertFalse("Lock must be dead", lock.isLive());
     }
+
+    /**
+     * Test parent/child lock
+     */
+    public void testParentChildLock() throws Exception {
+        // create new nodes
+        Node n1 = testRootNode.addNode(nodeName1, testNodeType);
+        n1.addMixin(mixReferenceable);
+        n1.addMixin(mixLockable);
+        Node n2 = n1.addNode(nodeName2, testNodeType);
+        n2.addMixin(mixReferenceable);
+        n2.addMixin(mixLockable);
+        testRootNode.save();
+
+        // lock parent node
+        n1.lock(false, true);
+
+        // lock child node
+        n2.lock(false, true);
+
+        // unlock parent node
+        n1.unlock();
+
+        // child node must still hold lock
+        assertTrue("child node must still hold lock", n2.holdsLock());
+    }
+
+    /**
+     * Test parent/child lock
+     */
+    public void testParentChildDeepLock() throws Exception {
+        // create new nodes
+        Node n1 = testRootNode.addNode(nodeName1, testNodeType);
+        n1.addMixin(mixReferenceable);
+        n1.addMixin(mixLockable);
+        Node n2 = n1.addNode(nodeName2, testNodeType);
+        n2.addMixin(mixReferenceable);
+        n2.addMixin(mixLockable);
+        testRootNode.save();
+
+        // lock child node
+        n2.lock(false, true);
+
+        // lock parent node
+        n1.lock(true, false);
+
+        // unlock child node
+        n2.unlock();
+
+        // parent node must still hold lock
+        assertTrue("parent node must still hold lock", n1.holdsLock());
+    }
 }
 



Mime
View raw message