jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1309300 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel: KernelNodeStateEditor.java TransientNodeState.java
Date Wed, 04 Apr 2012 09:35:55 GMT
Author: mduerig
Date: Wed Apr  4 09:35:54 2012
New Revision: 1309300

URL: http://svn.apache.org/viewvc?rev=1309300&view=rev
Log:
OAK-9: Internal tree builder
Make TransientNodeState not inherit from NodeState

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateEditor.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/TransientNodeState.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateEditor.java?rev=1309300&r1=1309299&r2=1309300&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateEditor.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateEditor.java
Wed Apr  4 09:35:54 2012
@@ -48,14 +48,6 @@ public class KernelNodeStateEditor imple
         jsop = new StringBuilder();
     }
 
-    private KernelNodeStateEditor(KernelNodeStateEditor parentEditor,
-            NodeState state, String name) {
-
-        base = parentEditor.base;
-        transientState = new TransientNodeState(state, this, parentEditor.getNodeState(),
name);
-        jsop = parentEditor.jsop;
-    }
-
     KernelNodeStateEditor(KernelNodeStateEditor parentEditor, TransientNodeState state) {
         base = parentEditor.base;
         transientState = state;
@@ -131,21 +123,16 @@ public class KernelNodeStateEditor imple
 
     @Override
     public KernelNodeStateEditor edit(String name) {
-        NodeState childState = transientState.getChildNode(name);
-        if (childState == null) {
-            return null;
-        }
-        else if (childState instanceof TransientNodeState) {
-            return ((TransientNodeState) childState).getEditor();
-        }
-        else {
-            return new KernelNodeStateEditor(this, childState, name);
-        }
+        TransientNodeState childState = transientState.getChildNode(name);
+        return childState == null
+            ? null
+            : childState.getEditor();
     }
 
     @Override
-    public TransientNodeState getNodeState() {
-        return transientState;
+    public NodeState getNodeState() {
+        // todo implement getNodeState
+        return null;
     }
 
     @Override
@@ -162,16 +149,19 @@ public class KernelNodeStateEditor imple
         return new KernelNodeState(microkernel, targetPath, rev);
     }
 
+    TransientNodeState getTransientState() {
+        return transientState;
+    }
+
     private TransientNodeState getTransientState(String path) {
-        KernelNodeStateEditor editor = this;
-        for(String name : PathUtils.elements(path)) {
-            editor = editor.edit(name);
-            if (editor == null) {
+        TransientNodeState state = transientState;
+        for (String name : PathUtils.elements(path)) {
+            state = state.getChildNode(name);
+            if (state == null) {
                 return null;
             }
         }
-        
-        return editor.transientState;
+        return state;
     }
 
     private String path(String name) {
@@ -179,8 +169,8 @@ public class KernelNodeStateEditor imple
         return path.isEmpty() ? name : path + '/' + name;
     }
 
-    private static boolean hasNode(NodeState nodeState, String name) {
-        return nodeState.getChildNode(name) != null;
+    private static boolean hasNode(TransientNodeState state, String name) {
+        return state.getChildNode(name) != null;
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/TransientNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/TransientNodeState.java?rev=1309300&r1=1309299&r2=1309300&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/TransientNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/TransientNodeState.java
Wed Apr  4 09:35:54 2012
@@ -1,7 +1,5 @@
 package org.apache.jackrabbit.oak.kernel;
 
-import org.apache.jackrabbit.mk.model.AbstractChildNodeEntry;
-import org.apache.jackrabbit.mk.model.AbstractNodeState;
 import org.apache.jackrabbit.mk.model.ChildNodeEntry;
 import org.apache.jackrabbit.mk.model.NodeState;
 import org.apache.jackrabbit.mk.model.PropertyState;
@@ -14,13 +12,14 @@ import java.util.Map.Entry;
 import java.util.NoSuchElementException;
 import java.util.Set;
 
-// fixme: this should be immutable as mandated by the NodeState interface
-public class TransientNodeState extends AbstractNodeState {
+public class TransientNodeState {
     private final KernelNodeStateEditor editor;
     private final NodeState persistentState;
 
-    private final Map<String, TransientNodeState>
-            addedNodes = new HashMap<String, TransientNodeState>();
+    private final Map<NodeState, TransientNodeState> existingChildNodes =
+            new HashMap<NodeState, TransientNodeState>();
+    private final Map<String, TransientNodeState> addedNodes =
+            new HashMap<String, TransientNodeState>();
     private final Set<String> removedNodes = new HashSet<String>();
     private final Map<String, PropertyState> addedProperties = new HashMap<String,
PropertyState>();
     private final Set<String> removedProperties = new HashSet<String>();
@@ -38,9 +37,15 @@ public class TransientNodeState extends 
     }
 
     private TransientNodeState(KernelNodeStateEditor parentEditor, String name) {
+        this(parentEditor, name, null);
+    }
+    
+    private TransientNodeState(KernelNodeStateEditor parentEditor, String name,
+            NodeState persistedState) {
+
         editor = new KernelNodeStateEditor(parentEditor, this);
-        persistentState = null;
-        parent = parentEditor.getNodeState();
+        this.persistentState = persistedState;
+        parent = parentEditor.getTransientState();
         this.name = name;
     }
 
@@ -63,7 +68,6 @@ public class TransientNodeState extends 
         this.removedProperties.addAll(state.removedProperties);
     }
 
-    @Override
     public PropertyState getProperty(String name) {
         PropertyState state = addedProperties.get(name);
         if (state != null) {
@@ -75,36 +79,18 @@ public class TransientNodeState extends 
             : persistentState.getProperty(name);
     }
 
-    @Override
-    public long getPropertyCount() {
-        // todo optimise getPropertyCount
-        // persistentCount - removedCount + addedCount won't work however since
-        // persisted properties might be overlaid
-        return super.getPropertyCount();
-    }
-
-    @Override
-    public NodeState getChildNode(String name) {
-        NodeState state = addedNodes.get(name);
+    public TransientNodeState getChildNode(String name) {
+        TransientNodeState state = addedNodes.get(name);
         if (state != null) {
             return state;
         }
 
         return removedNodes.contains(name)
             ? null
-            : persistentState.getChildNode(name);
-    }
-
-    @Override
-    public long getChildNodeCount() {
-        // todo optimise getChildNodeCount
-        // persistentCount - removedCount + addedCount won't work however since
-        // persisted nodes might be overlaid
-        return super.getChildNodeCount();
+            : getExistingChildNode(name);
     }
 
-    @Override
-    public Iterable<? extends PropertyState> getProperties() {
+    public Iterable<PropertyState> getProperties() {
         final Set<String> removed = new HashSet<String>();
         removed.addAll(removedProperties);
 
@@ -159,46 +145,35 @@ public class TransientNodeState extends 
         };
     }
 
-    @Override
-    public Iterable<? extends ChildNodeEntry> getChildNodeEntries(long offset, int
count) {
+    public Iterable<TransientNodeState> getChildNodes(long offset, int count) {
         final Set<String> removed = new HashSet<String>();
         removed.addAll(removedNodes);
 
-        final Map<String, NodeState> added = new HashMap<String, NodeState>();
+        final Map<String, TransientNodeState> added = new HashMap<String, TransientNodeState>();
         added.putAll(addedNodes);
 
         final Iterable<? extends ChildNodeEntry>
-                baseNodes = persistentState.getChildNodeEntries(offset, count);
+                persistedNodes = persistentState.getChildNodeEntries(offset, count);
 
-        return new Iterable<ChildNodeEntry>() {
+        return new Iterable<TransientNodeState>() {
             @Override
-            public Iterator<ChildNodeEntry> iterator() {
-                return new Iterator<ChildNodeEntry>() {
+            public Iterator<TransientNodeState> iterator() {
+                return new Iterator<TransientNodeState>() {
                     private final Iterator<? extends ChildNodeEntry>
-                            properties = baseNodes.iterator();
-                    private ChildNodeEntry next;
+                            nodes = persistedNodes.iterator();
+                    private TransientNodeState next;
 
                     @Override
                     public boolean hasNext() {
                         if (next == null) {
-                            while (properties.hasNext()) {
-                                final ChildNodeEntry entry = properties.next();
+                            while (nodes.hasNext()) {
+                                final ChildNodeEntry entry = nodes.next();
                                 if (added.containsKey(entry.getName())) {
-                                    next = new AbstractChildNodeEntry() {
-                                        @Override
-                                        public String getName() {
-                                            return entry.getName();
-                                        }
-
-                                        @Override
-                                        public NodeState getNode() {
-                                            return added.get(entry.getName());
-                                        }
-                                    };
+                                    next = added.get(entry.getName());
                                     break;
                                 }
                                 if (!removed.contains(entry.getName())) {
-                                    next = entry;
+                                    next = getExistingChildNode(entry.getName());
                                     break;
                                 }
                             }
@@ -207,11 +182,11 @@ public class TransientNodeState extends 
                     }
 
                     @Override
-                    public ChildNodeEntry next() {
+                    public TransientNodeState next() {
                         if (!hasNext()) {
                             throw new NoSuchElementException();
                         }
-                        ChildNodeEntry e = next;
+                        TransientNodeState e = next;
                         next = null;
                         return e;
                     }
@@ -262,7 +237,7 @@ public class TransientNodeState extends 
     }
 
     void move(String name, TransientNodeState destParent, String destName) {
-        TransientNodeState state = editor.edit(name).getNodeState();
+        TransientNodeState state = getChildNode(name);
         removeNode(name);
 
         state.name = destName;
@@ -271,9 +246,19 @@ public class TransientNodeState extends 
     }
 
     void copy(String name, TransientNodeState destParent, String destName) {
-        TransientNodeState state = editor.edit(name).getNodeState();
         destParent.addedNodes.put(destName,
-                new TransientNodeState(state, destParent, destName));
+                new TransientNodeState(getChildNode(name), destParent, destName));
+    }
+
+    private TransientNodeState getExistingChildNode(String name) {
+        NodeState state = persistentState.getChildNode(name);
+
+        TransientNodeState transientState = existingChildNodes.get(state);
+        if (transientState == null) {
+            transientState = new TransientNodeState(editor, name, state);
+            existingChildNodes.put(state, transientState);
+        }
+        return transientState;
     }
 
 }



Mime
View raw message