jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1298931 - in /jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit: state/TransientNodeState.java utils/Provider.java
Date Fri, 09 Mar 2012 17:23:41 GMT
Author: mduerig
Date: Fri Mar  9 17:23:41 2012
New Revision: 1298931

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

Removed:
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Provider.java
Modified:
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/TransientNodeState.java

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=1298931&r1=1298930&r2=1298931&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
Fri Mar  9 17:23:41 2012
@@ -31,7 +31,6 @@ import org.apache.jackrabbit.spi.commons
 import org.apache.jackrabbit.spi.commons.iterator.Predicate;
 import org.apache.jackrabbit.spi.commons.iterator.Transformer;
 import org.apache.jackrabbit.state.ChangeTree.NodeDelta;
-import org.apache.jackrabbit.utils.Provider;
 
 import javax.jcr.ItemExistsException;
 import javax.jcr.ItemNotFoundException;
@@ -42,24 +41,14 @@ import java.util.Map.Entry;
 
 public class TransientNodeState {
     private final Context sessionContext;
-    private final Provider<NodeDelta> nodeDelta;
 
     private String revision;
     private JsonObject jsonObject;
+    private NodeDelta nodeDelta;
 
-    private TransientNodeState(Context sessionContext, final NodeDelta nodeDelta) {
+    private TransientNodeState(Context sessionContext, NodeDelta nodeDelta) {
         this.sessionContext = sessionContext;
-
-        this.nodeDelta = new Provider<NodeDelta>() {
-            private NodeDelta nd = nodeDelta;
-
-            @Override
-            public NodeDelta get() {
-                // todo: return cached value as long as no refresh(false) has occurred.
-                nd = getTransientSpace().getNodeDelta(nd.getPath());
-                return nd;
-            }
-        };
+        this.nodeDelta = nodeDelta;
     }
 
     public boolean isRoot() {
@@ -67,7 +56,7 @@ public class TransientNodeState {
     }
 
     public Path getPath() {
-        return nodeDelta.get().getPath();
+        return getNodeDelta().getPath();
     }
 
     public String getName() {
@@ -75,32 +64,32 @@ public class TransientNodeState {
     }
 
     public boolean isNew() {
-        NodeDelta nd = nodeDelta.get();
-        return nd.isTransient() && !nd.isRemoved();
+        NodeDelta delta = getNodeDelta();
+        return delta.isTransient() && !delta.isRemoved();
     }
 
     public boolean isModified() {
-        return nodeDelta.get().isTransient();
+        return getNodeDelta().isTransient();
     }
 
     public TransientNodeState addNode(String name) throws ItemExistsException {
-        NodeDelta child = nodeDelta.get().addNode(name);
+        NodeDelta child = getNodeDelta().addNode(name);
         return getNodeState(sessionContext, child);
     }
 
     public void remove() throws ItemNotFoundException {
-        nodeDelta.get().getParent().removeNode(getName());
+        getNodeDelta().getParent().removeNode(getName());
     }
 
     public void move(String name, Path destination) throws ItemExistsException, PathNotFoundException,
             ItemNotFoundException {
 
-        nodeDelta.get().moveNode(name, destination);
+        getNodeDelta().moveNode(name, destination);
         nodeStateCache().remove(getPath().concat(name));
     }
 
     public void setProperty(String name, JsonValue value) {
-        nodeDelta.get().setValue(name, value);
+        getNodeDelta().setValue(name, value);
     }
 
     public boolean hasChildNodeStates() {
@@ -115,7 +104,7 @@ public class TransientNodeState {
                     new Predicate<Entry<String, JsonValue>>() {
                         @Override
                         public boolean evaluate(Entry<String, JsonValue> entry) {
-                            return isNode(entry.getValue()) && !nodeDelta.get().isNodeModified(entry.getKey());
+                            return isNode(entry.getValue()) && !getNodeDelta().isNodeModified(entry.getKey());
                         }
                     });
 
@@ -123,11 +112,11 @@ public class TransientNodeState {
             new Transformer<Entry<String, JsonValue>, TransientNodeState>() {
                 @Override
                 public TransientNodeState transform(Entry<String, JsonValue> entry)
{
-                    return getNodeState(sessionContext, nodeDelta.get().getNode(entry.getKey()));
+                    return getNodeState(sessionContext, getNodeDelta().getNode(entry.getKey()));
                 }
         });
 
-        Iterator<TransientNodeState> modifiedNodeStates = Iterators.transformIterator(nodeDelta.get().getNodes(),
+        Iterator<TransientNodeState> modifiedNodeStates = Iterators.transformIterator(getNodeDelta().getNodes(),
             new Transformer<NodeDelta, TransientNodeState>() {
                 @Override
                 public TransientNodeState transform(NodeDelta delta) {
@@ -155,11 +144,11 @@ public class TransientNodeState {
                         @Override
                         public boolean evaluate(Entry<String, JsonValue> entry) {
                             return !entry.getKey().startsWith(":") && !isNode(entry.getValue())
-                                    && !nodeDelta.get().hasProperty(entry.getKey());
+                                    && !getNodeDelta().hasProperty(entry.getKey());
                         }
                     });
 
-        return Iterators.iteratorChain(propertyEntries, nodeDelta.get().getProperties());
+        return Iterators.iteratorChain(propertyEntries, getNodeDelta().getProperties());
     }
 
     public Iterator<Entry<String, JsonValue>> getProperties(Predicate<Entry<String,
JsonValue>> condition) {
@@ -180,16 +169,16 @@ public class TransientNodeState {
     }
 
     public boolean isPropertyNew(String name) {
-        JsonValue value = nodeDelta.get().getProperty(name);
+        JsonValue value = getNodeDelta().getProperty(name);
         return value != null && !value.isNull() && getPersistedPropertyValue(name)
== null;
     }
 
     public boolean isPropertyModified(String name) {
-        return nodeDelta.get().hasProperty(name);
+        return getNodeDelta().hasProperty(name);
     }
 
     public void removeProperty(String name) {
-        nodeDelta.get().setValue(name, null);
+        getNodeDelta().setValue(name, null);
     }
 
     public static TransientNodeState getNodeState(Context sessionContext, Path path) {
@@ -241,7 +230,7 @@ public class TransientNodeState {
     }
 
     private JsonValue getPropertyValueOrNull(String name) {
-        JsonValue value = nodeDelta.get().getProperty(name);
+        JsonValue value = getNodeDelta().getProperty(name);
         if (value == null) {
             return getPersistedPropertyValue(name);
         }
@@ -261,7 +250,7 @@ public class TransientNodeState {
     }
 
     private synchronized JsonObject getJsonObject() {
-        Path path = nodeDelta.get().getPersistentPath();
+        Path path = getNodeDelta().getPersistentPath();
         String baseRevision = getBaseRevision();
         if (jsonObject == null || !revision.equals(baseRevision)) {
             revision =  baseRevision;
@@ -277,4 +266,8 @@ public class TransientNodeState {
         return jsonObject;
     }
 
+    private NodeDelta getNodeDelta() {
+        return nodeDelta = getTransientSpace().getNodeDelta(nodeDelta.getPath());
+    }
+
 }



Mime
View raw message