jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1245082 - in /jackrabbit/sandbox/jackrabbit-microkernel/src: main/java/org/apache/jackrabbit/state/NodeState.java main/java/org/apache/jackrabbit/utils/Provider.java test/java/org/apache/jackrabbit/RepositoryTest.java
Date Thu, 16 Feb 2012 17:01:53 GMT
Author: mduerig
Date: Thu Feb 16 17:01:53 2012
New Revision: 1245082

URL: http://svn.apache.org/viewvc?rev=1245082&view=rev
Log:
Microkernel based prototype of JCR implementation (WIP)
- make refresh(false) work correctly  

Added:
    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/NodeState.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/RepositoryTest.java

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/NodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/NodeState.java?rev=1245082&r1=1245081&r2=1245082&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/NodeState.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/NodeState.java
Thu Feb 16 17:01:53 2012
@@ -31,6 +31,7 @@ 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;
@@ -41,14 +42,23 @@ import java.util.Map.Entry;
 
 public class NodeState {
     private final Context sessionContext;
-    private final NodeDelta nodeDelta;  // fixme: re-resolve on refresh/save
+    private final Provider<NodeDelta> nodeDelta;
 
     private String revision;
     private JsonObject jsonObject;
 
-    private NodeState(Context sessionContext, NodeDelta nodeDelta) {
+    private NodeState(Context sessionContext, final NodeDelta nodeDelta) {
         this.sessionContext = sessionContext;
-        this.nodeDelta = nodeDelta;
+
+        this.nodeDelta = new Provider<NodeDelta>() {
+            private NodeDelta nd = nodeDelta;
+
+            @Override
+            public NodeDelta get() {
+                nd = getTransientSpace().getNodeDelta(nd.getPath());
+                return nd;
+            }
+        };
     }
 
     public boolean isRoot() {
@@ -56,7 +66,7 @@ public class NodeState {
     }
 
     public Path getPath() {
-        return nodeDelta.getPath();
+        return nodeDelta.get().getPath();
     }
 
     public String getName() {
@@ -64,31 +74,32 @@ public class NodeState {
     }
 
     public boolean isNew() {
-        return nodeDelta.isTransient() && !nodeDelta.isRemoved();
+        NodeDelta nd = nodeDelta.get();
+        return nd.isTransient() && !nd.isRemoved();
     }
 
     public boolean isModified() {
-        return nodeDelta.isTransient();
+        return nodeDelta.get().isTransient();
     }
 
     public NodeState addNode(String name) throws ItemExistsException {
-        NodeDelta child = nodeDelta.addNode(name);
+        NodeDelta child = nodeDelta.get().addNode(name);
         return getNodeState(sessionContext, child);
     }
 
     public void remove() throws ItemNotFoundException {
-        nodeDelta.getParent().removeNode(getName());
+        nodeDelta.get().getParent().removeNode(getName());
     }
 
     public void move(String name, Path destination) throws ItemExistsException, PathNotFoundException,
             ItemNotFoundException {
 
-        nodeDelta.moveNode(name, destination);
+        nodeDelta.get().moveNode(name, destination);
         nodeStateCache().remove(getPath().concat(name));
     }
 
     public void setProperty(String name, JsonValue value) {
-        nodeDelta.setValue(name, value);
+        nodeDelta.get().setValue(name, value);
     }
 
     public boolean hasChildNodeStates() {
@@ -100,22 +111,22 @@ public class NodeState {
 
         Iterator<Entry<String, JsonValue>> childNodeEntries =
             Iterators.filterIterator(childEntries.entrySet().iterator(),
-                new Predicate<Entry<String, JsonValue>>() {
-                    @Override
-                    public boolean evaluate(Entry<String, JsonValue> entry) {
-                        return isNode(entry.getValue()) && !nodeDelta.isNodeModified(entry.getKey());
-                    }
-                });
+                    new Predicate<Entry<String, JsonValue>>() {
+                        @Override
+                        public boolean evaluate(Entry<String, JsonValue> entry) {
+                            return isNode(entry.getValue()) && !nodeDelta.get().isNodeModified(entry.getKey());
+                        }
+                    });
 
         Iterator<NodeState> childNodeStates = Iterators.transformIterator(childNodeEntries,
             new Transformer<Entry<String, JsonValue>, NodeState>() {
                 @Override
                 public NodeState transform(Entry<String, JsonValue> entry) {
-                    return getNodeState(sessionContext, nodeDelta.getNode(entry.getKey()));
+                    return getNodeState(sessionContext, nodeDelta.get().getNode(entry.getKey()));
                 }
         });
 
-        Iterator<NodeState> modifiedNodeStates = Iterators.transformIterator(nodeDelta.getNodes(),
+        Iterator<NodeState> modifiedNodeStates = Iterators.transformIterator(nodeDelta.get().getNodes(),
             new Transformer<NodeDelta, NodeState>() {
                 @Override
                 public NodeState transform(NodeDelta delta) {
@@ -139,15 +150,15 @@ public class NodeState {
 
         Iterator<Entry<String, JsonValue>> propertyEntries =
             Iterators.filterIterator(childEntries.entrySet().iterator(),
-                new Predicate<Entry<String, JsonValue>>() {
-                    @Override
-                    public boolean evaluate(Entry<String, JsonValue> entry) {
-                        return !entry.getKey().startsWith(":") && !isNode(entry.getValue())
-                            && !nodeDelta.hasProperty(entry.getKey());
-                    }
-                });
+                    new Predicate<Entry<String, JsonValue>>() {
+                        @Override
+                        public boolean evaluate(Entry<String, JsonValue> entry) {
+                            return !entry.getKey().startsWith(":") && !isNode(entry.getValue())
+                                    && !nodeDelta.get().hasProperty(entry.getKey());
+                        }
+                    });
 
-        return Iterators.iteratorChain(propertyEntries, nodeDelta.getProperties());
+        return Iterators.iteratorChain(propertyEntries, nodeDelta.get().getProperties());
     }
 
     public Iterator<Entry<String, JsonValue>> getProperties(Predicate<Entry<String,
JsonValue>> condition) {
@@ -168,16 +179,16 @@ public class NodeState {
     }
 
     public boolean isPropertyNew(String name) {
-        JsonValue value = nodeDelta.getProperty(name);
+        JsonValue value = nodeDelta.get().getProperty(name);
         return value != null && !value.isNull() && getPersistedPropertyValue(name)
== null;
     }
 
     public boolean isPropertyModified(String name) {
-        return nodeDelta.hasProperty(name);
+        return nodeDelta.get().hasProperty(name);
     }
 
     public void removeProperty(String name) {
-        nodeDelta.setValue(name, null);
+        nodeDelta.get().setValue(name, null);
     }
 
     public static NodeState getNodeState(Context sessionContext, Path path) {
@@ -208,6 +219,10 @@ public class NodeState {
         return sessionContext.getRevision();
     }
     
+    private TransientSpace getTransientSpace() {
+        return sessionContext.getTransientSpace();
+    }
+    
     private static NodeState getNodeState(Context sessionContext, NodeDelta nodeDelta) {
         NodeStateCache cache = sessionContext.getNodeStateCache();
         Path path = nodeDelta.getPath();
@@ -225,7 +240,7 @@ public class NodeState {
     }
 
     private JsonValue getPropertyValueOrNull(String name) {
-        JsonValue value = nodeDelta.getProperty(name);
+        JsonValue value = nodeDelta.get().getProperty(name);
         if (value == null) {
             return getPersistedPropertyValue(name);
         }
@@ -245,7 +260,7 @@ public class NodeState {
     }
 
     private synchronized JsonObject getJsonObject() {
-        Path path = nodeDelta.getPersistentPath();
+        Path path = nodeDelta.get().getPersistentPath();
         String baseRevision = getBaseRevision();
         if (jsonObject == null || !revision.equals(baseRevision)) {
             revision =  baseRevision;

Added: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Provider.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Provider.java?rev=1245082&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Provider.java
(added)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Provider.java
Thu Feb 16 17:01:53 2012
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.utils;
+
+public interface Provider<T> {
+    T get();
+}

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=1245082&r1=1245081&r2=1245082&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 Feb 16 17:01:53 2012
@@ -1121,6 +1121,27 @@ public class RepositoryTest {
             session.logout();
         }
     }
+    
+    @Test
+    public void sessionRefreshFalse() throws RepositoryException {
+        Session session = getRepository().login();
+        try {
+            session.getNode("/").addNode("foo");
+            session.save();
+
+            Node foo = session.getNode("/foo");
+            foo.addNode("added");
+            NodeIterator it = foo.getNodes();
+            assertTrue(it.hasNext());
+
+            session.refresh(false);
+            it = foo.getNodes();
+            assertFalse(it.hasNext());
+        }
+        finally {
+            session.logout();
+        }
+    }
 
     @Test
     public void refreshConflict() throws RepositoryException {



Mime
View raw message