jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1173709 - in /jackrabbit/sandbox/microkernel/src: main/java/org/apache/jackrabbit/mk/index/Indexer.java test/java/org/apache/jackrabbit/mk/index/IndexTest.java
Date Wed, 21 Sep 2011 15:26:40 GMT
Author: thomasm
Date: Wed Sep 21 15:26:39 2011
New Revision: 1173709

URL: http://svn.apache.org/viewvc?rev=1173709&view=rev
Log:
Index mechanism: support move operations (plus don't open the repository within the test method
itself)

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/IndexTest.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java?rev=1173709&r1=1173708&r2=1173709&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java
Wed Sep 21 15:26:39 2011
@@ -21,6 +21,7 @@ import org.apache.jackrabbit.mk.json.Jso
 import org.apache.jackrabbit.mk.json.JsopTokenizer;
 import org.apache.jackrabbit.mk.mem.NodeImpl;
 import org.apache.jackrabbit.mk.mem.NodeMap;
+import org.apache.jackrabbit.mk.util.ExceptionFactory;
 import org.apache.jackrabbit.mk.util.PathUtils;
 
 import java.util.ArrayList;
@@ -229,10 +230,9 @@ public class Indexer {
             if (r == JsopTokenizer.END) {
                 break;
             }
-            String path;
+            String path = t.readString();
             switch (r) {
             case '+': {
-                path = t.readString();
                 t.read(':');
                 NodeMap map = new NodeMap();
                 if (t.matches('{')) {
@@ -250,11 +250,9 @@ public class Indexer {
                 break;
             }
             case '-':
-                path = t.readString();
-                removeNode(path, lastRevision);
+                moveNode(path, null, lastRevision);
                 break;
             case '^': {
-                path = t.readString();
                 removeProperty(path, lastRevision);
                 t.read(':');
                 if (t.matches(JsopTokenizer.NULL)) {
@@ -266,65 +264,29 @@ public class Indexer {
                 break;
             }
             case '>':
-                int todoNotImplementedYet;
-                path = t.readString();
                 t.read(':');
-                String position, target;
-                boolean rename;
-                String to;
+                String name = PathUtils.getName(path);
+                String target, position;
                 if (t.matches('{')) {
-                    rename = false;
                     position = t.readString();
                     t.read(':');
                     target = t.readString();
                     t.read('}');
                 } else {
-                    rename = true;
                     position = null;
                     target = t.readString();
                 }
-                boolean before = false;
-                if ("last".equals(position)) {
-                    // target = PathUtils.concat(target, name);
-                    position = null;
-                } else if ("first".equals(position)) {
-                    // target = PathUtils.concat(target, name);
-                    position = null;
-                    before = true;
-                } else if ("before".equals(position)) {
-                    position = PathUtils.getName(target);
-                    target = PathUtils.getParentPath(target);
-                    // target = PathUtils.concat(target, name);
-                    before = true;
-                } else if ("after".equals(position)) {
-                    position = PathUtils.getName(target);
+                if ("last".equals(position) || "first".equals(position)) {
+                    target = PathUtils.concat(target, name);
+                } else if ("before".equals(position) || "after".equals(position)) {
                     target = PathUtils.getParentPath(target);
-                    // target = PathUtils.concat(target, name);
+                    target = PathUtils.concat(target, name);
                 } else if (position == null) {
                     // move
                 } else {
-                    throw new AssertionError("position: " + position);
-                }
-                if (PathUtils.isAbsolute(target)) {
-                    to = PathUtils.relativize("/", target);
-                } else {
-                    // to = PathUtils.concat(fromRoot, target);
+                    throw ExceptionFactory.get("position: " + position);
                 }
-//                boolean inPlaceRename = false;
-//                if (rename) {
-//                    if (PathUtils.getParentPath(from).equals(PathUtils.getParentPath(to)))
{
-//                        inPlaceRename = true;
-//                        position = PathUtils.getName(from);
-//                    }
-//                }
-//                NodeImpl node = headRoot.getNode(from);
-//                if (!inPlaceRename) {
-//                    headRoot = headRoot.cloneAndRemoveChildNode(from, headRevId);
-//                }
-//                headRoot = headRoot.cloneAndAddChildNode(to, before, position, node, headRevId);
-//                if (inPlaceRename) {
-//                    headRoot = headRoot.cloneAndRemoveChildNode(from, headRevId);
-//                }
+                moveNode(path, target, lastRevision);
                 break;
             default:
                 throw new AssertionError("token: " + (char) t.getTokenType());
@@ -389,21 +351,27 @@ public class Indexer {
         }
     }
 
-    private void removeNode(String path, String lastRevision) {
-        if (isInIndex(path)) {
+    private void moveNode(String sourcePath, String targetPath, String lastRevision) {
+        if (isInIndex(sourcePath)) {
             // don't index the index
             return;
         }
-        if (!mk.nodeExists(path, lastRevision)) {
+        if (!mk.nodeExists(sourcePath, lastRevision)) {
             return;
         }
-        String node = mk.getNodes(path, lastRevision, Integer.MAX_VALUE, 0, Integer.MAX_VALUE);
+        String node = mk.getNodes(sourcePath, lastRevision, Integer.MAX_VALUE, 0, Integer.MAX_VALUE);
         JsopTokenizer t = new JsopTokenizer(node);
         NodeMap map = new NodeMap();
         t.read('{');
-        NodeImpl n = NodeImpl.parse(map, t, 0, path);
-        n.setPath(path);
+        NodeImpl n = NodeImpl.parse(map, t, 0, sourcePath);
         addOrRemoveRecursive(n, true, false);
+        if (targetPath != null) {
+            t = new JsopTokenizer(node);
+            map = new NodeMap();
+            t.read('{');
+            n = NodeImpl.parse(map, t, 0, targetPath);
+            addOrRemoveRecursive(n, false, true);
+        }
     }
 
     private void buildAndAddIndex(Index index) {

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/IndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/IndexTest.java?rev=1173709&r1=1173708&r2=1173709&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/IndexTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/index/IndexTest.java
Wed Sep 21 15:26:39 2011
@@ -20,7 +20,6 @@ import java.util.Iterator;
 import java.util.Random;
 import java.util.TreeMap;
 import junit.framework.Assert;
-import org.apache.jackrabbit.mk.MicroKernelFactory;
 import org.apache.jackrabbit.mk.MultiMkTestBase;
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.json.JsopTest;
@@ -72,13 +71,28 @@ public class IndexTest extends MultiMkTe
     public void nestedAddNode() {
         Indexer indexer = new Indexer(mk);
         PropertyIndex index = indexer.createPropertyIndex("id", true);
+
         mk.commit("/", "+ \"test\": { \"test2\": { \"id\": 2 }, \"id\": 1 }", mk.getHeadRevision(),
"");
         Assert.assertEquals("/test", index.getPath("1", mk.getHeadRevision()));
         Assert.assertEquals("/test/test2", index.getPath("2", mk.getHeadRevision()));
     }
 
     @Test
-    public void testAscending() {
+    public void move() {
+        Indexer indexer = new Indexer(mk);
+        PropertyIndex index = indexer.createPropertyIndex("id", true);
+
+        mk.commit("/", "+ \"test\": { \"test2\": { \"id\": 2 }, \"id\": 1 }", mk.getHeadRevision(),
"");
+        Assert.assertEquals("/test", index.getPath("1", mk.getHeadRevision()));
+        Assert.assertEquals("/test/test2", index.getPath("2", mk.getHeadRevision()));
+
+        mk.commit("/", "> \"test\": \"moved\"", mk.getHeadRevision(), "");
+        Assert.assertEquals("/moved", index.getPath("1", mk.getHeadRevision()));
+        Assert.assertEquals("/moved/test2", index.getPath("2", mk.getHeadRevision()));
+    }
+
+    @Test
+    public void ascending() {
         Indexer indexer = new Indexer(mk);
         BTree tree = new BTree(indexer, "test", true);
         tree.setMinSize(2);
@@ -161,8 +175,7 @@ public class IndexTest extends MultiMkTe
     }
 
     @Test
-    public void testRandom() {
-        MicroKernel mk = MicroKernelFactory.getInstance(url);
+    public void random() {
         Indexer indexer = new Indexer(mk);
         BTree tree = new BTree(indexer, "test", true);
         tree.setMinSize(2);



Mime
View raw message