jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1215155 - /jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntry.java
Date Fri, 16 Dec 2011 14:32:43 GMT
Author: mduerig
Date: Fri Dec 16 14:32:43 2011
New Revision: 1215155

URL: http://svn.apache.org/viewvc?rev=1215155&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP)
batch loading of child nodes

Modified:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntry.java

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntry.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntry.java?rev=1215155&r1=1215154&r2=1215155&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntry.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/NodeEntry.java
Fri Dec 16 14:32:43 2011
@@ -418,8 +418,8 @@ public class NodeEntry extends Hierarchy
 
                 // -> check for moved child entry in node-attic
                 // -> check if child points to a removed/moved sns
-                List<NodeEntry> siblings = Collections.singletonList(entry.childNodeEntries.get(name));
-                if (entry.containsAtticChild(siblings, name, index)) {
+                NodeEntry sibling = entry.childNodeEntries.get(name);
+                if (entry.containsAtticChild(sibling, name, index)) {
                     throw new PathNotFoundException(factory.saveGetJCRPath(path));
                 }
 
@@ -501,8 +501,8 @@ public class NodeEntry extends Hierarchy
                 }
                 // -> check for moved child entry in node-attic
                 // -> check if child points to a removed/moved sns
-                List<NodeEntry> siblings = Collections.singletonList(entry.childNodeEntries.get(name));
-                if (entry.containsAtticChild(siblings, name, index)) {
+                NodeEntry sibling = entry.childNodeEntries.get(name);
+                if (entry.containsAtticChild(sibling, name, index)) {
                     throw new PathNotFoundException(factory.saveGetJCRPath(path));
                 }
                 // break out of the loop and start deep loading the property
@@ -616,7 +616,7 @@ public class NodeEntry extends Hierarchy
         try {
             return getNodeEntry(nodeName, index) != null;
         } catch (RepositoryException e) {
-            log.debug("Unable to determine if a child node with name " + nodeName + " exists.");
+            log.error("Unable to determine if a child node with name " + nodeName + " exists.",
e);
             return false;
         }
     }
@@ -650,29 +650,26 @@ public class NodeEntry extends Hierarchy
      * @throws RepositoryException If an unexpected error occurs.
      */
     public NodeEntry getNodeEntry(Name nodeName, int index, boolean loadIfNotFound) throws
RepositoryException {
-        List<NodeEntry> entries = Collections.singletonList(childNodeEntries.get(nodeName));
+        if (index > Path.INDEX_DEFAULT) {
+            UnsupportedRepositoryOperationException e = new UnsupportedRepositoryOperationException(
+                    "Invalid index: " + index);
+            log.error(e.getMessage(), e);
+            throw e;
+        }
+
+        NodeEntry entry = childNodeEntries.get(nodeName);
         NodeEntry cne = null;
-        if (entries.size() >= index) {
-            // position of entry might differ from index-1 if a SNS with lower
-            // index has been transiently removed.
-            int eIndex = 1;
-            for (int i = 0; i < entries.size() && cne == null; i++) {
-                NodeEntry ne = entries.get(i);
-                if (EntryValidation.isValidNodeEntry(ne)) {
-                    if (eIndex == index) {
-                        cne = ne;
-                    }
-                    eIndex++;
-                }
+        if (EntryValidation.isValidNodeEntry(entry)) {
+            if (Path.INDEX_DEFAULT == index) {
+                cne = entry;
             }
         }
 
         if (cne == null && loadIfNotFound
-                && !containsAtticChild(entries, nodeName, index)
+                && !containsAtticChild(entry, nodeName, index)
                 && !childNodeEntries.isComplete()) {
 
-            NodeId cId = getIdFactory().createNodeId(getWorkspaceId(),
-                    getPathFactory().create(nodeName, index));
+            NodeId cId = getIdFactory().createNodeId(getWorkspaceId(), getPathFactory().create(nodeName,
index));
             cne = loadNodeEntry(cId);
         }
         return cne;
@@ -1264,37 +1261,27 @@ public class NodeEntry extends Hierarchy
      * been modified in a way that its original index is equal to the given
      * child index.
      *
-     * @param siblings
+     * @param sibling
      * @param childName
      * @param childIndex
      * @return {@code true} if there is a child entry in the attic that
      * matches the given name/index or if the siblings list contain a reordered
      * entry that matches.
      */
-    private boolean containsAtticChild(List<NodeEntry> siblings, Name childName, int
childIndex) {
-        // check if a matching entry exists in the attic
-        if (childNodeAttic.contains(childName)) {
-            return true;
-        }
-        // special treatment for potentially moved/reordered/removed sns
-        // TODO: check again
+    private boolean containsAtticChild(NodeEntry sibling, Name childName, int childIndex)
+            throws UnsupportedRepositoryOperationException {
+
         if (childIndex > Path.INDEX_DEFAULT) {
-            NodeEntry siblingsInAttic = childNodeAttic.get(childName);
-            if (siblings.size() < childIndex && childIndex <= siblings.size()
+ (siblingsInAttic == null ? 0 : 1)) {
-                return true;
-            }
-        }
-        if (getStatus() == Status.EXISTING_MODIFIED) {
-            for (NodeEntry child : siblings) {
-                if (!EntryValidation.isValidNodeEntry(child) ||
-                        child.revertInfo != null &&
-                                Path.INDEX_DEFAULT == childIndex) {
-                    
-                    return true;
-                }
-            }
+            UnsupportedRepositoryOperationException e = new UnsupportedRepositoryOperationException(
+                    "Invalid index: " + childIndex);
+            log.error(e.getMessage(), e);
+            throw e;
         }
-        return false;
+
+        return childNodeAttic.contains(childName) ||
+            getStatus() == Status.EXISTING_MODIFIED &&
+                (!EntryValidation.isValidNodeEntry(sibling) ||
+                        sibling.revertInfo != null && Path.INDEX_DEFAULT == childIndex);
     }
 
     /**



Mime
View raw message