jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1339218 - in /jackrabbit/oak/trunk: oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/ oak-mk/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/jackrabbit/mk...
Date Wed, 16 May 2012 15:13:46 GMT
Author: stefan
Date: Wed May 16 15:13:46 2012
New Revision: 1339218

URL: http://svn.apache.org/viewvc?rev=1339218&view=rev
Log:
OAK-75: specify format and semantics of 'filter' parameter in MicroKernel API (WIP)

Modified:
    jackrabbit/oak/trunk/oak-it/mk/src/main/java/org/apache/jackrabbit/mk/test/MicroKernelIT.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/core/MicroKernelImpl.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/DiffBuilder.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=1339218&r1=1339217&r2=1339218&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
Wed May 16 15:13:46 2012
@@ -68,7 +68,7 @@ public class MicroKernelIT extends Abstr
         assertNotNull(head);
 
         try {
-            Thread.sleep(1000);
+            Thread.sleep(100);
         } catch (InterruptedException ignore) {
         }
 
@@ -144,7 +144,36 @@ public class MicroKernelIT extends Abstr
         // there should be exactly 0 entries
         assertEquals(array.size(), 0);
 
-        // TODO test getRevisionHistory/getJournal path filter
+        // test getRevisionHistory/getJournal/diff path filter
+        mk.commit("/test", "+\"foo\":{} +\"bar\":{}", null, "");
+
+        try {
+            Thread.sleep(100);
+        } catch (InterruptedException ignore) {
+        }
+
+        long ts1 = System.currentTimeMillis();
+
+        String revFoo = mk.commit("/test/foo", "^\"p1\":123", null, "");
+        String revBar = mk.commit("/test/bar", "^\"p2\":456", null, "");
+
+        // get history since ts1 (no filter)
+        array = parseJSONArray(mk.getRevisionHistory(ts1, -1, null));
+        // history should contain 2 commits: revFoo and revBar
+        assertEquals(2, array.size());
+        assertPropertyValue(getObjectArrayEntry(array, 0), "id", revFoo);
+        assertPropertyValue(getObjectArrayEntry(array, 1), "id", revBar);
+
+        // get history since ts1 (non-matching filter)
+        array = parseJSONArray(mk.getRevisionHistory(ts1, -1, "/blah"));
+        // history should contain 0 commits since filter doesn't match
+        assertEquals(0, array.size());
+
+        // get history since ts1 (filter on /test/bar)
+        array = parseJSONArray(mk.getRevisionHistory(ts1, -1, "/test/bar"));
+        // history should contain 1 commits: revFoo and revBar
+        assertEquals(1, array.size());
+        assertPropertyValue(getObjectArrayEntry(array, 0), "id", revBar);
     }
 
     @Test

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=1339218&r1=1339217&r2=1339218&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
Wed May 16 15:13:46 2012
@@ -135,7 +135,9 @@ public interface MicroKernel {
      * <p/>
      * The {@code path} parameter allows to filter the revisions by path, i.e.
      * only those revisions that affected the subtree rooted at {@code path}
-     * will be included.
+     * will be included. The filter will also be applied to the JSON diff, i.e.
+     * the diff will include only those changes that affected the subtree rooted
+     * at {@code path}.
      * <p/>
      * A {@code MicroKernelException} is thrown if either {@code fromRevisionId}
      * or {@code toRevisionId}  doesn't exist, denotes a <i>private</i> branch
@@ -160,9 +162,9 @@ public interface MicroKernel {
      * covers intermediary revisions. {@code fromRevisionId} and {@code toRevisionId}
      * don't need not be in a specific chronological order.
      * <p/>
-     * The {@code path} parameter allows to filter the revisions by path, i.e.
-     * only those revisions that affected the subtree rooted at {@code path}
-     * will be included.
+     * The {@code path} parameter allows to filter the changes included in the
+     * JSON diff, i.e. only those changes that affected the subtree rooted at
+     * {@code path} will be included.
      *
      * @param fromRevisionId a revision id, if {@code null} the current head revision is
assumed
      * @param toRevisionId   another revision id, if {@code null} the current head revision
is assumed

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=1339218&r1=1339217&r2=1339218&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
Wed May 16 15:13:46 2012
@@ -113,7 +113,10 @@ public class MicroKernelImpl implements 
         if (rep == null) {
             throw new IllegalStateException("this instance has already been disposed");
         }
-        // todo support path filter
+
+        path = (path == null || "".equals(path)) ? "/" : path;
+        boolean filtered = !"/".equals(path);
+
         maxEntries = maxEntries < 0 ? Integer.MAX_VALUE : maxEntries;
         List<StoredCommit> history = new ArrayList<StoredCommit>();
         try {
@@ -121,7 +124,21 @@ public class MicroKernelImpl implements 
             while (commit != null
                     && history.size() < maxEntries
                     && commit.getCommitTS() >= since) {
-                history.add(commit);
+                if (filtered) {
+                    try {
+                        String diff = new DiffBuilder(
+                                rep.getNodeState(commit.getParentId(), "/"),
+                                rep.getNodeState(commit.getId(), "/"),
+                                "/", rep.getRevisionStore(), path).build();
+                        if (!diff.isEmpty()) {
+                            history.add(commit);
+                        }
+                    } catch (Exception e) {
+                        throw new MicroKernelException(e);
+                    }
+                } else {
+                    history.add(commit);
+                }
 
                 Id commitId = commit.getParentId();
                 if (commitId == null) {

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/DiffBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/DiffBuilder.java?rev=1339218&r1=1339217&r2=1339218&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/DiffBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/DiffBuilder.java
Wed May 16 15:13:46 2012
@@ -51,7 +51,8 @@ public class DiffBuilder {
         final HashMap<NodeState, String> addedNodes = new HashMap<NodeState, String>();
         final HashMap<NodeState, String> removedNodes = new HashMap<NodeState, String>();
 
-        if (!path.startsWith(pathFilter)) {
+        if (!PathUtils.isAncestor(path, pathFilter)
+                && !path.startsWith(pathFilter)) {
             return "";
         }
 
@@ -73,71 +74,67 @@ public class DiffBuilder {
             @Override
             public void propertyAdded(PropertyState after) {
                 String p = PathUtils.concat(getCurrentPath(), after.getName());
-                if (!p.startsWith(pathFilter)) {
-                    return;
+                if (p.startsWith(pathFilter)) {
+                    buff.tag('+').
+                            key(p).
+                            encodedValue(after.getEncodedValue()).
+                            newline();
                 }
-                buff.tag('+').
-                        key(p).
-                        encodedValue(after.getEncodedValue()).
-                        newline();
             }
 
             @Override
             public void propertyChanged(PropertyState before, PropertyState after) {
                 String p = PathUtils.concat(getCurrentPath(), after.getName());
-                if (!p.startsWith(pathFilter)) {
-                    return;
+                if (p.startsWith(pathFilter)) {
+                    buff.tag('^').
+                            key(p).
+                            encodedValue(after.getEncodedValue()).
+                            newline();
                 }
-                buff.tag('^').
-                        key(p).
-                        encodedValue(after.getEncodedValue()).
-                        newline();
             }
 
             @Override
             public void propertyDeleted(PropertyState before) {
                 String p = PathUtils.concat(getCurrentPath(), before.getName());
-                if (!p.startsWith(pathFilter)) {
-                    return;
+                if (p.startsWith(pathFilter)) {
+                    // since property and node deletions can't be distinguished
+                    // using the "- <path>" notation we're representing
+                    // property deletions as "^ <path>:null"
+                    buff.tag('^').
+                            key(p).
+                            value(null).
+                            newline();
                 }
-                // since property and node deletions can't be distinguished
-                // using the "- <path>" notation we're representing
-                // property deletions as "^ <path>:null"
-                buff.tag('^').
-                        key(p).
-                        value(null).
-                        newline();
             }
 
             @Override
             public void childNodeAdded(String name, NodeState after) {
                 String p = PathUtils.concat(getCurrentPath(), name);
-                if (!p.startsWith(pathFilter)) {
-                    return;
+                if (p.startsWith(pathFilter)) {
+                    addedNodes.put(after, p);
+                    buff.tag('+').
+                            key(p).object();
+                    toJson(buff, after);
+                    buff.endObject().newline();
                 }
-                addedNodes.put(after, p);
-                buff.tag('+').
-                        key(p).object();
-                toJson(buff, after);
-                buff.endObject().newline();
             }
 
             @Override
             public void childNodeDeleted(String name, NodeState before) {
                 String p = PathUtils.concat(getCurrentPath(), name);
-                if (!p.startsWith(pathFilter)) {
-                    return;
+                if (p.startsWith(pathFilter)) {
+                    removedNodes.put(before, p);
+                    buff.tag('-');
+                    buff.value(p);
+                    buff.newline();
                 }
-                removedNodes.put(before, p);
-                buff.tag('-');
-                buff.value(p);
-                buff.newline();
             }
 
             @Override
             public void childNodeChanged(String name, NodeState before, NodeState after)
{
                 String p = PathUtils.concat(getCurrentPath(), name);
-                if (p.startsWith(pathFilter)) {
+                if (PathUtils.isAncestor(p, pathFilter)
+                        || p.startsWith(pathFilter)) {
                     super.childNodeChanged(name, before, after);
                 }
             }
@@ -161,40 +158,37 @@ public class DiffBuilder {
                 @Override
                 public void propertyAdded(PropertyState after) {
                     String p = PathUtils.concat(getCurrentPath(), after.getName());
-                    if (!p.startsWith(pathFilter)) {
-                        return;
+                    if (p.startsWith(pathFilter)) {
+                        buff.tag('+').
+                                key(p).
+                                encodedValue(after.getEncodedValue()).
+                                newline();
                     }
-                    buff.tag('+').
-                            key(p).
-                            encodedValue(after.getEncodedValue()).
-                            newline();
                 }
 
                 @Override
                 public void propertyChanged(PropertyState before, PropertyState after) {
                     String p = PathUtils.concat(getCurrentPath(), after.getName());
-                    if (!p.startsWith(pathFilter)) {
-                        return;
+                    if (p.startsWith(pathFilter)) {
+                        buff.tag('^').
+                                key(p).
+                                encodedValue(after.getEncodedValue()).
+                                newline();
                     }
-                    buff.tag('^').
-                            key(p).
-                            encodedValue(after.getEncodedValue()).
-                            newline();
                 }
 
                 @Override
                 public void propertyDeleted(PropertyState before) {
                     String p = PathUtils.concat(getCurrentPath(), before.getName());
-                    if (!p.startsWith(pathFilter)) {
-                        return;
+                    if (p.startsWith(pathFilter)) {
+                        // since property and node deletions can't be distinguished
+                        // using the "- <path>" notation we're representing
+                        // property deletions as "^ <path>:null"
+                        buff.tag('^').
+                                key(p).
+                                value(null).
+                                newline();
                     }
-                    // since property and node deletions can't be distinguished
-                    // using the "- <path>" notation we're representing
-                    // property deletions as "^ <path>:null"
-                    buff.tag('^').
-                            key(p).
-                            value(null).
-                            newline();
                 }
 
                 @Override
@@ -204,13 +198,12 @@ public class DiffBuilder {
                         return;
                     }
                     String p = PathUtils.concat(getCurrentPath(), name);
-                    if (!p.startsWith(pathFilter)) {
-                        return;
+                    if (p.startsWith(pathFilter)) {
+                        buff.tag('+').
+                                key(p).object();
+                        toJson(buff, after);
+                        buff.endObject().newline();
                     }
-                    buff.tag('+').
-                            key(p).object();
-                    toJson(buff, after);
-                    buff.endObject().newline();
                 }
 
                 @Override
@@ -220,18 +213,18 @@ public class DiffBuilder {
                         return;
                     }
                     String p = PathUtils.concat(getCurrentPath(), name);
-                    if (!p.startsWith(pathFilter)) {
-                        return;
+                    if (p.startsWith(pathFilter)) {
+                        buff.tag('-');
+                        buff.value(p);
+                        buff.newline();
                     }
-                    buff.tag('-');
-                    buff.value(p);
-                    buff.newline();
                 }
 
                 @Override
                 public void childNodeChanged(String name, NodeState before, NodeState after)
{
                     String p = PathUtils.concat(getCurrentPath(), name);
-                    if (p.startsWith(pathFilter)) {
+                    if (PathUtils.isAncestor(p, pathFilter)
+                            || p.startsWith(pathFilter)) {
                         super.childNodeChanged(name, before, after);
                     }
                 }



Mime
View raw message