jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1299676 - in /jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit: ItemImpl.java SessionContext.java SessionImpl.java state/NodeStateProvider.java state/PersistentNodeState.java state/TransientNodeState.java
Date Mon, 12 Mar 2012 14:09:54 GMT
Author: mduerig
Date: Mon Mar 12 14:09:54 2012
New Revision: 1299676

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

Added:
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/NodeStateProvider.java
Modified:
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/ItemImpl.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/SessionContext.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/SessionImpl.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/PersistentNodeState.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/TransientNodeState.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=1299676&r1=1299675&r2=1299676&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
Mon Mar 12 14:09:54 2012
@@ -86,7 +86,7 @@ abstract class ItemImpl implements Item 
     //------------------------------------------< internal >---
 
     protected static TransientNodeState getNodeState(Context sessionContext, Path path) {
-        return sessionContext.getSession().getNodeState(path);
+        return sessionContext.getNodeStateProvider().getNodeState(path);
     }
 
 }

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/SessionContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/SessionContext.java?rev=1299676&r1=1299675&r2=1299676&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/SessionContext.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/SessionContext.java
Mon Mar 12 14:09:54 2012
@@ -21,8 +21,7 @@ package org.apache.jackrabbit;
 
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.security.CredentialsInfo;
-import org.apache.jackrabbit.state.TransientNodeStateCache;
-import org.apache.jackrabbit.state.TransientSpace;
+import org.apache.jackrabbit.state.NodeStateProvider;
 
 import javax.jcr.Session;
 import javax.jcr.ValueFactory;
@@ -35,6 +34,5 @@ public interface SessionContext<T extend
     MicroKernel getMicrokernel();
     String getRevision();
     ValueFactory getValueFactory();
-    TransientSpace getTransientSpace();
-    TransientNodeStateCache getNodeStateCache();
+    NodeStateProvider getNodeStateProvider();
 }

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/SessionImpl.java?rev=1299676&r1=1299675&r2=1299676&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/SessionImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/SessionImpl.java
Mon Mar 12 14:09:54 2012
@@ -19,13 +19,11 @@
 
 package org.apache.jackrabbit;
 
-import org.apache.jackrabbit.configuration.RepositoryConfiguration;
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.security.Authenticator;
 import org.apache.jackrabbit.security.CredentialsInfo;
-import org.apache.jackrabbit.state.ChangeTree.NodeDelta;
+import org.apache.jackrabbit.state.NodeStateProvider;
 import org.apache.jackrabbit.state.TransientNodeState;
-import org.apache.jackrabbit.state.TransientNodeStateCache;
 import org.apache.jackrabbit.state.TransientSpace;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
@@ -56,7 +54,7 @@ public class SessionImpl implements Sess
     private final String workspaceName;
     private final MicroKernel microKernel;
     private final TransientSpace transientSpace;
-    private final TransientNodeStateCache nodeStateCache;
+    private final NodeStateProvider nodeStateProvider;
 
     private String revision;
     private boolean live = true;
@@ -100,13 +98,8 @@ public class SessionImpl implements Sess
         }
 
         @Override
-        public TransientSpace getTransientSpace() {
-            return transientSpace;
-        }
-
-        @Override
-        public TransientNodeStateCache getNodeStateCache() {
-            return nodeStateCache;
+        public NodeStateProvider getNodeStateProvider() {
+            return nodeStateProvider;
         }
     };
 
@@ -138,19 +131,6 @@ public class SessionImpl implements Sess
         }
     };
 
-    public TransientNodeState getNodeState(Path path) {
-        TransientNodeState state = nodeStateCache.get(path);
-        if (state == null) {
-            NodeDelta delta = transientSpace.getNodeDelta(path);
-            if (delta == null) {
-                return null;
-            }
-            state = new TransientNodeState(sessionContext, delta);
-            nodeStateCache.put(path, state);
-        }
-        return state;
-    }
-
     private SessionImpl(GlobalContext globalContext, CredentialsInfo credentialsInfo, String
workspaceName,
                         String revision) {
 
@@ -160,8 +140,7 @@ public class SessionImpl implements Sess
         this.revision = revision;
         microKernel = globalContext.getInstance(MicroKernel.class);
         transientSpace = new TransientSpace(workspaceName, microKernel, revision);
-        nodeStateCache = globalContext.getInstance(CacheFactory.class)
-            .create(globalContext.getInstance(RepositoryConfiguration.class));
+        nodeStateProvider = new NodeStateProvider(sessionContext, transientSpace);
     }
 
     //------------------------------------------< Session >--- 
@@ -270,7 +249,7 @@ public class SessionImpl implements Sess
         checkLive();
         
         Path sourcePath = Path.create(workspaceName, srcAbsPath);
