jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1412898 - in /jackrabbit/oak/trunk: oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/ oak-mk-api/src/main/java/org/apache/jackrabbit/mk/api/ oak-mk/src/main/java/org/apache/jackrabbit/mk/core/ oak-mk/src/main/java/org/apache/jackrabbi...
Date Fri, 23 Nov 2012 14:18:27 GMT
Author: stefan
Date: Fri Nov 23 14:18:25 2012
New Revision: 1412898

URL: http://svn.apache.org/viewvc?rev=1412898&view=rev
Log:
OAK-468: Identifier- or hash-based access in the MicroKernel

Modified:
    jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java
    jackrabbit/oak/trunk/oak-mk-api/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/Id.java

Modified: jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java?rev=1412898&r1=1412897&r2=1412898&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java
(original)
+++ jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.java
Fri Nov 23 14:18:25 2012
@@ -456,6 +456,10 @@ public class MicroKernelIT extends Abstr
         assertPropertyExists(obj, ":hash", String.class);
         String hash0 = (String) resolveValue(obj, ":hash");
 
+        // get node by identifier (:hash)
+        JSONObject obj1 = parseJSONObject(mk.getNodes(hash0, null, 1, 0, -1, "{\"properties\":[\"*\",\":hash\"]}"));
+        assertEquals(obj, obj1);
+
         // modify a property and verify that the hash of the root node changed
         mk.commit("/test", "^\"booleanProp\":false", null, null);
         obj = parseJSONObject(mk.getNodes("/", null, 1, 0, -1, "{\"properties\":[\"*\",\":hash\"]}"));
@@ -480,6 +484,41 @@ public class MicroKernelIT extends Abstr
     }
 
     @Test
