jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1527616 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment: SegmentNodeState.java Template.java
Date Mon, 30 Sep 2013 15:50:09 GMT
Author: jukka
Date: Mon Sep 30 15:50:08 2013
New Revision: 1527616

URL: http://svn.apache.org/r1527616
Log:
OAK-1031: SegmentMK: Fewer segment lookups

Move functionality from Template to SegmentNodeState to better leverage the Record base class

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java?rev=1527616&r1=1527615&r2=1527616&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeState.java
Mon Sep 30 15:50:08 2013
@@ -19,11 +19,15 @@ package org.apache.jackrabbit.oak.plugin
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
+import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.MISSING_NODE;
+
+import java.util.Collections;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 
 import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryChildNodeEntry;
 import org.apache.jackrabbit.oak.spi.state.AbstractNodeState;
 import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
@@ -65,7 +69,8 @@ public class SegmentNodeState extends Re
     }
 
     MapRecord getChildNodeMap() {
-        return getTemplate().getChildNodeMap(getSegment(), getRecordId());
+        Segment segment = getSegment();
+        return segment.readMap(segment.readRecordId(getOffset(0, 1)));
     }
 
     @Override
@@ -122,29 +127,78 @@ public class SegmentNodeState extends Re
 
     @Override
     public long getChildNodeCount(long max) {
-        return getTemplate().getChildNodeCount(getSegment(), getRecordId());
+        String childName = getTemplate().getChildName();
+        if (childName == Template.ZERO_CHILD_NODES) {
+            return 0;
+        } else if (childName == Template.MANY_CHILD_NODES) {
+            return getChildNodeMap().size();
+        } else {
+            return 1;
+        }
     }
 
     @Override
     public boolean hasChildNode(String name) {
         checkArgument(!checkNotNull(name).isEmpty());
-        return getTemplate().hasChildNode(name, getSegment(), getRecordId());
+        String childName = getTemplate().getChildName();
+        if (childName == Template.ZERO_CHILD_NODES) {
+            return false;
+        } else if (childName == Template.MANY_CHILD_NODES) {
+            return getChildNodeMap().getEntry(name) != null;
+        } else {
+            return childName.equals(name);
+        }
     }
 
-    @Override @CheckForNull
+    @Override @Nonnull
     public NodeState getChildNode(String name) {
         // checkArgument(!checkNotNull(name).isEmpty()); // TODO
-        return getTemplate().getChildNode(name, getSegment(), getRecordId());
+        String childName = getTemplate().getChildName();
+        if (childName == Template.ZERO_CHILD_NODES) {
+            return MISSING_NODE;
+        } else if (childName == Template.MANY_CHILD_NODES) {
+            RecordId childNodeId = getChildNodeMap().getEntry(name);
+            if (childNodeId != null) {
+                return new SegmentNodeState(getSegment(), childNodeId);
+            } else {
+                return MISSING_NODE;
+            }
+        } else {
+            if (childName.equals(name)) {
+                Segment segment = getSegment();
+                RecordId childNodeId = segment.readRecordId(getOffset(0, 1));
+                return new SegmentNodeState(segment, childNodeId);
+            } else {
+                return MISSING_NODE;
+            }
+        }
     }
 
-    @Override
+    @Override @Nonnull
     public Iterable<String> getChildNodeNames() {
-        return getTemplate().getChildNodeNames(getSegment(), getRecordId());
+        String childName = getTemplate().getChildName();
+        if (childName == Template.ZERO_CHILD_NODES) {
+            return Collections.emptyList();
+        } else if (childName == Template.MANY_CHILD_NODES) {
+            return getChildNodeMap().getKeys();
+        } else {
+            return Collections.singletonList(childName);
+        }
     }
 
     @Override @Nonnull
     public Iterable<? extends ChildNodeEntry> getChildNodeEntries() {
-        return getTemplate().getChildNodeEntries(getSegment(), getRecordId());
+        String childName = getTemplate().getChildName();
+        if (childName == Template.ZERO_CHILD_NODES) {
+            return Collections.emptyList();
+        } else if (childName == Template.MANY_CHILD_NODES) {
+            return getChildNodeMap().getEntries();
+        } else {
+            Segment segment = getSegment();
+            RecordId childNodeId = segment.readRecordId(getOffset(0, 1));
+            return Collections.singletonList(new MemoryChildNodeEntry(
+                    childName, new SegmentNodeState(segment, childNodeId)));
+        }
     }
 
     @Override @Nonnull

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java?rev=1527616&r1=1527615&r2=1527616&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java
Mon Sep 30 15:50:08 2013
@@ -160,12 +160,8 @@ public class Template {
         return childName == MANY_CHILD_NODES;
     }
 
-    public String getChildName() {
-        if (hasOneChildNode()) {
-            return childName;
-        } else {
-            return null;
-        }
+    String getChildName() {
+        return childName;
     }
 
     public int getPropertyCount() {
@@ -263,17 +259,6 @@ public class Template {
         return list;
     }
 
-    public long getChildNodeCount(Segment segment, RecordId recordId) {
-        if (hasNoChildNodes()) {
-            return 0;
-        } else if (hasManyChildNodes()) {
-            MapRecord map = getChildNodeMap(segment, recordId);
-            return map.size();
-        } else {
-            return 1;
-        }
-    }
-
     MapRecord getChildNodeMap(Segment segment, RecordId recordId) {
         checkState(hasManyChildNodes());
         segment = segment.getSegment(recordId);
@@ -282,18 +267,6 @@ public class Template {
         return segment.readMap(childNodesId);
     }
 
-    public boolean hasChildNode(
-            String name, Segment segment, RecordId recordId) {
-        if (hasNoChildNodes()) {
-            return false;
-        } else if (hasManyChildNodes()) {
-            MapRecord map = getChildNodeMap(segment, recordId);
-            return map.getEntry(name) != null;
-        } else {
-            return name.equals(childName);
-        }
-    }
-
     public NodeState getChildNode(
             String name, Segment segment, RecordId recordId) {
         if (hasNoChildNodes()) {
@@ -316,17 +289,6 @@ public class Template {
         }
     }
 
-    Iterable<String> getChildNodeNames(Segment segment, RecordId recordId) {
-        if (hasNoChildNodes()) {
-            return Collections.emptyList();
-        } else if (hasManyChildNodes()) {
-            MapRecord map = getChildNodeMap(segment, recordId);
-            return map.getKeys();
-        } else {
-            return Collections.singletonList(childName);
-        }
-    }
-
     Iterable<? extends ChildNodeEntry> getChildNodeEntries(
             Segment segment, RecordId recordId) {
         if (hasNoChildNodes()) {



Mime
View raw message