jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1438549 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/index/diffindex/BaseDiffCollector.java test/java/org/apache/jackrabbit/oak/plugins/index/diffindex/DiffCollectorTest.java
Date Fri, 25 Jan 2013 15:12:11 GMT
Author: alexparvulescu
Date: Fri Jan 25 15:12:11 2013
New Revision: 1438549

URL: http://svn.apache.org/viewvc?rev=1438549&view=rev
Log:
OAK-343 Session.getNodeByUUID requires save call - deep change fix+test

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/diffindex/BaseDiffCollector.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/diffindex/DiffCollectorTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/diffindex/BaseDiffCollector.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/diffindex/BaseDiffCollector.java?rev=1438549&r1=1438548&r2=1438549&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/diffindex/BaseDiffCollector.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/diffindex/BaseDiffCollector.java
Fri Jan 25 15:12:11 2013
@@ -22,7 +22,6 @@ import java.util.HashSet;
 import java.util.Set;
 
 import org.apache.jackrabbit.oak.spi.query.Filter;
-import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
 import org.apache.jackrabbit.oak.spi.state.EmptyNodeStateDiff;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStateUtils;
@@ -32,7 +31,7 @@ public abstract class BaseDiffCollector 
     private final NodeState before;
     private final NodeState after;
 
-    private final Set<String> results;
+    private Set<String> results;
     protected boolean init = false;
 
     /**
@@ -69,59 +68,94 @@ public abstract class BaseDiffCollector 
     }
 
     public void collect(final Filter filter) {
-        after.compareAgainstBaseState(before, new EmptyNodeStateDiff() {
+        DiffCollectorNodeStateDiff diff = new DiffCollectorNodeStateDiff(this,
+                filter);
+        after.compareAgainstBaseState(before, diff);
+        this.results = new HashSet<String>(diff.getResults());
+        this.init = true;
+    }
 
-            @Override
-            public void childNodeAdded(String name, NodeState after) {
-                if (NodeStateUtils.isHidden(name) || init) {
-                    return;
-                }
-                testNodeState(after, name);
+    abstract boolean match(NodeState state, Filter filter);
+
+    protected boolean isUnique() {
+        return false;
+    }
+
+    private static class DiffCollectorNodeStateDiff extends EmptyNodeStateDiff {
+
+        private final BaseDiffCollector collector;
+        private final Filter filter;
+        private final Set<String> results;
+
+        private final DiffCollectorNodeStateDiff parent;
+        private final String path;
+        private boolean done;
+
+        DiffCollectorNodeStateDiff(BaseDiffCollector collector, Filter filter) {
+            this(collector, filter, null, "", new HashSet<String>());
+        }
+
+        private DiffCollectorNodeStateDiff(BaseDiffCollector collector,
+                Filter filter, DiffCollectorNodeStateDiff parent, String path,
+                Set<String> results) {
+            this.collector = collector;
+            this.filter = filter;
+            this.parent = parent;
+            this.path = path;
+            this.results = results;
+        }
+
+        private boolean isDone() {
+            if (parent != null) {
+                return parent.isDone();
             }
+            return done;
+        }
 
-            @Override
-            public void childNodeChanged(String name, NodeState before,
-                    NodeState after) {
-                if (init) {
-                    return;
-                }
-                for (ChildNodeEntry entry : after.getChildNodeEntries()) {
-                    if (init) {
-                        break;
-                    }
-                    if (!before.hasChildNode(entry.getName())) {
-                        testNodeState(entry.getNodeState(),
-                                concat(name, entry.getName()));
-                    }
-                }
+        private void setDone() {
+            if (parent != null) {
+                parent.setDone();
+                return;
             }
+            done = true;
+        }
+
+        @Override
+        public void childNodeAdded(String name, NodeState after) {
+            if (NodeStateUtils.isHidden(name) || isDone()) {
+                return;
+            }
+            testNodeState(after, name);
+        }
 
-            private void testNodeState(NodeState nodeState, String currentPath) {
-                if (init) {
+        @Override
+        public void childNodeChanged(String name, NodeState before,
+                NodeState after) {
+            if (isDone()) {
+                return;
+            }
+            after.compareAgainstBaseState(before,
+                    new DiffCollectorNodeStateDiff(collector, filter, this,
+                            concat(path, name), results));
+        }
+
+        private void testNodeState(NodeState nodeState, String currentPath) {
+            if (isDone()) {
+                return;
+            }
+            boolean match = collector.match(nodeState, filter);
+            if (match) {
+                results.add(concat(path, currentPath));
+                if (collector.isUnique()) {
+                    setDone();
                     return;
                 }
-                boolean match = match(nodeState, filter);
-                if (match) {
-                    results.add(currentPath);
-                    if (isUnique()) {
-                        init = true;
-                        return;
-                    }
-                }
-                for (ChildNodeEntry entry : nodeState.getChildNodeEntries()) {
-                    if (!NodeStateUtils.isHidden(entry.getName())) {
-                        testNodeState(entry.getNodeState(),
-                                concat(currentPath, entry.getName()));
-                    }
-                }
             }
-        });
-    }
-
-    protected abstract boolean match(NodeState state, Filter filter);
+        }
 
-    protected boolean isUnique() {
-        return false;
+        Set<String> getResults() {
+            return results;
+        }
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/diffindex/DiffCollectorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/diffindex/DiffCollectorTest.java?rev=1438549&r1=1438548&r2=1438549&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/diffindex/DiffCollectorTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/diffindex/DiffCollectorTest.java
Fri Jan 25 15:12:11 2013
@@ -66,4 +66,46 @@ public class DiffCollectorTest {
         assertFalse(iterator.hasNext());
     }
 
+    @Test
+    public void testDeepChange() throws Exception {
+        NodeState root = MemoryNodeState.EMPTY_NODE;
+        NodeBuilder builder = root.builder();
+
+        NodeBuilder b1 = builder.child("rep:security").child(
+                "rep:authorizables");
+        b1.child("rep:groups").child("t").child("te")
+                .child("testGroup_1c22a39f");
+        NodeBuilder b2 = b1.child("rep:users");
+        b2.child("t").child("te").child("testUser_008e00d9");
+        NodeBuilder b3 = b2.child("a");
+        b3.child("an").child("anonymous");
+        b3.child("ad").child("admin");
+
+        NodeState before = builder.getNodeState();
+        builder = before.builder();
+
+        NodeBuilder a1 = builder.child("rep:security")
+                .child("rep:authorizables").child("rep:groups").child("t")
+                .child("te");
+        a1.child("testGroup_1c22a39f").setProperty("jcr:uuid",
+                "c6195630-e956-3d4b-8912-479c303bf15a");
+        a1.child("testPrincipal_4e6b704e").setProperty("jcr:uuid",
+                "ee59b554-76b7-3e27-9fc6-15bda1388894");
+        NodeState after = builder.getNodeState();
+
+        UUIDDiffCollector collector = new UUIDDiffCollector(before, after);
+
+        FilterImpl f = new FilterImpl(null, null);
+        f.restrictProperty("jcr:uuid", Operator.EQUAL, PropertyValues
+                .newString("ee59b554-76b7-3e27-9fc6-15bda1388894"));
+
+        Set<String> result = collector.getResults(f);
+        Iterator<String> iterator = result.iterator();
+        assertTrue(iterator.hasNext());
+        assertEquals(
+                "rep:security/rep:authorizables/rep:groups/t/te/testPrincipal_4e6b704e",
+                iterator.next());
+        assertFalse(iterator.hasNext());
+    }
+
 }



Mime
View raw message