jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1298885 - /jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/TransientSpace.java
Date Fri, 09 Mar 2012 15:42:23 GMT
Author: mduerig
Date: Fri Mar  9 15:42:23 2012
New Revision: 1298885

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

Modified:
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/TransientSpace.java

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=1298885&r1=1298884&r2=1298885&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
Fri Mar  9 15:42:23 2012
@@ -26,7 +26,6 @@ import org.apache.jackrabbit.mk.api.Micr
 import org.apache.jackrabbit.spi.commons.iterator.Predicate;
 import org.apache.jackrabbit.state.ChangeTree.Listener;
 import org.apache.jackrabbit.state.ChangeTree.NodeDelta;
-import org.apache.jackrabbit.utils.Provider;
 
 import javax.jcr.RepositoryException;
 
@@ -38,8 +37,29 @@ import javax.jcr.RepositoryException;
  */
 public class TransientSpace {
     private final MicroKernel microkernel;
+    private final String workspace;
     private final ChangeLog changeLog = new ChangeLog();
-    private final Provider<ChangeTree> changeTreeProvider;
+    private final Listener changeTreeListener = new Listener() {
+        @Override
+        public void added(NodeDelta nodeDelta) {
+            changeLog.addNode(nodeDelta.getPath());
+        }
+
+        @Override
+        public void removed(NodeDelta nodeDelta) {
+            changeLog.removeNode(nodeDelta.getPath());
+        }
+
+        @Override
+        public void moved(Path source, NodeDelta nodeDelta) {
+            changeLog.moveNode(source, nodeDelta.getPath());
+        }
+
+        @Override
+        public void setValue(NodeDelta parent, String name, JsonValue value) {
+            changeLog.setProperty(parent.getPath(), name, value);
+        }
+    };
 
     private ChangeTree changeTree;
     private String revision;
@@ -53,45 +73,10 @@ public class TransientSpace {
      */
     public TransientSpace(final String workspace, final MicroKernel microkernel, final String
revision) {
         this.microkernel = microkernel;
+        this.workspace = workspace;
         this.revision = revision;
 
-        final Listener changeTreeListener = new Listener() {
-            @Override
-            public void added(NodeDelta nodeDelta) {
-                changeLog.addNode(nodeDelta.getPath());
-            }
-
-            @Override
-            public void removed(NodeDelta nodeDelta) {
-                changeLog.removeNode(nodeDelta.getPath());
-            }
-
-            @Override
-            public void moved(Path source, NodeDelta nodeDelta) {
-                changeLog.moveNode(source, nodeDelta.getPath());
-            }
-
-            @Override
-            public void setValue(NodeDelta parent, String name, JsonValue value) {
-                changeLog.setProperty(parent.getPath(), name, value);
-            }
-        };
-
-        final Predicate<Path> nodeExists = new Predicate<Path>() {
-            @Override
-            public boolean evaluate(Path path) {
-                return microkernel.nodeExists(path.toMkPath(), getRevision());
-            }
-        };
-
-        changeTreeProvider = new Provider<ChangeTree>() {
-            @Override
-            public ChangeTree get() {
-                return new ChangeTree(Path.create(workspace), changeTreeListener, nodeExists);
-            }
-        };
-
-        changeTree = changeTreeProvider.get();
+        changeTree = createChangeTree(workspace, changeTreeListener);
     }
 
     /**
@@ -113,7 +98,7 @@ public class TransientSpace {
         try {
             revision = microkernel.commit("", changeLog.toJsop(), revision, "");
             changeLog.clear();
-            changeTree = changeTreeProvider.get();
+            changeTree = createChangeTree(workspace, changeTreeListener);
             return revision;
         }
         catch (MicroKernelException e) {
@@ -129,12 +114,13 @@ public class TransientSpace {
      * @return the new revision
      */
     public String refresh(boolean keepChanges) {
+        revision = microkernel.getHeadRevision();
         if (!keepChanges) {
             changeLog.clear();
-            changeTree = changeTreeProvider.get();
+            changeTree = createChangeTree(workspace, changeTreeListener);
         }
 
-        return revision = microkernel.getHeadRevision();
+        return revision;
     }
 
     /**
@@ -146,7 +132,13 @@ public class TransientSpace {
 
     //------------------------------------------< private >---
 
-    private String getRevision() {
-        return revision;
+    private ChangeTree createChangeTree(final String workspace, Listener listener) {
+        return new ChangeTree(Path.create(workspace), listener, new Predicate<Path>()
{
+            @Override
+            public boolean evaluate(Path path) {
+                return microkernel.nodeExists(path.toMkPath(), revision);
+            }
+        });
     }
+
 }



Mime
View raw message