jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1342630 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/ oak-mk/src/main/java/org/apache/jackrabbit/mk/api/ oak-mk/src/main/java/org/apache/jackrabbit/mk/client/ oak-mk/src/main/java/org/apache/jackrabbi...
Date Fri, 25 May 2012 14:17:51 GMT
Author: stefan
Date: Fri May 25 14:17:51 2012
New Revision: 1342630

URL: http://svn.apache.org/viewvc?rev=1342630&view=rev
Log:
OAK-116: MicroKernel API: clarify semantics of getNodes depth, offset and count parameters

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/LogWrapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/MicroKernelWrapperBase.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/client/Client.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/server/MicroKernelServlet.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/LogWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/LogWrapper.java?rev=1342630&r1=1342629&r2=1342630&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/LogWrapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/LogWrapper.java
Fri May 25 14:17:51 2012
@@ -115,10 +115,10 @@ public class LogWrapper implements Micro
     }
 
     @Override
-    public String getNodes(String path, String revisionId, int depth, long offset, int count,
String filter) {
+    public String getNodes(String path, String revisionId, int depth, long offset, int maxChildNodes,
String filter) {
         try {
-            logMethod("getNodes", path, revisionId, depth, offset, count, filter);
-            String result = mk.getNodes(path, revisionId, depth, offset, count, filter);
+            logMethod("getNodes", path, revisionId, depth, offset, maxChildNodes, filter);
+            String result = mk.getNodes(path, revisionId, depth, offset, maxChildNodes, filter);
             logResult(result);
             return result;
         } catch (Exception e) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/MicroKernelWrapperBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/MicroKernelWrapperBase.java?rev=1342630&r1=1342629&r2=1342630&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/MicroKernelWrapperBase.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/wrapper/MicroKernelWrapperBase.java
Fri May 25 14:17:51 2012
@@ -39,9 +39,9 @@ public abstract class MicroKernelWrapper
     }
 
     @Override
-    public final String getNodes(String path, String revisionId, int depth, long offset,
int count, String filter) {
+    public final String getNodes(String path, String revisionId, int depth, long offset,
int maxChildNodes, String filter) {
         JsopReader reader =
-                getNodesStream(path, revisionId, depth, offset, count, filter);
+                getNodesStream(path, revisionId, depth, offset, maxChildNodes, filter);
         if (reader != null) {
             return reader.toString();
         } else {
@@ -156,8 +156,8 @@ public abstract class MicroKernelWrapper
             }
 
             @Override
-            public String getNodes(String path, String revisionId, int depth, long offset,
int count, String filter) {
-                return wrapped.getNodes(path, revisionId, depth, offset, count, filter);
+            public String getNodes(String path, String revisionId, int depth, long offset,
int maxChildNodes, String filter) {
+                return wrapped.getNodes(path, revisionId, depth, offset, maxChildNodes, filter);
             }
 
             @Override

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java?rev=1342630&r1=1342629&r2=1342630&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
Fri May 25 14:17:51 2012
@@ -209,7 +209,7 @@ public interface MicroKernel {
 
     /**
      * Returns the node tree rooted at the specified parent node with the
-     * specified depth, maximum child node count and offset. The depth of the
+     * specified depth, maximum child node maxChildNodes and offset. The depth of the
      * returned tree is governed by the {@code depth} parameter:
      * <table>
      * <tr>
@@ -263,8 +263,13 @@ public interface MicroKernel {
      * of returned child nodes, then the node has more child nodes than those
      * included in the tree.</li>
      * </ul>
-     * The {@code offset} and {@code count} parameters are only applied to the
-     * direct child nodes of the root of the returned node tree.
+     * The {@code offset} parameter is only applied to the direct child nodes
+     * of the root of the returned node tree. {@code maxChildNodes} however
+     * is applied on all hierarchy levels.
+     * <p/>
+     * An {@code IllegalArgumentException} is thrown if both an {@code offset}
+     * greater than zero and a {@code filter} on node names (see below) have been
+     * specified.
      * <p/>
      * The optional {@code filter} parameter allows to specify glob patterns for names of
      * nodes and/or properties to be included or excluded.
@@ -311,19 +316,20 @@ public interface MicroKernel {
      *     it can be included by specifying a filter such as {@code {properties:["*", ":hash"]}}</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 depth      maximum depth of returned tree
-     * @param offset     start position in the iteration order of child nodes (0 to start
at the
-     *                   beginning)
-     * @param count      maximum number of child nodes to retrieve (-1 for all)
-     * @param filter     optional filter on property and/or node names; if {@code null} or
-     *                   {@code ""} the default filter will be assumed
+     * @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 depth         maximum depth of returned tree
+     * @param offset        start position in the iteration order of child nodes (0 to start
at the
+     *                      beginning)
+     * @param maxChildNodes maximum number of sibling child nodes to retrieve (-1 for all)
+     * @param filter        optional filter on property and/or node names; if {@code null}
or
+     *                      {@code ""} the default filter will be assumed
      * @return node tree in JSON format or {@code null} if the specified node does not exist
      * @throws MicroKernelException if the specified revision does not exist or if another
error occurs
+     * @throws IllegalArgumentException if both an {@code offset > 0} and a {@code filter}
on node names have been specified
      */
     String /* jsonTree */ getNodes(String path, String revisionId, int depth,
-                                   long offset, int count, String filter)
+                                   long offset, int maxChildNodes, String filter)
             throws MicroKernelException;
 
     //------------------------------------------------------------< WRITE ops >

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/client/Client.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/client/Client.java?rev=1342630&r1=1342629&r2=1342630&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/client/Client.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/client/Client.java
Fri May 25 14:17:51 2012
@@ -223,7 +223,7 @@ public class Client implements MicroKern
 
     @Override
     public String getNodes(String path, String revisionId, int depth,
-            long offset, int count, String filter) throws MicroKernelException {
+            long offset, int maxChildNodes, String filter) throws MicroKernelException {
         
         Request request = null;
 
@@ -233,7 +233,7 @@ public class Client implements MicroKern
             request.addParameter("revision_id", revisionId);
             request.addParameter("depth", depth);
             request.addParameter("offset", offset);
-            request.addParameter("count", count);
+            request.addParameter("maxChildNodes", maxChildNodes);
             request.addParameter("filter", filter);
             // OAK-48: MicroKernel.getNodes() should return null for not existing nodes instead
of throwing an exception
             String result = request.getString();

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=1342630&r1=1342629&r2=1342630&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 May 25 14:17:51 2012
@@ -314,7 +314,7 @@ public class MicroKernelImpl implements 
         }
     }
 
-    public String getNodes(String path, String revisionId, int depth, long offset, int count,
String filter) throws MicroKernelException {
+    public String getNodes(String path, String revisionId, int depth, long offset, int maxChildNodes,
String filter) throws MicroKernelException {
         if (rep == null) {
             throw new IllegalStateException("this instance has already been disposed");
         }
@@ -328,9 +328,13 @@ public class MicroKernelImpl implements 
             }
 
             NodeFilter nodeFilter = filter == null || filter.isEmpty() ? null : NodeFilter.parse(filter);
+            if (offset > 0 && nodeFilter != null && nodeFilter.getChildNodeFilter()
!= null) {
+                // both an offset > 0 and a filter on node names have been specified...
+                throw new IllegalArgumentException("offset > 0 with child node filter");
+            }
 
             JsopBuilder buf = new JsopBuilder().object();
-            toJson(buf, nodeState, depth, (int) offset, count, true, nodeFilter);
+            toJson(buf, nodeState, depth, (int) offset, maxChildNodes, true, nodeFilter);
             return buf.endObject().toString();
         } catch (Exception e) {
             throw new MicroKernelException(e);
@@ -537,7 +541,7 @@ public class MicroKernelImpl implements 
     //-------------------------------------------------------< implementation >
 
     void toJson(JsopBuilder builder, NodeState node,
-                int depth, int offset, int count,
+                int depth, int offset, int maxChildNodes,
                 boolean inclVirtualProps, NodeFilter filter) {
         for (PropertyState property : node.getProperties()) {
             if (filter == null || filter.includeProperty(property.getName())) {
@@ -551,6 +555,7 @@ public class MicroKernelImpl implements 
                 // unless it is explicitly excluded in the filter
                 builder.key(":childNodeCount").value(childCount);
             }
+            // TODO check whether :hash has been explicitly included
             if (filter != null && filter.includeProperty(":hash")) {
                 // :hash must be explicitly included in the filter
                 builder.key(":hash").value(rep.getRevisionStore().getId(node).toString());
@@ -563,6 +568,7 @@ public class MicroKernelImpl implements 
                     // optimization for large child node lists:
                     // no need to iterate over the entire child node list if the filter
                     // does not include wildcards
+                    int count = maxChildNodes == -1 ? Integer.MAX_VALUE : maxChildNodes;
                     for (String name : childFilter.getInclusionPatterns()) {
                         NodeState child = node.getChildNode(name);
                         if (child != null) {
@@ -574,9 +580,12 @@ public class MicroKernelImpl implements 
                                 }
                             }
                             if (incl) {
+                                if (count-- <= 0) {
+                                    break;
+                                }
                                 builder.key(name).object();
                                 if (depth > 0) {
-                                    toJson(builder, child, depth - 1, 0, -1, inclVirtualProps,
filter);
+                                    toJson(builder, child, depth - 1, 0, maxChildNodes, inclVirtualProps,
filter);
                                 }
                                 builder.endObject();
                             }
@@ -585,11 +594,22 @@ public class MicroKernelImpl implements 
                     return;
                 }
             }
-            for (ChildNodeEntry entry : node.getChildNodeEntries(offset, count)) {
+
+            int count = maxChildNodes == -1 ? Integer.MAX_VALUE : maxChildNodes;
+            if (maxChildNodes != -1
+                    && filter != null
+                    && filter.getChildNodeFilter() != null) {
+                // specific maxChildNodes limit and child node filter
+                maxChildNodes = -1;
+            }
+            for (ChildNodeEntry entry : node.getChildNodeEntries(offset, maxChildNodes))
{
                 if (filter == null || filter.includeNode(entry.getName())) {
+                    if (count-- <= 0) {
+                        break;
+                    }
                     builder.key(entry.getName()).object();
                     if (depth > 0) {
-                        toJson(builder, entry.getNode(), depth - 1, 0, -1, inclVirtualProps,
filter);
+                        toJson(builder, entry.getNode(), depth - 1, 0, maxChildNodes, inclVirtualProps,
filter);
                     }
                     builder.endObject();
                 }

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java?rev=1342630&r1=1342629&r2=1342630&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java
Fri May 25 14:17:51 2012
@@ -229,11 +229,11 @@ class MicroKernelServlet {
             String revisionId = request.getParameter("revision_id", headRevision);
             int depth = request.getParameter("depth", 1);
             long offset = request.getParameter("offset", 0L);
-            int count = request.getParameter("count", -1);
+            int maxChildNodes = request.getParameter("maxChildNodes", -1);
             String filter = request.getParameter("filter", "");
 
             response.setContentType("application/json");
-            String json = mk.getNodes(path, revisionId, depth, offset, count, filter);
+            String json = mk.getNodes(path, revisionId, depth, offset, maxChildNodes, filter);
             // OAK-48: MicroKernel.getNodes() should return null for not existing nodes instead
of throwing an exception
             if (json == null) {
                 json = "null";



Mime
View raw message