jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpfis...@apache.org
Subject svn commit: r349986 - in /incubator/jackrabbit/trunk/jackrabbit/src: main/java/org/apache/jackrabbit/core/PathMap.java test/java/org/apache/jackrabbit/test/api/lock/LockTest.java
Date Wed, 30 Nov 2005 17:02:17 GMT
Author: dpfister
Date: Wed Nov 30 09:02:01 2005
New Revision: 349986

URL: http://svn.apache.org/viewcvs?rev=349986&view=rev
Log:
#JCR-284 Locking two same-name siblings and unlocking first apparently unlocks second instead.

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

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/PathMap.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/PathMap.java?rev=349986&r1=349985&r2=349986&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/PathMap.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/PathMap.java
Wed Nov 30 09:02:01 2005
@@ -256,36 +256,56 @@
         /**
          * Remove a child. Will shift all children having an index greater than
          * the child removed to the left. If there are no more children left in
-         * this child and no object is associated with this child, the child
-         * itself gets removed.
+         * this element and no object is associated with this element, the
+         * element itself gets removed.
          *
          * @param nameIndex child's path element
          * @return removed child, may be <code>null</code>
          */
         public Element remove(Path.PathElement nameIndex) {
+            return remove(nameIndex, true);
+        }
+
+        /**
+         * Remove a child. If <code>shift</code> is set to <code>true</code>,
+         * will shift all children having an index greater than the child
+         * removed to the left. If there are no more children left in
+         * this element and no object is associated with this element, the
+         * element itself gets removed.
+         *
+         * @param nameIndex child's path element
+         * @param shift whether to shift same name siblings having a greater
+         *              index to the left
+         * @return removed child, may be <code>null</code>
+         */
+        private Element remove(Path.PathElement nameIndex, boolean shift) {
             // convert 1-based index value to 0-base value
             int index = getOneBasedIndex(nameIndex) - 1;
-            if (children != null) {
-                ArrayList list = (ArrayList) children.get(nameIndex.getName());
-                if (list != null && list.size() > index) {
-                    for (int i = index + 1; i < list.size(); i++) {
-                        Element element = (Element) list.get(i);
-                        if (element != null) {
-                            element.index--;
-                        }
-                    }
-                    Element element = (Element) list.remove(index);
-                    if (element != null) {
-                        element.parent = null;
-                        childrenCount--;
-                    }
-                    if (childrenCount == 0 && obj == null) {
-                        remove();
+            if (children == null) {
+                return null;
+            }
+            ArrayList list = (ArrayList) children.get(nameIndex.getName());
+            if (list == null || list.size() <= index) {
+                return null;
+            }
+            Element element = (Element) list.set(index, null);
+            if (shift) {
+                for (int i = index + 1; i < list.size(); i++) {
+                    Element sibling = (Element) list.get(i);
+                    if (sibling != null) {
+                        sibling.index--;
                     }
-                    return element;
                 }
+                list.remove(index);
+            }
+            if (element != null) {
+                element.parent = null;
+                childrenCount--;
+            }
+            if (childrenCount == 0 && obj == null && parent != null) {
+                parent.remove(getPathElement(), shift);
             }
-            return null;
+            return element;
         }
 
         /**
@@ -312,8 +332,8 @@
         public void set(Object obj) {
             this.obj = obj;
 
-            if (obj == null && childrenCount == 0) {
-                remove();
+            if (obj == null && childrenCount == 0 && parent != null) {
+                parent.remove(getPathElement(), false);
             }
         }
 

Modified: incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/lock/LockTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/lock/LockTest.java?rev=349986&r1=349985&r2=349986&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/lock/LockTest.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/lock/LockTest.java
Wed Nov 30 09:02:01 2005
@@ -661,6 +661,36 @@
     }
 
     /**
+     * Tests if unlocking the first of two locked same-name sibling nodes does
+     * not unlock the second (JIRA issue JCR-284).
+     */
+    public void testUnlockSameNameSibling() throws RepositoryException {
+        Session session = testRootNode.getSession();
+
+        // create two same-name sibling nodes
+        Node n1 = testRootNode.addNode(nodeName1);
+        n1.addMixin("mix:lockable");
+        Node n2 = testRootNode.addNode(nodeName1);
+        n2.addMixin("mix:lockable");
+        session.save();
+
+        // lock both nodes
+        n1.lock(true, true);
+        n2.lock(true, true);
+
+        // assert: both nodes are locked
+        assertTrue("First node locked: ", n1.isLocked());
+        assertTrue("Second node locked: ", n2.isLocked());
+
+        // unlock first sibling
+        n1.unlock();
+
+        // assert: first node unlocked, second node still locked
+        assertFalse("First node unlocked: ", n1.isLocked());
+        assertTrue("Second node locked: ", n2.isLocked());
+    }
+
+    /**
      * Return a flag indicating whether the indicated session contains
      * a specific lock token
      */



Mime
View raw message