jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1224983 - in /jackrabbit/sandbox/jackrabbit-microkernel/src: main/java/org/apache/jackrabbit/ main/java/org/apache/jackrabbit/state/ test/java/org/apache/jackrabbit/state/
Date Tue, 27 Dec 2011 19:23:56 GMT
Author: mduerig
Date: Tue Dec 27 19:23:56 2011
New Revision: 1224983

URL: http://svn.apache.org/viewvc?rev=1224983&view=rev
Log:
Microkernel based prototype of JCR implementation (WIP)
- refactor

Modified:
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/ItemImpl.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/NodeImpl.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/PropertyImpl.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeTree.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/TransientSpace.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/ItemImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/ItemImpl.java?rev=1224983&r1=1224982&r2=1224983&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/ItemImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/ItemImpl.java
Tue Dec 27 19:23:56 2011
@@ -25,6 +25,7 @@ import org.apache.jackrabbit.state.Chang
 import javax.jcr.Item;
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.UnsupportedRepositoryOperationException;
@@ -88,7 +89,7 @@ abstract class ItemImpl implements Item 
         try {
             return getNodeDelta().isTransient();
         }
-        catch (ItemNotFoundException e) {
+        catch (PathNotFoundException e) {
             // should never happen
             throw new IllegalStateException(e);
         }
@@ -99,7 +100,7 @@ abstract class ItemImpl implements Item 
         try {
             return getNodeDelta().hasChanges();
         }
-        catch (ItemNotFoundException e) {
+        catch (PathNotFoundException e) {
             // should never happen
             throw new IllegalStateException(e);
         }
@@ -149,7 +150,7 @@ abstract class ItemImpl implements Item 
         return !sessionContext.getRevision().equals(revision);
     }
 
-    protected final NodeDelta getNodeDelta() throws ItemNotFoundException {
+    protected final NodeDelta getNodeDelta() throws PathNotFoundException {
         return sessionContext.getTransientSpace().getNode(path);
     }
 

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/NodeImpl.java?rev=1224983&r1=1224982&r2=1224983&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/NodeImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/NodeImpl.java
Tue Dec 27 19:23:56 2011
@@ -40,7 +40,6 @@ import javax.jcr.Binary;
 import javax.jcr.InvalidItemStateException;
 import javax.jcr.Item;
 import javax.jcr.ItemExistsException;
-import javax.jcr.ItemNotFoundException;
 import javax.jcr.ItemVisitor;
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
@@ -67,15 +66,11 @@ public class NodeImpl extends ItemImpl i
     private JsonObject node;
 
     static boolean exist(Context sessionContext, Path path) {
-        return getNode(sessionContext, path) != null;
+        return sessionContext.getTransientSpace().nodeExists(path);
     }
 
     static Node create(Context sessionContext, Path path) throws RepositoryException {
         JsonObject node = getNode(sessionContext, path);
-        if (node == null) {
-            throw new PathNotFoundException(path.toString());
-        }
-
         return new NodeImpl(sessionContext, path, node);
     }
 
@@ -619,30 +614,19 @@ public class NodeImpl extends ItemImpl i
 
     private JsonObject getNode() throws InvalidItemStateException {
         if (isStale() || node.isEmpty() ) {
-            JsonObject n = getNode(sessionContext, path);
-            if (n == null) {
-                throw new InvalidItemStateException(path.toString());
+            try {
+                node = getNode(sessionContext, path);
+                revision = sessionContext.getRevision();
+            }
+            catch (PathNotFoundException e) {
+                throw new InvalidItemStateException(path.toString(), e);
             }
-
-            node = n;
-            revision = sessionContext.getRevision();
         }
         return node;
     }
 
-    private static JsonObject getNode(Context sessionContext, Path path) {
-        if (!sessionContext.getTransientSpace().nodeExists(path)) {
-            return null;
-        }
-
-        NodeDelta delta;
-        try {
-            delta = sessionContext.getTransientSpace().getNode(path);
-        }
-        catch (ItemNotFoundException e) {
-            // should not happen
-            throw new IllegalStateException(e);
-        }
+    private static JsonObject getNode(Context sessionContext, Path path) throws PathNotFoundException
{
+        NodeDelta delta = sessionContext.getTransientSpace().getNode(path);
 
         Path persistedPath = delta.getPersistentPath();
         if (persistedPath == null) {
@@ -651,10 +635,6 @@ public class NodeImpl extends ItemImpl i
 
         MicroKernel microkernel = sessionContext.getMicrokernel();
         String revision = sessionContext.getRevision();
-        if (!microkernel.nodeExists(persistedPath.getMkPath(), revision)) {
-            return null;
-        }
-
         String nodeJson = microkernel.getNodes(persistedPath.getMkPath(), revision, 0, 0,
-1);
         return FullJsonParser.parseObject(new UnescapingJsonTokenizer(nodeJson));
     }

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/PropertyImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/PropertyImpl.java?rev=1224983&r1=1224982&r2=1224983&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/PropertyImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/PropertyImpl.java
Tue Dec 27 19:23:56 2011
@@ -32,7 +32,6 @@ import org.apache.jackrabbit.utils.Value
 
 import javax.jcr.Binary;
 import javax.jcr.InvalidItemStateException;
-import javax.jcr.ItemNotFoundException;
 import javax.jcr.ItemVisitor;
 import javax.jcr.Node;
 import javax.jcr.PathNotFoundException;
@@ -52,7 +51,12 @@ public class PropertyImpl extends ItemIm
     private JsonValue value;
 
     public static boolean exist(Context sessionContext, Path path) {
-        return getProperty(sessionContext, path) != null;
+        try {
+            return getProperty(sessionContext, path) != null;
+        }
+        catch (PathNotFoundException e) {
+            return false;
+        }
     }
 
     static Property create(Context sessionContext, Path path) throws RepositoryException
{
@@ -301,33 +305,21 @@ public class PropertyImpl extends ItemIm
 
     //------------------------------------------< private >---
 
-    private JsonValue resolve() throws RepositoryException {
+    private JsonValue resolve() throws InvalidItemStateException {
         if (isStale()) {
-            JsonValue v = getProperty(sessionContext, path);
-            if (v == null) {
-                throw new InvalidItemStateException(path.toString());
+            try {
+                value = getProperty(sessionContext, path);
+                revision = sessionContext.getRevision();
+            }
+            catch (PathNotFoundException e) {
+                throw new InvalidItemStateException(path.toString(), e);
             }
-
-            value = v;
-            revision = sessionContext.getRevision();
         }
         return value;
     }
 
-    private static JsonValue getProperty(Context sessionContext, Path path) {
-        Path parentPath = path.getParent();
-        if (!sessionContext.getTransientSpace().nodeExists(parentPath)) {
-            return null;
-        }
-
-        NodeDelta delta;
-        try {
-            delta = sessionContext.getTransientSpace().getNode(parentPath);
-        }
-        catch (ItemNotFoundException e) {
-            // should never happen
-            throw new IllegalStateException(e);
-        }
+    private static JsonValue getProperty(Context sessionContext, Path path) throws PathNotFoundException
{
+        NodeDelta delta = sessionContext.getTransientSpace().getNode(path.getParent());
 
         String name = path.getName();
         if (delta.hasProperty(name)) {
@@ -341,13 +333,15 @@ public class PropertyImpl extends ItemIm
 
         MicroKernel microkernel = sessionContext.getMicrokernel();
         String revision = sessionContext.getRevision();
-        if (!microkernel.nodeExists(persistedPath.getMkPath(), revision)) {
-            return null;
-        }
-
         String nodeJson = microkernel.getNodes(persistedPath.getMkPath(), revision, 0, 0,
-1);
         JsonObject node = FullJsonParser.parseObject(new UnescapingJsonTokenizer(nodeJson));
-        return node.value().get(name);
+        JsonValue jsonValue = node.value().get(name);
+        if (jsonValue == null) {
+            throw new PathNotFoundException(path.getPath());
+        }
+        else {
+            return jsonValue;
+        }
     }
 
 }

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=1224983&r1=1224982&r2=1224983&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
Tue Dec 27 19:23:56 2011
@@ -94,9 +94,9 @@ public class ChangeTree {
     }
 
     public boolean hasChanges() {
-        return root.hasChanges();   
+        return root.hasChanges();
     }
-    
+
     private NodeDelta getNodeOrNull(Path path) {
         NodeDelta delta = root;
         for (String name : path.getNames()) {
@@ -199,7 +199,7 @@ public class ChangeTree {
         public boolean hasChanges() {
             return !childNodes.isEmpty() || !properties.isEmpty();
         }
-        
+
         public final boolean hasNode(String name) {
             return getNode(name) != null;
         }
@@ -219,7 +219,7 @@ public class ChangeTree {
         public boolean hasProperty(String name) {
             return properties.containsKey(name);
         }
-        
+
         public JsonValue getProperty(String name) {
             return properties.get(name);
         }
@@ -333,7 +333,7 @@ public class ChangeTree {
             return delta;
         }
     }
-    
+
     public class Existing extends NodeDelta {
         Existing(NodeDelta parent, String name) {
             super(parent, name);
@@ -369,8 +369,8 @@ public class ChangeTree {
             NodeDelta delta = getChild(name);
             if (delta == null) {
                 return nodeExists.apply(getPath().concat(name).getMkPath())
-                    ? new Existing(this, name)
-                    : null;
+                        ? new Existing(this, name)
+                        : null;
             }
             else {
                 return delta.isRemoved() ? null : delta;
@@ -581,5 +581,5 @@ public class ChangeTree {
             throw new IllegalStateException("Removed");
         }
     }
-    
+
 }

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/TransientSpace.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/TransientSpace.java?rev=1224983&r1=1224982&r2=1224983&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/TransientSpace.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/TransientSpace.java
Tue Dec 27 19:23:56 2011
@@ -8,7 +8,7 @@ import org.apache.jackrabbit.state.Chang
 import org.apache.jackrabbit.state.ChangeTree.NodeDelta;
 import org.apache.jackrabbit.utils.Function1;
 
-import javax.jcr.ItemNotFoundException;
+import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
 
 public class TransientSpace {
@@ -32,7 +32,7 @@ public class TransientSpace {
         return changeTree.nodeExists(path);
     }
 
-    public NodeDelta getNode(Path path) throws ItemNotFoundException {
+    public NodeDelta getNode(Path path) throws PathNotFoundException {
         return changeTree.getNode(path);
     }
 

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=1224983&r1=1224982&r2=1224983&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
Tue Dec 27 19:23:56 2011
@@ -22,6 +22,7 @@ import org.junit.internal.matchers.TypeS
 
 import javax.jcr.ItemExistsException;
 import javax.jcr.ItemNotFoundException;
+import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
 
 import static org.apache.jackrabbit.state.TransientSpaceTest.MicrokernelMatcher.propertyExists;
@@ -50,8 +51,8 @@ public class TransientSpaceTest {
         mk.dispose();
     }
 
-    @Test(expected = ItemNotFoundException.class)
-    public void getNotExistingNode() throws ItemNotFoundException {
+    @Test(expected = PathNotFoundException.class)
+    public void getNotExistingNode() throws PathNotFoundException, ItemNotFoundException
{
         transientSpace.getNode(ROOT.concat("any"));
     }
     
@@ -191,7 +192,7 @@ public class TransientSpaceTest {
         sourceNode.moveNode("node", ROOT.concat("target/moved"));
     }
 
-    @Test(expected = ItemNotFoundException.class)
+    @Test(expected = PathNotFoundException.class)
     public void moveToNotExistingTarget() throws RepositoryException {
         NodeDelta root = transientSpace.getNode(ROOT);
         root.addNode("source").addNode("node");



Mime
View raw message