jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1296336 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk: api/ client/ server/ simple/ store/ wrapper/
Date Fri, 02 Mar 2012 17:32:49 GMT
Author: stefan
Date: Fri Mar  2 17:32:49 2012
New Revision: 1296336

URL: http://svn.apache.org/viewvc?rev=1296336&view=rev
Log:
readded convenience method mk.getChildNodeCount()

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/client/Client.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/simple/SimpleKernelImpl.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/IdFactory.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/IndexWrapper.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/LogWrapper.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/SecurityWrapper.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/VirtualRepositoryWrapper.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/WrapperBase.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java?rev=1296336&r1=1296335&r2=1296336&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
Fri Mar  2 17:32:49 2012
@@ -93,7 +93,6 @@ public interface MicroKernel {
      *                   if < 0, no limit will be applied.
      * @return a chronological list of revisions in JSON format.
      * @throws MicroKernelException if an error occurs
-     * @todo provide a per revision size hint? (TBD)
      */
     String /* jsonArray */ getRevisions(long since, int maxEntries)
             throws MicroKernelException;
@@ -123,7 +122,7 @@ public interface MicroKernel {
      * </pre>
      *
      * @param fromRevisionId first revision to be returned in journal
-     * @param toRevisionId   last revision to be returned in journal
+     * @param toRevisionId   last revision to be returned in journal, if null the current
head revision is assumed
      * @return a chronological list of revisions in JSON format
      * @throws MicroKernelException if an error occurs
      */
@@ -133,15 +132,17 @@ public interface MicroKernel {
     /**
      * Returns the JSON diff representation of the changes between the specified
      * revisions. The changes will be consolidated if the specified range
-     * covers intermediary revisions.
+     * covers intermediary revisions. The revisions need not be in a specified
+     * chronological order.
+     *
      * <p/>
      * Format:
      * <pre>
      * [ { "id" : "&lt;revisionId&gt;", "ts" : "&lt;revisionTimestamp&gt;",
"msg" : "&lt;commitMessage&gt;", "changes" : "&lt;JSON diff&gt;" }, ... ]
      * </pre>
      *
-     * @param fromRevisionId
-     * @param toRevisionId
+     * @param fromRevisionId a revision
+     * @param toRevisionId   another revision, if null the current head revision is assumed
      * @param path consider only changes that affected the specified subtree at <code>path</code>;
      *        if null the default "/" is assumed
      * @return JSON diff representation of the changes
@@ -157,13 +158,28 @@ public interface MicroKernel {
      * Determines whether the specified node exists.
      *
      * @param path       path denoting node
-     * @param revisionId revision
+     * @param revisionId revision, if null the current head revision is assumed
      * @return <code>true</code> if the specified node exists, otherwise <code>false</code>
      * @throws MicroKernelException if an error occurs
      */
     boolean nodeExists(String path, String revisionId) throws MicroKernelException;
 
     /**
+     * Returns the number of child nodes of the specified node.
+     * <p/>
+     * This is a convenience method since this information could gathered by
+     * calling <code>getNodes(path, revisionId, 0, 0, 0)</code> and evaluating
+     * the <code>:childNodeCount</code> property.
+     *
+     *
+     * @param path       path denoting node
+     * @param revisionId revision, if null the current head revision is assumed
+     * @return the number of child nodes
+     * @throws MicroKernelException if an error occurs
+     */
+    long getChildNodeCount(String path, String revisionId) throws MicroKernelException;
+
+    /**
      * Returns the node tree rooted at the specified parent node with depth 1.
      * Depth 1 means all properties of the node are returned, including the list
      * of child nodes and their properties (including
@@ -198,7 +214,7 @@ public interface MicroKernel {
      * <code>getNodes(path, revisionId, 1, 0, -1)</code>
      *
      * @param path       path denoting root of node tree to be retrieved
-     * @param revisionId revision
+     * @param revisionId revision, if null the current head revision is assumed
      * @return node tree in JSON format
      * @throws MicroKernelException if an error occurs
      */
@@ -227,7 +243,7 @@ public interface MicroKernel {
      * Offset and count only affect the returned child node list of this node.
      *
      * @param path       path denoting root of node tree to be retrieved
-     * @param revisionId revision
+     * @param revisionId revision, if null the current head revision is assumed
      * @param depth      maximum depth of returned tree
      * @param offset     start position in child node list (0 to start at the
      *                   beginning)
@@ -253,7 +269,7 @@ public interface MicroKernel {
      *
      * @param path path denoting target node
      * @param jsonDiff changes to be applied in JSON diff format.
-     * @param revisionId revision the changes are based on
+     * @param revisionId revision the changes are based on, if null the current head revision
is assumed
      * @param message commit message
      * @return id of newly created revision
      * @throws MicroKernelException if an error occurs

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/client/Client.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/client/Client.java?rev=1296336&r1=1296335&r2=1296336&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/client/Client.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/client/Client.java
Fri Mar  2 17:32:49 2012
@@ -216,6 +216,23 @@ public class Client implements MicroKern
         }
     }
 
+    public synchronized long getChildNodeCount(String path, String revisionId)
+            throws MicroKernelException {
+
+        Request request = null;
+
+        try {
+            request = createRequest("getChildNodeCount");
+            request.addParameter("path", path);
+            request.addParameter("revision_id", revisionId);
+            return request.getLong();
+        } catch (IOException e) {
+            throw toMicroKernelException(e);
+        } finally {
+            IOUtils.closeQuietly(request);
+        }
+    }
+
     public synchronized String getNodes(String path, String revisionId)
             throws MicroKernelException {
 

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java?rev=1296336&r1=1296335&r2=1296336&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java
Fri Mar  2 17:32:49 2012
@@ -79,6 +79,7 @@ class MicroKernelServlet {
         COMMANDS.put("getJournal", new GetJournal());
         COMMANDS.put("diff", new Diff());
         COMMANDS.put("nodeExists", new NodeExists());
+        COMMANDS.put("getChildNodeCount", new GetChildNodeCount());
         COMMANDS.put("getNodes", new GetNodes());
         COMMANDS.put("commit", new Commit());
         COMMANDS.put("getLength", new GetLength());
@@ -190,6 +191,21 @@ class MicroKernelServlet {
         }
     }
 
+    static class GetChildNodeCount implements Command {
+
+        public void execute(MicroKernel mk, Request request, Response response)
+                throws IOException, MicroKernelException {
+
+            String headRevision = mk.getHeadRevision();
+
+            String path = request.getParameter("path", "/");
+            String revisionId = request.getParameter("revision_id", headRevision);
+
+            response.setContentType("text/plain");
+            response.write(Long.toString(mk.getChildNodeCount(path, revisionId)));
+        }
+    }
+
     static class GetNodes implements Command {
 
         public void execute(MicroKernel mk, Request request, Response response)

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/simple/SimpleKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/simple/SimpleKernelImpl.java?rev=1296336&r1=1296335&r2=1296336&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/simple/SimpleKernelImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/simple/SimpleKernelImpl.java
Fri Mar  2 17:32:49 2012
@@ -568,6 +568,13 @@ public class SimpleKernelImpl extends Wr
         return getRevisionDataRoot(revisionId).exists(path.substring(1));
     }
 
+    public long getChildNodeCount(String path, String revisionId) {
+        if (!PathUtils.isAbsolute(path)) {
+            throw ExceptionFactory.get("Not an absolute path: " + path);
+        }
+        return getRevisionDataRoot(revisionId).getNode(path).getChildNodeCount();
+    }
+
     public long getLength(String blobId) {
         return ds.getBlobLength(blobId);
     }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/IdFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/IdFactory.java?rev=1296336&r1=1296335&r2=1296336&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/IdFactory.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/IdFactory.java
Fri Mar  2 17:32:49 2012
@@ -111,5 +111,5 @@ public abstract class IdFactory {
                 return longToBytes(clock.time());
             }
         };
-    };
+    }
 }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/IndexWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/IndexWrapper.java?rev=1296336&r1=1296335&r2=1296336&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/IndexWrapper.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/IndexWrapper.java
