jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1360824 - in /jackrabbit/oak/trunk/oak-jcr: pom.xml src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java src/test/java/org/apache/jackrabbit/oak/jcr/OrderableNodesTest.java
Date Thu, 12 Jul 2012 17:25:03 GMT
Author: jukka
Date: Thu Jul 12 17:25:03 2012
New Revision: 1360824

URL: http://svn.apache.org/viewvc?rev=1360824&view=rev
Log:
OAK-169: Support orderable nodes

Initial implementation of Node.orderBefore()

Modified:
    jackrabbit/oak/trunk/oak-jcr/pom.xml
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/OrderableNodesTest.java

Modified: jackrabbit/oak/trunk/oak-jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/pom.xml?rev=1360824&r1=1360823&r2=1360824&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-jcr/pom.xml Thu Jul 12 17:25:03 2012
@@ -47,7 +47,9 @@ org.apache.jackrabbit.test.api.NodeTest#
 org.apache.jackrabbit.test.api.NodeTest#testMixinTypesProtected<!--OAK-66-->
 org.apache.jackrabbit.test.api.NodeUUIDTest#testSaveReferentialIntegrityException<!--OAK-66-->
 org.apache.jackrabbit.test.api.NodeUUIDTest#testSaveMovedRefNode<!--OAK-66-->
-org.apache.jackrabbit.test.api.NodeOrderableChildNodesTest
+org.apache.jackrabbit.test.api.NodeOrderableChildNodesTest#testOrderBeforeUnsupportedRepositoryOperationException<!--OAK-169-->
+org.apache.jackrabbit.test.api.NodeOrderableChildNodesTest#testOrderBeforePlaceAtEndParentSave<!--OAK-169-->
+org.apache.jackrabbit.test.api.NodeOrderableChildNodesTest#testOrderBeforePlaceAtEndSessionSave<!--OAK-169-->
 org.apache.jackrabbit.test.api.SetValueValueFormatExceptionTest
 org.apache.jackrabbit.test.api.SetValueFormatExceptionTest
 org.apache.jackrabbit.test.api.SetPropertyNodeTest

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java?rev=1360824&r1=1360823&r2=1360824&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
Thu Jul 12 17:25:03 2012
@@ -16,17 +16,22 @@
  */
 package org.apache.jackrabbit.oak.jcr;
 
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.jcr.InvalidItemStateException;
+import javax.jcr.ItemNotFoundException;
 
 import org.apache.jackrabbit.oak.api.CoreValue;
+import org.apache.jackrabbit.oak.api.CoreValueFactory;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.Tree.Status;
@@ -234,6 +239,46 @@ public class NodeDelegate extends ItemDe
         }
     }
 
+    public void orderBefore(String source, String target)
+            throws ItemNotFoundException, InvalidItemStateException {
+        Tree tree = getTree();
+        if (tree.getChild(source) == null) {
+            throw new ItemNotFoundException("Not a child: " + source);
+        } else if (target != null && tree.getChild(target) == null) {
+            throw new ItemNotFoundException("Not a child: " + target);
+        } else {
+            List<CoreValue> order = new ArrayList<CoreValue>();
+            Set<String> added = new HashSet<String>();
+            CoreValueFactory factory =
+                    sessionDelegate.getContentSession().getCoreValueFactory();
+
+            PropertyState property = tree.getProperty("childOrder");
+            if (property != null) {
+                for (CoreValue value : property.getValues()) {
+                    String name = value.getString();
+                    if (!name.equals(source) && !added.contains(property)
+                            && !name.startsWith(":")) {
+                        if (name.equals(target)) {
+                            order.add(factory.createValue(source));
+                            added.add(source);
+                        }
+                        order.add(factory.createValue(name));
+                        added.add(name);
+                    }
+                }
+            }
+
+            if (!added.contains(source)) {
+                order.add(factory.createValue(source));
+            }
+            if (target != null && !added.contains(target)) {
+                order.add(factory.createValue(source));
+            }
+
+            tree.setProperty("childOrder", order);
+        }
+    }
+
     /**
      * Set a property
      * @param name  oak name

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java?rev=1360824&r1=1360823&r2=1360824&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
Thu Jul 12 17:25:03 2012
@@ -232,7 +232,14 @@ public class NodeImpl extends ItemImpl<N
     @Override
     public void orderBefore(String srcChildRelPath, String destChildRelPath) throws RepositoryException
{
         checkStatus();
-        throw new UnsupportedRepositoryOperationException("TODO: ordering not supported");
+        String oakSrcChildRelPath =
+                sessionDelegate.getOakPathOrThrowNotFound(srcChildRelPath);
+        String oakDestChildRelPath = null;
+        if (destChildRelPath != null) {
+            oakDestChildRelPath =
+                    sessionDelegate.getOakPathOrThrowNotFound(destChildRelPath);
+        }
+        dlg.orderBefore(oakSrcChildRelPath, oakDestChildRelPath);
     }
 
     /**

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/OrderableNodesTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/OrderableNodesTest.java?rev=1360824&r1=1360823&r2=1360824&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/OrderableNodesTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/OrderableNodesTest.java
Thu Jul 12 17:25:03 2012
@@ -39,21 +39,21 @@ public class OrderableNodesTest extends 
 
         NodeIterator iterator;
 
-        root.setProperty("childOrder", "abc".split(""));
+        root.orderBefore("a", "b");
         iterator = root.getNodes();
         assertEquals("a", iterator.nextNode().getName());
         assertEquals("b", iterator.nextNode().getName());
         assertEquals("c", iterator.nextNode().getName());
         assertFalse(iterator.hasNext());
 
-        root.setProperty("childOrder", "cab".split(""));
+        root.orderBefore("c", "a");
         iterator = root.getNodes();
         assertEquals("c", iterator.nextNode().getName());
         assertEquals("a", iterator.nextNode().getName());
         assertEquals("b", iterator.nextNode().getName());
         assertFalse(iterator.hasNext());
 
-        root.setProperty("childOrder", "bc".split(""));
+        root.orderBefore("b", "c");
         iterator = root.getNodes();
         assertEquals("b", iterator.nextNode().getName());
         assertEquals("c", iterator.nextNode().getName());



Mime
View raw message