-        TransientNodeState sourceParent = getNodeState(sourcePath.getParent());
+        TransientNodeState sourceParent = nodeStateProvider.getNodeState(sourcePath.getParent());
         if (sourceParent == null) {
             throw new PathNotFoundException(srcAbsPath);
         }
@@ -290,14 +269,14 @@ public class SessionImpl implements Sess
     public void save() throws RepositoryException {
         checkLive();
         revision = transientSpace.save();
-        nodeStateCache.clear();
+        nodeStateProvider.clear();
     }
 
     @Override
     public void refresh(boolean keepChanges) throws RepositoryException {
         checkLive();
         revision = transientSpace.refresh(keepChanges);
-        nodeStateCache.clear();
+        nodeStateProvider.clear();
     }
 
     @Override

Added: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/NodeStateProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/NodeStateProvider.java?rev=1299676&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/NodeStateProvider.java
(added)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/NodeStateProvider.java
Mon Mar 12 14:09:54 2012
@@ -0,0 +1,55 @@
+package org.apache.jackrabbit.state;
+
+import org.apache.jackrabbit.Path;
+import org.apache.jackrabbit.SessionImpl.Context;
+import org.apache.jackrabbit.state.ChangeTree.NodeDelta;
+
+public class NodeStateProvider {
+    private final Context sessionContext;
+    private final TransientSpace transientSpace;
+    private final TransientNodeStateCache nodeStateCache;
+
+    public NodeStateProvider(Context sessionContext, TransientSpace transientSpace) {
+        this.sessionContext = sessionContext;
+        this.transientSpace = transientSpace;
+        nodeStateCache = new TransientNodeStateCacheImpl(100); // fixme don't hard code
+    }
+
+    public TransientNodeState getNodeState(Path path) {
+        TransientNodeState state = nodeStateCache.get(path);
+        if (state == null) {
+            NodeDelta delta = transientSpace.getNodeDelta(path);
+            if (delta == null) {
+                return null;
+            }
+            state = new TransientNodeState(sessionContext, delta);
+            nodeStateCache.put(path, state);
+        }
+        return state;
+    }
+
+    public void release(Path path) {
+        nodeStateCache.remove(path);
+    }
+
+    public void clear() {
+        nodeStateCache.clear();
+    }
+
+    //------------------------------------------< internal/private >---
+
+    TransientNodeState getNodeState(NodeDelta nodeDelta) {
+        Path path = nodeDelta.getPath();
+        TransientNodeState state = nodeStateCache.get(path);
+        if (state == null) {
+            state = new TransientNodeState(sessionContext, nodeDelta);
+            nodeStateCache.put(path, state);
+        }
+        return state;
+    }
+
+    NodeDelta getNodeDelta(Path path) {
+        return transientSpace.getNodeDelta(path);
+    }
+
+}

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/PersistentNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/PersistentNodeState.java?rev=1299676&r1=1299675&r2=1299676&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/PersistentNodeState.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/PersistentNodeState.java
Mon Mar 12 14:09:54 2012
@@ -40,10 +40,10 @@ public class PersistentNodeState extends
             }
     };
     
