You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ju...@apache.org on 2014/07/08 19:35:28 UTC

svn commit: r1608857 - in /jackrabbit/oak/branches/1.0: ./ oak-core/src/main/java/org/apache/jackrabbit/oak/core/MutableTree.java

Author: jukka
Date: Tue Jul  8 17:35:28 2014
New Revision: 1608857

URL: http://svn.apache.org/r1608857
Log:
1.0.2: Merged revision 1607152 (OAK-1934)

Modified:
    jackrabbit/oak/branches/1.0/   (props changed)
    jackrabbit/oak/branches/1.0/oak-core/src/main/java/org/apache/jackrabbit/oak/core/MutableTree.java

Propchange: jackrabbit/oak/branches/1.0/
------------------------------------------------------------------------------
  Merged /jackrabbit/oak/trunk:r1607152

Modified: jackrabbit/oak/branches/1.0/oak-core/src/main/java/org/apache/jackrabbit/oak/core/MutableTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.0/oak-core/src/main/java/org/apache/jackrabbit/oak/core/MutableTree.java?rev=1608857&r1=1608856&r2=1608857&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.0/oak-core/src/main/java/org/apache/jackrabbit/oak/core/MutableTree.java (original)
+++ jackrabbit/oak/branches/1.0/oak-core/src/main/java/org/apache/jackrabbit/oak/core/MutableTree.java Tue Jul  8 17:35:28 2014
@@ -21,7 +21,6 @@ package org.apache.jackrabbit.oak.core;
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Preconditions.checkState;
-import static com.google.common.collect.Lists.newArrayList;
 import static com.google.common.collect.Lists.newArrayListWithCapacity;
 import static org.apache.jackrabbit.oak.api.Type.NAMES;
 import static org.apache.jackrabbit.oak.commons.PathUtils.elements;
@@ -227,31 +226,56 @@ class MutableTree extends AbstractTree {
     public boolean orderBefore(final String name) {
         beforeWrite();
         if (parent == null) {
-            // root does not have siblings
-            return false;
-        }
-        if (name != null) {
-            if (name.equals(this.name) || !parent.hasChild(name)) {
-                // same node or no such sibling (not existing or not accessible)
-                return false;
-            }
+            return false; // root does not have siblings
+        } else if (this.name.equals(name)) {
+            return false; // same node
         }
+
         // perform the reorder
-        List<String> names = newArrayList();
-        for (String n : parent.getChildNames()) {
-            if (n.equals(name)) {
+        List<String> names = newArrayListWithCapacity(10000);
+        NodeBuilder builder = parent.nodeBuilder;
+        boolean found = false;
+
+        // first try reordering based on the (potentially out-of-sync)
+        // child order property in the parent node
+        for (String n : builder.getNames(OAK_CHILD_ORDER)) {
+            if (n.equals(name) && parent.hasChild(name)) {
                 names.add(this.name);
+                found = true;
             }
             if (!n.equals(this.name)) {
                 names.add(n);
             }
         }
+
+        // if the target node name was not found in the parent's child order
+        // property, we need to fall back to recreating the child order list
+        if (!found) {
+            names.clear();
+            for (String n : parent.getChildNames()) {
+                if (n.equals(name)) {
+                    names.add(this.name);
+                    found = true;
+                }
+                if (!n.equals(this.name)) {
+                    names.add(n);
+                }
+            }
+        }
+
         if (name == null) {
             names.add(this.name);
+            found = true;
+        }
+
+        if (found) {
+            builder.setProperty(OAK_CHILD_ORDER, names, NAMES);
+            root.updated();
+            return true;
+        } else {
+            // no such sibling (not existing or not accessible)
+            return false;
         }
-        parent.nodeBuilder.setProperty(OAK_CHILD_ORDER, names, NAMES);
-        root.updated();
-        return true;
     }
 
     @Override