Fri Mar  2 17:32:49 2012
@@ -72,6 +72,10 @@ public class IndexWrapper extends Wrappe
         return mk.nodeExists(path, revisionId);
     }
 
+    public long getChildNodeCount(String path, String revisionId) {
+        return mk.getChildNodeCount(path, revisionId);
+    }
+
     public int read(String blobId, long pos, byte[] buff, int off, int length) {
         return mk.read(blobId, pos, buff, off, length);
     }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/LogWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/LogWrapper.java?rev=1296336&r1=1296335&r2=1296336&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/LogWrapper.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/LogWrapper.java
Fri Mar  2 17:32:49 2012
@@ -165,6 +165,18 @@ public class LogWrapper implements Micro
         }
     }
 
+    public long getChildNodeCount(String path, String revisionId) {
+        try {
+            logMethod("getChildNodeCount", path, revisionId);
+            long result = mk.getChildNodeCount(path, revisionId);
+            logResult(Long.toString(result));
+            return result;
+        } catch (Exception e) {
+            logException(e);
+            throw convert(e);
+        }
+    }
+
     public int read(String blobId, long pos, byte[] buff, int off, int length) {
         try {
             logMethod("read", blobId, pos, buff, off, length);

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/SecurityWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/SecurityWrapper.java?rev=1296336&r1=1296335&r2=1296336&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/SecurityWrapper.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/SecurityWrapper.java
Fri Mar  2 17:32:49 2012
@@ -330,6 +330,14 @@ public class SecurityWrapper extends Wra
         return mk.nodeExists(path, revisionId);
     }
 
+    public long getChildNodeCount(String path, String revisionId) {
+        rightsRevision = getHeadRevision();
+        if (!checkRights(path, false)) {
+            throw ExceptionFactory.get("Node not found: " + path);
+        }
+        return mk.getChildNodeCount(path, revisionId);
+    }
+
     public int read(String blobId, long pos, byte[] buff, int off, int length) {
         return mk.read(blobId, pos, buff, off, length);
     }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/VirtualRepositoryWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/VirtualRepositoryWrapper.java?rev=1296336&r1=1296335&r2=1296336&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/VirtualRepositoryWrapper.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/VirtualRepositoryWrapper.java
Fri Mar  2 17:32:49 2012
@@ -313,6 +313,16 @@ public class VirtualRepositoryWrapper ex
         return mk.nodeExists(path, rev);
     }
 
+    public long getChildNodeCount(String path, String revisionId) {
+        String mount = getMount(path);
+        if (mount == null) {
+            throw ExceptionFactory.get("Not mapped: " + path);
+        }
+        String rev = getRevision(mount, revisionId);
+        MicroKernel mk = mounts.get(mount);
+        return mk.getChildNodeCount(path, rev);
+    }
+
     public int read(String blobId, long pos, byte[] buff, int off, int length) {
         return mk.read(blobId, pos, buff, off, length);
     }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/WrapperBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/WrapperBase.java?rev=1296336&r1=1296335&r2=1296336&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/WrapperBase.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/wrapper/WrapperBase.java
Fri Mar  2 17:32:49 2012
@@ -120,6 +120,10 @@ public abstract class WrapperBase implem
                 return wrapped.nodeExists(path, revisionId);
             }
 
+            public long getChildNodeCount(String path, String revisionId) {
+                return wrapped.getChildNodeCount(path, revisionId);
+            }
+
             public int read(String blobId, long pos, byte[] buff, int off, int length) {
                 return wrapped.read(blobId, pos, buff, off, length);
             }



Mime
View raw message