+    public void getNodesId() {
+        // :id must be explicitly specified in the filter
+        JSONObject obj = parseJSONObject(mk.getNodes("/", null, 1, 0, -1, null));
+        assertPropertyNotExists(obj, ":id");
+        obj = parseJSONObject(mk.getNodes("/", null, 1, 0, -1, "{\"properties\":[\"*\"]}"));
+        assertPropertyNotExists(obj, ":id");
+
+        // verify initial content with :id property
+        obj = parseJSONObject(mk.getNodes("/", null, 1, 0, -1, "{\"properties\":[\"*\",\":id\"]}"));
+        assertPropertyValue(obj, "test/booleanProp", true);
+
+        if (obj.get(":id") == null) {
+            // :id is optional, an implementation might not support it
+            return;
+        }
+
+        assertPropertyExists(obj, ":id", String.class);
+        String id0 = (String) resolveValue(obj, ":id");
+
+        // get node by identifier (:hash)
+        JSONObject obj1 = parseJSONObject(mk.getNodes(id0, null, 1, 0, -1, "{\"properties\":[\"*\",\":id\"]}"));
+        assertEquals(obj, obj1);
+
+        // modify a property and verify that the id of the root node changed
+        mk.commit("/test", "^\"booleanProp\":false", null, null);
+        obj = parseJSONObject(mk.getNodes("/", null, 1, 0, -1, "{\"properties\":[\"*\",\":id\"]}"));
+        assertPropertyValue(obj, "test/booleanProp", false);
+
+        assertPropertyExists(obj, ":id", String.class);
+        String id1 = (String) resolveValue(obj, ":id");
+
+        assertFalse(id0.equals(id1));
+    }
+
+    @Test
     public void getNodesChildNodeCount() {
         // :childNodeCount is included per default
         JSONObject obj = parseJSONObject(mk.getNodes("/", null, 1, 0, -1, null));

Modified: jackrabbit/oak/trunk/oak-mk-api/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk-api/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java?rev=1412898&r1=1412897&r2=1412898&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk-api/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
(original)
+++ jackrabbit/oak/trunk/oak-mk-api/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
Fri Nov 23 14:18:25 2012
@@ -368,15 +368,33 @@ public interface MicroKernel {
      *     if on the other hand the {@code :hash} values are identical the respective
      *     subtrees are identical with regard to structure and properties.
      *     {@code :hash} is <i>not</i> included by the implicit default filter.
-     *     it can be included by specifying a filter such as {@code {properties:["*", ":hash"]}}
+     *     it can be included by specifying a filter such as {@code {properties:["*", ":hash"]}}.
      *     <p>Returning the {@code :hash} property is optional. Some implementations
      *     might only return it on specific nodes or might not support it at all.
      *     If however a {@code :hash} property is returned it has to obey the contract
-     *     described above.</p></li>
+     *     described above.</p>
+     *     <p>Implementations that keep track of the child hash along with
+     *     the child node name can return the {@code :hash} value also as
+     *     a property of the child node objects, even if they'd otherwise
+     *     be empty, for example due to a depth limit. If such child hashes
+     *     are returned, the client can use them as an alternative to child
+     *     paths when accessing those nodes.</li>
+     *     <li>{@code :id} provides an implementation-specific identifier
+     *     of a node. Identifiers are like content hashes as described above,
+     *     except for the fact that two different identifiers may refer to
+     *     identical subtrees. Also {@code :id} values may be returned for
+     *     child nodes, in which case the client can use them for accessing
+     *     those nodes.
+     *     </li>
      * </ul>
      *
-     * @param path          path denoting root of node tree to be retrieved
-     * @param revisionId    revision id, if {@code null} the current head revision is assumed
+     * @param path          path denoting root of node tree to be retrieved,
+     *                      or alternatively a previously returned
+     *                      {@code :hash} or {@code :id} value; in the latter case
+     *                      the {@code revisionId} parameter is ignored.
+     * @param revisionId    revision id, if {@code null} the current head revision is assumed;
+     *                      the {@code revisionId} parameter is ignored if {@code path}
+     *                      is an identifier (i.e. a {@code :hash} or {@code :id} value).
      * @param depth         maximum depth of returned tree
      * @param offset        start position in the iteration order of child nodes (0 to start
at the
      *                      beginning)

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java?rev=1412898&r1=1412897&r2=1412898&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/MicroKernelImpl.java
Fri Nov 23 14:18:25 2012
@@ -30,6 +30,7 @@ import org.apache.jackrabbit.mk.model.tr
 import org.apache.jackrabbit.mk.model.tree.DiffBuilder;
 import org.apache.jackrabbit.mk.model.tree.NodeState;
 import org.apache.jackrabbit.mk.model.tree.PropertyState;
+import org.apache.jackrabbit.mk.store.RevisionStore;
 import org.apache.jackrabbit.mk.util.CommitGate;
 import org.apache.jackrabbit.mk.util.NameFilter;
 import org.apache.jackrabbit.mk.util.NodeFilter;
@@ -347,6 +348,11 @@ public class MicroKernelImpl implements 
             throw new IllegalStateException("this instance has already been disposed");
         }
 
+        Id id = null;
+        if (!path.startsWith("/")) {
+            // OAK-468: Identifier- or hash-based access in the MicroKernel
+            id = Id.fromString(path);
+        }
         Id revId = revisionId == null ? getHeadRevisionId() : Id.fromString(revisionId);
 
         NodeFilter nodeFilter = filter == null || filter.isEmpty() ? null : NodeFilter.parse(filter);
@@ -356,7 +362,13 @@ public class MicroKernelImpl implements 
         }
 
         try {
-            NodeState nodeState = rep.getNodeState(revId, path);
+            NodeState nodeState;
+            if (id != null) {
+                RevisionStore rs = rep.getRevisionStore();
+                nodeState = rs.getNodeState(rs.getNode(id));
+            } else {
+                nodeState = rep.getNodeState(revId, path);
+            }
             if (nodeState == null) {
                 return null;
             }
@@ -571,13 +583,19 @@ public class MicroKernelImpl implements 
                 // unless it is explicitly excluded in the filter
                 builder.key(":childNodeCount").value(childCount);
             }
-            // check whether :hash has been explicitly included
             if (filter != null) {
                 NameFilter nf = filter.getPropertyFilter();
-                if (nf != null
-                        && nf.getInclusionPatterns().contains(":hash")
-                        && !nf.getExclusionPatterns().contains(":hash")) {
-                    builder.key(":hash").value(rep.getRevisionStore().getId(node).toString());
+                if (nf != null) {
+                    // check whether :id has been explicitly included
+                    if (nf.getInclusionPatterns().contains(":hash")
+                            && !nf.getExclusionPatterns().contains(":hash")) {
+                        builder.key(":hash").value(rep.getRevisionStore().getId(node).toString());
+                    }
+                    // check whether :id has been explicitly included
+                    if (nf.getInclusionPatterns().contains(":id")
+                            && !nf.getExclusionPatterns().contains(":id")) {
+                        builder.key(":id").value(rep.getRevisionStore().getId(node).toString());
+                    }
                 }
             }
         }

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/Id.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/Id.java?rev=1412898&r1=1412897&r2=1412898&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/Id.java (original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/Id.java Fri Nov
23 14:18:25 2012
@@ -63,6 +63,7 @@ public class Id implements Comparable<Id
      *
      * @param s a string representation of an {@code Id}
      * @return an {@code Id} instance
+     * @throws IllegalArgumentException if {@code s} is not a valid string representation
      */
     public static Id fromString(String s) {
         return new Id(StringUtils.convertHexToBytes(s));



Mime
View raw message