jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1225524 - in /jackrabbit/sandbox/jackrabbit-microkernel/src: main/java/org/apache/jackrabbit/state/ChangeTree.java test/java/org/apache/jackrabbit/RepositoryTest.java test/java/org/apache/jackrabbit/state/TransientSpaceTest.java
Date Thu, 29 Dec 2011 13:22:10 GMT
Author: mduerig
Date: Thu Dec 29 13:22:10 2011
New Revision: 1225524

URL: http://svn.apache.org/viewvc?rev=1225524&view=rev
Log:
Microkernel based prototype of JCR implementation (WIP)
- correctly implement live nodes (i.e. avoid schizophrenia)

Modified:
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeTree.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/RepositoryTest.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/state/TransientSpaceTest.java

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeTree.java?rev=1225524&r1=1225523&r2=1225524&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeTree.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeTree.java
Thu Dec 29 13:22:10 2011
@@ -19,6 +19,7 @@
 
 package org.apache.jackrabbit.state;
 
+import org.apache.commons.collections.map.ReferenceMap;
 import org.apache.jackrabbit.Path;
 import org.apache.jackrabbit.json.JsonValue;
 import org.apache.jackrabbit.spi.commons.iterator.Iterators;
@@ -33,6 +34,10 @@ import java.util.Iterator;
 import java.util.Map;
 import java.util.Map.Entry;
 
+import static org.apache.commons.collections.map.ReferenceMap.HARD;
+import static org.apache.commons.collections.map.ReferenceMap.WEAK;
+import static org.apache.jackrabbit.utils.Unchecked.cast;
+
 /**
  * A change tree records changes to a tree of nodes and properties and it provides
  * a consolidated view of these changes. Changes are described by operations for
@@ -80,6 +85,9 @@ public class ChangeTree {
     private final NodeDelta root;
     private final Predicate<Path> nodeExists;
 
+    /** Keep Existing instances at least as long as referenced by a client */
+    private final Map<Path, Existing> existing = cast(new ReferenceMap(HARD, WEAK));
+
     /**
      * Create a new change tree rooted at {@code rootPath}.
      * @param rootPath  root path for this change tree
@@ -134,6 +142,7 @@ public class ChangeTree {
      */
     public void clear() {
         root.clear();
+        existing.clear();
     }
 
     /**
@@ -144,6 +153,22 @@ public class ChangeTree {
     }
 
     /**
+     * @return A {@code Existing} instance for the given {@code parent} and {@code name}.
+     * Returns a previously allocated instance if not yet garbage collected.
+     * <em>Note:</em> returning fresh instances while previously allocated ones
are still
+     * referenced in client code results in schizophrenia: same node multiple states.
+     */
+    private Existing existing(NodeDelta parent, String name) {
+        Path path = parent.getPath().concat(name);
+        Existing e = existing.get(path);
+        if (e == null) {
+            e = new Existing(parent, name);
+            existing.put(path, e);
+        }
+        return e;
+    }
+    
+    /**
      * Visitor for traversing a change tree.
      */
     public interface Visitor {
@@ -568,7 +593,7 @@ public class ChangeTree {
             NodeDelta delta = getChild(name);
             if (delta == null) {
                 return nodeExists.evaluate(getPath().concat(name))
-                        ? new Existing(this, name)
+                        ? existing(this, name)
                         : null;
             }
             else {

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/RepositoryTest.java?rev=1225524&r1=1225523&r2=1225524&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/RepositoryTest.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/RepositoryTest.java
Thu Dec 29 13:22:10 2011
@@ -1535,6 +1535,36 @@ public class RepositoryTest {
         disposer.get(10000, TimeUnit.MILLISECONDS);
         assertTrue(failedEvents.isEmpty());
     }
+    
+    @Test
+    public void liveNode() throws RepositoryException {
+        Session session = getSession();
+        
+        Node n1 = session.getNode(TEST_PATH);
+        Node n2 = session.getNode(TEST_PATH);
+
+        Node c1 = n1.addNode("c1");
+        n1.setProperty("p1", "v1");
+        c1.setProperty("pc1", "vc1");
+
+        Node c2 = n2.addNode("c2");
+        n2.setProperty("p2", "v2");
+        c2.setProperty("pc2", "vc2");
+
+        assertTrue(n1.hasNode("c1"));
+        assertTrue(n1.hasNode("c2"));
+        assertTrue(n1.hasProperty("p1"));
+        assertTrue(n1.hasProperty("p2"));
+        assertTrue(c1.hasProperty("pc1"));
+        assertFalse(c1.hasProperty("pc2"));
+
+        assertTrue(n2.hasNode("c1"));
+        assertTrue(n2.hasNode("c2"));
+        assertTrue(n2.hasProperty("p1"));
+        assertTrue(n2.hasProperty("p2"));
+        assertFalse(c2.hasProperty("pc1"));
+        assertTrue(c2.hasProperty("pc2"));
+    }
 
     /**
      * Trans-session isolation differs from Jackrabbit 2. Snapshot isolation can

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/state/TransientSpaceTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/state/TransientSpaceTest.java?rev=1225524&r1=1225523&r2=1225524&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/state/TransientSpaceTest.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/state/TransientSpaceTest.java
Thu Dec 29 13:22:10 2011
@@ -239,12 +239,12 @@ public class TransientSpaceTest {
         NodeDelta root = transientSpace.getNode(ROOT);
         NodeDelta b = root.addNode("a").addNode("b");
         b.addNode("c").addNode("d");
-        NodeDelta y = root.addNode("v").addNode("w");
-        y.addNode("x").addNode("y");
+        NodeDelta w = root.addNode("v").addNode("w");
+        w.addNode("x").addNode("y");
         transientSpace.save();
 
         b = transientSpace.getNode(ROOT.concat("a/b"));
-        b.moveNode("c", y.getPath().concat("c-moved"));
+        b.moveNode("c", w.getPath().concat("c-moved"));
         
         assertNull(transientSpace.getNode(ROOT.concat("a/b/c")));
         assertNotNull(transientSpace.getNode(ROOT.concat("a/b")));
@@ -763,6 +763,21 @@ public class TransientSpaceTest {
         assertThat(mk, CoreMatchers.not(propertyExists(ROOT.concat("source/node/prop2"))));
         assertThat(mk, CoreMatchers.not(propertyExists(ROOT.concat("target/moved/prop2"))));
     }
+    
+    @Test
+    public void liveNode() throws RepositoryException {
+        NodeDelta root = transientSpace.getNode(ROOT);
+        root.addNode("test");
+        transientSpace.save();
+
+        NodeDelta n1 = root.getNode("test");
+        NodeDelta n2 = root.getNode("test");
+        n1.addNode("c1");
+        n2.addNode("c2");
+
+        assertTrue(root.getNode("test").hasNode("c1"));
+        assertTrue(root.getNode("test").hasNode("c2"));
+    }
 
     public static class MicrokernelMatcher {
         private MicrokernelMatcher() { }



Mime
View raw message