jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1189741 - in /jackrabbit/sandbox/microkernel/src: main/java/org/apache/jackrabbit/mk/ main/java/org/apache/jackrabbit/mk/index/ main/java/org/apache/jackrabbit/mk/json/ main/java/org/apache/jackrabbit/mk/store/ main/java/org/apache/jackrab...
Date Thu, 27 Oct 2011 13:20:16 GMT
Author: stefan
Date: Thu Oct 27 13:20:16 2011
New Revision: 1189741

URL: http://svn.apache.org/viewvc?rev=1189741&view=rev
Log:
support move&set within commit
misc. minor improvements

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/CommitBuilder.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/PathUtils.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/PathTest.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java?rev=1189741&r1=1189740&r2=1189741&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
Thu Oct 27 13:20:16 2011
@@ -211,7 +211,7 @@ public class MicroKernelImpl implements 
             if (node1 == null) {
                 if (node2 != null) {
                     buff.appendTag("+ ").key(path).object();
-                    toJson(buff, node2, Integer.MAX_VALUE, 0, -1);
+                    toJson(buff, node2, Integer.MAX_VALUE, 0, -1, false);
                     return buff.endObject().newline().toString();
                 } else {
                     throw new MicroKernelException("path doesn't exist in the specified revisions:
" + path);
@@ -252,7 +252,7 @@ public class MicroKernelImpl implements 
                     buff.appendTag("+ ").
                             key(PathUtils.concat(nodePath, childName)).object();
                     try {
-                        toJson(buff, rep.getPersistenceManager().getNode(id), Integer.MAX_VALUE,
0, -1);
+                        toJson(buff, rep.getPersistenceManager().getNode(id), Integer.MAX_VALUE,
0, -1, false);
                     } catch (Exception e) {
                         buff.value("ERROR: failed to retrieve node " + id);
                     }
@@ -316,7 +316,7 @@ public class MicroKernelImpl implements 
                         buff.appendTag("+ ").
                                 key(PathUtils.concat(nodePath, childName)).object();
                         try {
-                            toJson(buff, rep.getPersistenceManager().getNode(id), Integer.MAX_VALUE,
0, -1);
+                            toJson(buff, rep.getPersistenceManager().getNode(id), Integer.MAX_VALUE,
0, -1, false);
                         } catch (Exception e) {
                             buff.value("ERROR: failed to retrieve node " + id);
                         }
@@ -368,7 +368,7 @@ public class MicroKernelImpl implements 
     public String getNodes(String path, String revisionId, int depth, long offset, int count)
throws MicroKernelException {
         try {
             JsopBuilder buf = new JsopBuilder().object();
-            toJson(buf, rep.getNode(revisionId, path), depth, offset, count);
+            toJson(buf, rep.getNode(revisionId, path), depth, offset, count, true);
             return buf.endObject().toString();
         } catch (Exception e) {
             throw new MicroKernelException(e);
@@ -485,12 +485,14 @@ public class MicroKernelImpl implements 
 
     //-------------------------------------------------------< implementation >
 
-    void toJson(JsopBuilder builder, Node node, int depth, long offset, int count) throws
Exception {
+    void toJson(JsopBuilder builder, Node node, int depth, long offset, int count, boolean
inclVirtualProps) throws Exception {
         for (Map.Entry<String, String> prop : node.getProperties().entrySet()) {
             builder.key(prop.getKey()).encodedValue(prop.getValue());
         }
         long childCount = node.getChildNodeCount();
-        builder.key(":childNodeCount").value(childCount);
+        if (inclVirtualProps) {
+            builder.key(":childNodeCount").value(childCount);
+        }
         if (childCount > 0 && depth >= 0) {
             for (Map.Entry<String, String> child : node.getChildNodeEntries().entrySet())
{
                 if (offset-- > 0) {
@@ -502,7 +504,7 @@ public class MicroKernelImpl implements 
                     builder.key(childName).object();
                     if (depth > 0) {
                         String childId = child.getValue();
-                        toJson(builder, rep.getPersistenceManager().getNode(childId), depth
- 1, 0, -1);
+                        toJson(builder, rep.getPersistenceManager().getNode(childId), depth
- 1, 0, -1, inclVirtualProps);
                     }
                     builder.endObject();
                 }

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=1189741&r1=1189740&r2=1189741&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
Thu Oct 27 13:20:16 2011
@@ -375,7 +375,7 @@ public class Indexer {
     }
 
     private boolean isInIndex(String path) {
-        return PathUtils.isParent(indexRootNode, path) || indexRootNode.equals(path);
+        return PathUtils.isAncestor(indexRootNode, path) || indexRootNode.equals(path);
     }
 
     private void removeProperty(String path, String lastRevision) {

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java?rev=1189741&r1=1189740&r2=1189741&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java
Thu Oct 27 13:20:16 2011
@@ -57,10 +57,8 @@ public class JsopBuilder {
     }
 
     /**
-     * Append an already formatted comment or whitespace. The comma flag is not
-     * changed.
+     * Append a newline character.
      *
-     * @param string the string to append
      * @return this
      */
     public JsopBuilder newline() {

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/CommitBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/CommitBuilder.java?rev=1189741&r1=1189740&r2=1189741&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/CommitBuilder.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/CommitBuilder.java
Thu Oct 27 13:20:16 2011
@@ -225,19 +225,24 @@ public class CommitBuilder {
     MutableNode getOrCreateStagedNode(String nodePath) throws Exception {
         MutableNode node = staged.get(nodePath);
         if (node == null) {
-            node = new MutableNode(rep.getNode(baseRevId, nodePath));
-            staged.put(nodePath, node);
-            // make sure all direct ancestors are staged as well
-            String p1 = nodePath;
-            while (!PathUtils.denotesRoot(p1)) {
-                String p0 = PathUtils.getParentPath(p1);
-                MutableNode n0 = staged.get(p0);
-                if (n0 != null) {
-                    break;
+            MutableNode parent = staged.get("/");
+            if (parent == null) {
+                parent = new MutableNode(rep.getNode(baseRevId, "/"));
+                staged.put("/", parent);
+            }
+            node = parent;
+            String names[] = PathUtils.split(nodePath);
+            for (int i = names.length - 1; i >= 0; i--) {
+                String path = PathUtils.getAncestorPath(nodePath, i);
+                node = staged.get(path);
+                if (node == null) {
+                    // not yet staged, resolve id using staged parent
+                    // to allow for staged move operations
+                    String id = parent.getChildNodeEntries().get(names[names.length - i -
1]);
+                    node = new MutableNode(rep.getPersistenceManager().getNode(id));
+                    staged.put(path, node);
                 }
-                n0 = new MutableNode(rep.getNode(baseRevId, p0));
-                staged.put(p0, n0);
-                p1 = p0;
+                parent = node;
             }
         }
         return node;

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/PathUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/PathUtils.java?rev=1189741&r1=1189740&r2=1189741&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/PathUtils.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/PathUtils.java
Thu Oct 27 13:20:16 2011
@@ -78,19 +78,40 @@ public class PathUtils {
      * @return the parent path
      */
     public static String getParentPath(String path) {
+        return getAncestorPath(path, 1);
+    }
+
+    /**
+     * Get the nth ancestor of a path. The 1st ancestor is the parent path,
+     * 2nd ancestor the grandparent path, and so on...
+     * <p/>
+     * If nth <= 0, the path argument is returned as is.
+     *
+     * @param path the path
+     * @return the ancestor path
+     */
+    public static String getAncestorPath(String path, int nth) {
         assertValid(path);
 
-        if (path.length() == 0 || denotesRootPath(path)) {
+        if (path.length() == 0 || denotesRootPath(path)
+                || nth <= 0) {
             return path;
         }
+
         int end = path.length() - 1;
-        int pos = path.lastIndexOf('/', end);
-        if (pos > 0) {
-            return path.substring(0, pos);
-        } else if (pos == 0) {
-            return "/";
+        int pos = -1;
+        while (nth-- > 0) {
+            pos = path.lastIndexOf('/', end);
+            if (pos > 0) {
+                end = pos - 1;
+            } else if (pos == 0) {
+                return "/";
+            } else {
+                return "";
+            }
         }
-        return "";
+
+        return path.substring(0, pos);
     }
 
     /**
@@ -232,16 +253,16 @@ public class PathUtils {
     }
 
     /**
-     * Check if a path is the (direct or indirect) parent of another path.
+     * Check if a path is a (direct or indirect) ancestor of another path.
      *
-     * @param parent the parent path
-     * @param path the possible child path
-     * @return true if the path is a child of the parent
+     * @param ancestor the ancestor path
+     * @param path the potential offspring path
+     * @return true if the path is an offspring of the ancestor
      */
-    public static boolean isParent(String parent, String path) {
-        assertValid(parent);
+    public static boolean isAncestor(String ancestor, String path) {
+        assertValid(ancestor);
         assertValid(path);
-        return path.startsWith(parent) && path.length() > parent.length();
+        return path.startsWith(ancestor) && path.length() > ancestor.length();
     }
 
     /**

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/PathTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/PathTest.java?rev=1189741&r1=1189740&r2=1189741&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/PathTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/PathTest.java
Thu Oct 27 13:20:16 2011
@@ -98,6 +98,18 @@ public class PathTest extends TestCase {
         assertEquals("/", PathUtils.getParentPath("/" + parent));
         assertEquals("/" + parent, PathUtils.getParentPath("/" + parent + "/" + child));
 
+        // getAncestorPath
+        assertEquals("/", PathUtils.getAncestorPath("/", 1));
+        assertEquals("/", PathUtils.getAncestorPath("/" + parent, 1));
+        assertEquals("/" + parent, PathUtils.getAncestorPath("/" + parent + "/" + child,
1));
+        assertEquals("/" + parent + "/" + child, PathUtils.getAncestorPath("/" + parent +
"/" + child, 0));
+        assertEquals("/", PathUtils.getAncestorPath("/" + parent + "/" + child, 2));
+
+        assertEquals(PathUtils.getParentPath("/foo"), PathUtils.getAncestorPath("/foo", 1));
+        assertEquals(PathUtils.getParentPath("/foo/bar"), PathUtils.getAncestorPath("/foo/bar",
1));
+        assertEquals(PathUtils.getParentPath("foo/bar"), PathUtils.getAncestorPath("foo/bar",
1));
+        assertEquals(PathUtils.getParentPath("foo"), PathUtils.getAncestorPath("foo", 1));
+
         // isAbsolute
         assertEquals(true, PathUtils.isAbsolute("/"));
         assertEquals(false, PathUtils.isAbsolute(parent));
@@ -106,12 +118,12 @@ public class PathTest extends TestCase {
         assertEquals(true, PathUtils.isAbsolute("/" + parent + "/" + child));
         assertEquals(false, PathUtils.isAbsolute(parent + "/" + child));
 
-        // isParent
-        assertTrue(PathUtils.isParent("/", "/" + parent));
-        assertTrue(PathUtils.isParent(parent, parent + "/" + child));
-        assertFalse(PathUtils.isParent("/", parent + "/" + child));
-        assertTrue(PathUtils.isParent("/" + parent, "/" + parent + "/" + child));
-        assertFalse(PathUtils.isParent(parent, child));
+        // isAncestor
+        assertTrue(PathUtils.isAncestor("/", "/" + parent));
+        assertTrue(PathUtils.isAncestor(parent, parent + "/" + child));
+        assertFalse(PathUtils.isAncestor("/", parent + "/" + child));
+        assertTrue(PathUtils.isAncestor("/" + parent, "/" + parent + "/" + child));
+        assertFalse(PathUtils.isAncestor(parent, child));
 
         // relativize
         assertEquals("", PathUtils.relativize("/", "/"));



Mime
View raw message