jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1407001 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: core/TreeImpl.java plugins/memory/MemoryNodeBuilder.java spi/state/NodeBuilder.java spi/state/ReadOnlyBuilder.java
Date Thu, 08 Nov 2012 10:35:07 GMT
Author: mduerig
Date: Thu Nov  8 10:35:06 2012
New Revision: 1407001

URL: http://svn.apache.org/viewvc?rev=1407001&view=rev
Log:
OAK-417: Refactor/reimplement TreeImpl.getStatus and TreeImpl.getPropertyStatus to take advantage
of the underlying NodeBuilder

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java?rev=1407001&r1=1407000&r2=1407001&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
Thu Nov  8 10:35:06 2012
@@ -39,7 +39,6 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.plugins.memory.MultiStringPropertyState;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
-import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
 import org.apache.jackrabbit.oak.spi.state.NodeStateUtils;
 import org.apache.jackrabbit.oak.spi.state.PropertyBuilder;
 
@@ -140,7 +139,7 @@ public class TreeImpl implements Tree {
         root.checkLive();
         Status nodeStatus = getStatus();
         if (nodeStatus == Status.NEW) {
-                return (hasProperty(name)) ? Status.NEW : null;
+            return (hasProperty(name)) ? Status.NEW : null;
         } else if (nodeStatus == Status.REMOVED) {
             return Status.REMOVED; // FIXME not correct if no property existed with that
name
         } else {
@@ -150,7 +149,8 @@ public class TreeImpl implements Tree {
                 return null;
             }
 
-            PropertyState base = getBaseState().getProperty(name);
+            NodeState parentBase = getBaseState();
+            PropertyState base = parentBase == null ? null : parentBase.getProperty(name);
             if (head == null) {
                 return (base == null) ? null : Status.REMOVED;
             } else {
@@ -200,26 +200,30 @@ public class TreeImpl implements Tree {
         }
     }
 
+    // FIXME rely on underlying mechanism to determine whether a node has been removed. (OAK-417)
+    private boolean isRemoved() {
+        try {
+            return getNodeBuilder().isRemoved();
+        } catch (IllegalStateException e) {
+            return true;
+        }
+    }
+
     @Override
     public Status getStatus() {
         root.checkLive();
+
         if (isRemoved()) {
             return Status.REMOVED;
         }
 
-        NodeState baseState = getBaseState();
-        if (baseState == null) {
-            // Did not exist before, so its NEW
+        NodeBuilder builder = getNodeBuilder();
+        if (builder.isNew()) {
             return Status.NEW;
+        } else if (builder.isModified()) {
+            return Status.MODIFIED;
         } else {
-            // Did exit it before. So...
-            if (isSame(baseState, getNodeState())) {
-                // ...it's EXISTING if it hasn't changed
-                return Status.EXISTING;
-            } else {
-                // ...and MODIFIED otherwise.
-                return Status.MODIFIED;
-            }
+            return Status.EXISTING;
         }
     }
 
@@ -488,19 +492,6 @@ public class TreeImpl implements Tree {
         return getNodeBuilder().getProperty(propertyName);
     }
 
-    // FIXME rely on underlying mechanism to determine whether a node has been removed. (OAK-417)
-    private boolean isRemoved() {
-        if (parent != null && parent.isRemoved()) {
-            return true;
-        }
-        try {
-            return getNodeBuilder().getNodeState() == null;
-        }
-        catch (IllegalStateException e) {
-            return true;
-        }
-    }
-
     private void buildPath(StringBuilder sb) {
         if (!isRoot()) {
             parent.buildPath(sb);
@@ -577,43 +568,6 @@ public class TreeImpl implements Tree {
         }
     }
 
-    private static boolean isSame(NodeState state1, NodeState state2) {
-        final boolean[] isDirty = {false};
-        state2.compareAgainstBaseState(state1, new NodeStateDiff() {
-            @Override
-            public void propertyAdded(PropertyState after) {
-                isDirty[0] = true;
-            }
-
-            @Override
-            public void propertyChanged(PropertyState before, PropertyState after) {
-                isDirty[0] = true;
-            }
-
-            @Override
-            public void propertyDeleted(PropertyState before) {
-                isDirty[0] = true;
-            }
-
-            @Override
-            public void childNodeAdded(String name, NodeState after) {
-                isDirty[0] = true;
-            }
-
-            @Override
-            public void childNodeChanged(String name, NodeState before, NodeState after)
{
-                // cut transitivity here
-            }
-
-            @Override
-            public void childNodeDeleted(String name, NodeState before) {
-                isDirty[0] = true;
-            }
-        });
-
-        return !isDirty[0];
-    }
-
     //-------------------------------------------------------< TreeLocation >---
 
     public class NodeLocation implements TreeLocation {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java?rev=1407001&r1=1407000&r2=1407001&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
Thu Nov  8 10:35:06 2012
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.oak.plugin
 
 import java.util.Iterator;
 import java.util.Map;
+import java.util.Map.Entry;
 
 import javax.annotation.Nonnull;
 
@@ -248,6 +249,51 @@ public class MemoryNodeBuilder implement
     //--------------------------------------------------------< NodeBuilder >---
 
     @Override
+    public boolean isNew() {
+        return this != root && parent.isNew(name);
+    }
+
+    private boolean isNew(String name) {
+        return (getBaseState() == null || !getBaseState().hasChildNode(name)) &&
hasChildNode(name);
+    }
+
+    @Override
+    public boolean isRemoved() {
+        return this != root && (parent.isRemoved() || parent.isRemoved(name));
+    }
+
+    private boolean isRemoved(String name) {
+        return getBaseState() != null && getBaseState().hasChildNode(name) &&
!hasChildNode(name);
+    }
+
+    @Override
+    public boolean isModified() {
+        if (writeState == null) {
+            return false;
+        }
+        else {
+            for (Entry<String, MutableNodeState> n : writeState.nodes.entrySet()) {
+                if (n.getValue() == null) {
+                    return true;
+                }
+                if (!getBaseState().hasChildNode(n.getKey())) {
+                    return true;
+                }
+            }
+            for (Entry<String, PropertyState> p : writeState.properties.entrySet())
{
+                PropertyState pState = p.getValue();
+                if (pState == null) {
+                    return true;
+                }
+                if (!pState.equals(getBaseState().getProperty(p.getKey()))) {
+                    return true;
+                }
+            }
+            return false;
+        }
+    }
+
+    @Override
     public NodeState getNodeState() {
         read();
         if (writeState != null) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java?rev=1407001&r1=1407000&r2=1407001&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java
Thu Nov  8 10:35:06 2012
@@ -46,6 +46,12 @@ public interface NodeBuilder {
     @CheckForNull
     NodeState getBaseState();
 
+    boolean isNew();
+
+    boolean isRemoved();
+
+    boolean isModified();
+
     /**
      * Replaces the base state of this builder and throws away all changes.
      * The effect of this method is equivalent to replacing this builder

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java?rev=1407001&r1=1407000&r2=1407001&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java
Thu Nov  8 10:35:06 2012
@@ -38,6 +38,21 @@ public class ReadOnlyBuilder implements 
     }
 
     @Override
+    public boolean isNew() {
+        return false;
+    }
+
+    @Override
+    public boolean isRemoved() {
+        return false;
+    }
+
+    @Override
+    public boolean isModified() {
+        return false;
+    }
+
+    @Override
     public NodeState getNodeState() {
         return state;
     }



Mime
View raw message