-    public PersistentNodeState(MicroKernel microkernel, String revision, Path path) {
+    PersistentNodeState(MicroKernel microkernel, Path path, String revision) {
         this.microkernel = microkernel;
-        this.revision = revision;
         this.path = path;
+        this.revision = revision;
     }
     
     @Override
@@ -59,7 +59,7 @@ public class PersistentNodeState extends
     @Override
     public NodeState getChildNode(String name) {
         if (microkernel.nodeExists(name, revision)) {
-            return new PersistentNodeState(microkernel, revision, path.concat(name));
+            return new PersistentNodeState(microkernel, path.concat(name), revision);
         }
         else {
             return null;
@@ -106,7 +106,7 @@ public class PersistentNodeState extends
 
             @Override
             public NodeState getNode() {
-                return new PersistentNodeState(microkernel, revision, path.concat(name));
+                return new PersistentNodeState(microkernel, path.concat(name), revision);
             }
 
             @Override

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/TransientNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/TransientNodeState.java?rev=1299676&r1=1299675&r2=1299676&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/TransientNodeState.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/TransientNodeState.java
Mon Mar 12 14:09:54 2012
@@ -23,7 +23,6 @@ import org.apache.jackrabbit.Path;
 import org.apache.jackrabbit.SessionImpl.Context;
 import org.apache.jackrabbit.json.JsonValue;
 import org.apache.jackrabbit.json.JsonValue.JsonAtom;
-import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.oak.model.ChildNodeEntry;
 import org.apache.jackrabbit.oak.model.NodeState;
 import org.apache.jackrabbit.oak.model.PropertyState;
@@ -37,9 +36,9 @@ import javax.jcr.ItemNotFoundException;
 import javax.jcr.PathNotFoundException;
 import java.util.Iterator;
 
+import static org.apache.jackrabbit.utils.Iterators.chain;
 import static org.apache.jackrabbit.utils.Iterators.filter;
 import static org.apache.jackrabbit.utils.Iterators.flatten;
-import static org.apache.jackrabbit.utils.Iterators.chain;
 import static org.apache.jackrabbit.utils.Iterators.map;
 
 public class TransientNodeState {
@@ -51,7 +50,7 @@ public class TransientNodeState {
     private NodeState persistentNodeState;
     private NodeDelta nodeDelta;
 
-    public TransientNodeState(Context sessionContext, NodeDelta nodeDelta) {
+    TransientNodeState(Context sessionContext, NodeDelta nodeDelta) {
         this.sessionContext = sessionContext;
         this.nodeDelta = nodeDelta;
     }
@@ -79,11 +78,11 @@ public class TransientNodeState {
 
     public TransientNodeState addNode(String name) throws ItemExistsException {
         NodeDelta child = getNodeDelta().addNode(name);
-        return getNodeState(sessionContext, child);
+        return getNodeState(child);
     }
 
     public void remove() throws ItemNotFoundException {
-        nodeStateCache().remove(getPath());
+        getNodeStateProvider().release(getPath());
         getNodeDelta().getParent().removeNode(getName());
     }
 
@@ -91,7 +90,7 @@ public class TransientNodeState {
             ItemNotFoundException {
 
         getNodeDelta().moveNode(name, destination);
-        nodeStateCache().remove(getPath().concat(name));
+        getNodeStateProvider().release(getPath().concat(name));
     }
 
     public void setProperty(String name, JsonValue value) {
@@ -126,7 +125,7 @@ public class TransientNodeState {
                 new Function1<ChildNodeEntry, TransientNodeState>() {
                     @Override
                     public TransientNodeState apply(ChildNodeEntry entry) {
-                        return getNodeState(sessionContext, delta.getNode(entry.getName()));
+                        return getNodeState(delta.getNode(entry.getName()));
                     }
                 });
 
@@ -134,7 +133,7 @@ public class TransientNodeState {
                 new Function1<NodeDelta, TransientNodeState>() {
                     @Override
                     public TransientNodeState apply(NodeDelta delta) {
-                        return getNodeState(sessionContext, delta);
+                        return getNodeState(delta);
                     }
                 });
 
@@ -195,32 +194,12 @@ public class TransientNodeState {
 
     //------------------------------------------< private >---
 
-    private TransientNodeStateCache nodeStateCache() {
-        return sessionContext.getNodeStateCache();
-    }
-    
-    private MicroKernel getMicrokernel() {
-        return sessionContext.getMicrokernel();
-    }
-    
-    private String getBaseRevision() {
-        return sessionContext.getRevision();
+    private NodeStateProvider getNodeStateProvider() {
+        return sessionContext.getNodeStateProvider();
     }
     
-    private TransientSpace getTransientSpace() {
-        return sessionContext.getTransientSpace();
-    }
-    
-    private static TransientNodeState getNodeState(Context sessionContext, NodeDelta nodeDelta)
{
-        TransientNodeStateCache cache = sessionContext.getNodeStateCache();
-        Path path = nodeDelta.getPath();
-
-        TransientNodeState state = cache.get(path);
-        if (state == null) {
-            state = new TransientNodeState(sessionContext, nodeDelta);
-            cache.put(path, state);
-        }
-        return state;
+    private TransientNodeState getNodeState(NodeDelta nodeDelta) {
+        return getNodeStateProvider().getNodeState(nodeDelta);
     }
 
     private JsonValue getPropertyValueOrNull(String name) {
@@ -245,14 +224,14 @@ public class TransientNodeState {
 
     private synchronized NodeState getPersistentNodeState() {
         Path path = getNodeDelta().getPersistentPath();
-        String baseRevision = getBaseRevision();
+        String baseRevision = sessionContext.getRevision();
         if (persistentNodeState == null || !revision.equals(baseRevision)) {
-            revision =  baseRevision;
+            revision = baseRevision;
             if (path == null) {
                 persistentNodeState = EmptyNodeState.INSTANCE;
             }
             else {
-                persistentNodeState = new PersistentNodeState(getMicrokernel(), revision,
path);
+                persistentNodeState = new PersistentNodeState(sessionContext.getMicrokernel(),
path, revision);
             }
         }
 
@@ -260,7 +239,7 @@ public class TransientNodeState {
     }
 
     private NodeDelta getNodeDelta() {
-        return nodeDelta = getTransientSpace().getNodeDelta(nodeDelta.getPath());
+        return nodeDelta = getNodeStateProvider().getNodeDelta(nodeDelta.getPath());
     }
 
 }



Mime
View raw message