jackrabbit-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?rev=1215135&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP)
remove expensive index calculation

Modified:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/ChildNodeAttic.java
    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/ChildNodeAttic.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/ChildNodeAttic.java?rev=1215135&r1=1215134&r2=1215135&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/ChildNodeAttic.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/ChildNodeAttic.java
Fri Dec 16 14:09:02 2011
@@ -20,10 +20,7 @@ import org.apache.jackrabbit.spi.Name;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Set;
 
 /**
@@ -38,18 +35,18 @@ class ChildNodeAttic {
         return attic.isEmpty();
     }
 
-    boolean contains(Name name, int index) {
+    boolean contains(Name name) {
         for (NodeEntry ne : attic) {
-            if (ne.matches(name, index)) {
+            if (ne.matches(name)) {
                 return true;
             }
         }
         return false;
     }
 
-    boolean contains(Name name, int index, String uniqueId) {
+    boolean contains(Name name, String uniqueId) {
         for (NodeEntry ne : attic) {
-            if (uniqueId != null && uniqueId.equals(ne.getUniqueID()) || ne.matches(name,
index)) {
+            if (uniqueId != null && uniqueId.equals(ne.getUniqueID()) || ne.matches(name))
{
                 return true;
             }
         }
@@ -57,30 +54,13 @@ class ChildNodeAttic {
         return false;
     }
 
-    List<NodeEntry> get(Name name) {
-        if (attic.isEmpty()) {
-            // shortcut
-            return Collections.emptyList();
-        }
-        
-        List<NodeEntry> l = new ArrayList<NodeEntry>();
-        for (NodeEntry ne : attic) {
-            if (ne.matches(name)) {
-                l.add(ne);
-            }
-        }
-        return l;
-    }
-
     /**
-     *
      * @param name The original name of the NodeEntry before it has been moved.
-     * @param index The original index of the NodeEntry before it has been moved.
      * @return
      */
-    NodeEntry get(Name name, int index) {
+    NodeEntry get(Name name) {
         for (NodeEntry ne : attic) {
-            if (ne.matches(name, index)) {
+            if (ne.matches(name)) {
                 return ne;
             }
         }

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=1215135&r1=1215134&r2=1215135&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:09:02 2011
@@ -49,7 +49,6 @@ import org.apache.jackrabbit.spi.commons
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.jcr.InvalidItemStateException;
 import javax.jcr.ItemExistsException;
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.PathNotFoundException;
@@ -316,7 +315,7 @@ public class NodeEntry extends Hierarchy
 
         PathBuilder pathBuilder = new PathBuilder(pathFactory);
         while (entry.getParent() != null && entry.getUniqueID() == null) {
-            pathBuilder.addFirst(entry.getName(wspId), entry.getIndex(wspId));
+            pathBuilder.addFirst(entry.getName(wspId), Path.INDEX_DEFAULT);
             entry = wspId && entry.revertInfo != null
                 ? entry.revertInfo.oldParent
                 : entry.parent;
@@ -363,7 +362,7 @@ public class NodeEntry extends Hierarchy
      * @throws RepositoryException
      */
     public int getIndex() throws RepositoryException {
-        return getIndex(false);
+        return Path.INDEX_DEFAULT;
     }
 
     /**
@@ -568,10 +567,17 @@ public class NodeEntry extends Hierarchy
             }
 
             int index = elem.getNormalizedIndex();
+            if (index > Path.INDEX_DEFAULT) {
+                UnsupportedRepositoryOperationException e = new UnsupportedRepositoryOperationException(
+                        "Invalid index: " + index);
+                log.error(e.getMessage(), e);
+                throw e;
+            }
+
             Name childName = elem.getName();
 
             // first try to resolve node
-            NodeEntry cne = entry.lookupNodeEntry(null, childName, index);
+            NodeEntry cne = entry.lookupNodeEntry(null, childName);
             if (cne != null) {
                 entry = cne;
             } else if (index == Path.INDEX_DEFAULT && i == workspacePath.getLength()
- 1) {
@@ -723,12 +729,17 @@ public class NodeEntry extends Hierarchy
      * @param uniqueID
      * @return the {@code NodeEntry}.
      */
-    public NodeEntry getOrAddNodeEntry(Name nodeName, int index, String uniqueID)
-            throws RepositoryException {
+    public NodeEntry getOrAddNodeEntry(Name nodeName, int index, String uniqueID) throws
RepositoryException {
+        if (index > Path.INDEX_DEFAULT) {
+            UnsupportedRepositoryOperationException e = new UnsupportedRepositoryOperationException(
+                    "Invalid index: " + index);
+            log.error(e.getMessage(), e);
+            throw e;
+        }
 
-        NodeEntry ne = lookupNodeEntry(uniqueID, nodeName, index);
+        NodeEntry ne = lookupNodeEntry(uniqueID, nodeName);
         if (ne == null) {
-            ne = internalAddNodeEntry(nodeName, uniqueID, index);
+            ne = internalAddNodeEntry(nodeName, uniqueID);
         } else {
             log.debug("Child NodeEntry already exists -> didn't add.");
         }
@@ -746,8 +757,8 @@ public class NodeEntry extends Hierarchy
      */
     public NodeEntry addNewNodeEntry(Name nodeName, String uniqueID, Name primaryNodeType,
QNodeDefinition definition)
             throws RepositoryException {
-        
-        NodeEntry entry = internalAddNodeEntry(nodeName, uniqueID, Path.INDEX_UNDEFINED);
+
+        NodeEntry entry = internalAddNodeEntry(nodeName, uniqueID);
         NodeState state = getItemStateFactory().createNewNodeState(entry, primaryNodeType,
definition);
         entry.setItemState(state);
         return entry;
@@ -1023,9 +1034,8 @@ public class NodeEntry extends Hierarchy
         // recursively build path of parent
         buildPath(builder, parentEntry, wspPath);
 
-        int index = nEntry.getIndex(wspPath);
         Name name = nEntry.getName(wspPath);
-        builder.addLast(name, index);
+        builder.addLast(name, Path.INDEX_DEFAULT);
     }
 
     //-----------------------------------------------< private || protected >---
@@ -1037,16 +1047,9 @@ public class NodeEntry extends Hierarchy
     /**
      * @param nodeName
      * @param uniqueID
-     * @param index
      * @return the added entry.
      */
-    private NodeEntry internalAddNodeEntry(Name nodeName, String uniqueID, int index) throws
RepositoryException {
-        if (index > Path.INDEX_DEFAULT) {
-            IllegalArgumentException e = new IllegalArgumentException("Invalid index: " +
index);
-            log.error(e.getMessage(), e);
-            throw e;
-        }
-
+    private NodeEntry internalAddNodeEntry(Name nodeName, String uniqueID) throws RepositoryException
{
         NodeEntry entry = factory.createNodeEntry(this, nodeName, uniqueID);
         childNodeEntries.add(entry);
         return entry;
@@ -1112,21 +1115,6 @@ public class NodeEntry extends Hierarchy
 
     /**
      * @param oldName
-     * @param oldIndex
-     * @return {@code true} if the given oldName and oldIndex match
-     * {@link #getName(boolean)} and {@link #getIndex(boolean)}, respectively.
-     */
-    boolean matches(Name oldName, int oldIndex) {
-        try {
-            return getName(true).equals(oldName) && getIndex(true) == oldIndex;
-        } catch (RepositoryException e) {
-            // should not get here
-            return false;
-        }
-    }
-
-    /**
-     * @param oldName
      * @return {@code true} if the given oldName matches
      * {@link #getName(boolean)}.
      */
@@ -1143,24 +1131,6 @@ public class NodeEntry extends Hierarchy
         }
     }
 
-    private int getIndex(boolean wspIndex) throws RepositoryException {
-        if (parent == null) {
-            // the root state may never have siblings
-            return Path.INDEX_DEFAULT;
-        }
-
-        if (wspIndex && revertInfo != null) {
-            return revertInfo.oldIndex;
-        } else {
-            NodeState state = getItemState();
-            if (state == null || !state.hasDefinition() || state.getDefinition().allowsSameNameSiblings())
{
-                return parent.getChildIndex(this, wspIndex);
-            } else {
-                return Path.INDEX_DEFAULT;
-            }
-        }
-    }
-
     /**
      *
      * @param childId
@@ -1192,13 +1162,7 @@ public class NodeEntry extends Hierarchy
         }
     }
 
-    private NodeEntry lookupNodeEntry(String uniqueChildId, Name childName, int index) throws
RepositoryException {
-        if (index > Path.INDEX_DEFAULT) {
-            IllegalArgumentException e = new IllegalArgumentException("Invalid index: " +
index);
-            log.error(e.getMessage(), e);
-            throw e;
-        }
-
+    private NodeEntry lookupNodeEntry(String uniqueChildId, Name childName) throws RepositoryException
{
         NodeEntry child = null;
         if (uniqueChildId != null) {
             child = childNodeAttic.get(uniqueChildId);
@@ -1207,7 +1171,7 @@ public class NodeEntry extends Hierarchy
             }
         }
         if (child == null) {
-            child = childNodeAttic.get(childName, index);
+            child = childNodeAttic.get(childName);
             if (child == null && childNodeEntries != null) {
                 child = childNodeEntries.get(childName);
             }
@@ -1295,65 +1259,6 @@ public class NodeEntry extends Hierarchy
     }
 
     /**
-     * Returns the index of the given {@code NodeEntry}.
-     *
-     * @param cne  the {@code NodeEntry} instance.
-     * @param wspIndex if {@code true} transiently removed siblings are respected.
-     * @return the index of the child node entry.
-     * @throws ItemNotFoundException if the given entry isn't a valid child of
-     * this {@code NodeEntry}.
-     */
-    private int getChildIndex(NodeEntry cne, boolean wspIndex) throws RepositoryException
{
-        List<NodeEntry> sns = new ArrayList<NodeEntry>();
-        sns.add(childNodeEntries.get(cne.getName()));
-
-        if (wspIndex) {
-            List<NodeEntry> atticSiblings = childNodeAttic.get(cne.getName());
-            for (NodeEntry s : atticSiblings) {
-                if (s.revertInfo != null) {
-                    sns.add(s.revertInfo.oldIndex - 1, s);
-                } else {
-                    log.error("Sibling in attic doesn't have revertInfo....");
-                }
-            }
-        }
-
-        if (sns.isEmpty()) {
-            // the given node entry is not connected with his parent any more
-            // -> throw
-            String msg = "NodeEntry " + cne.getName() + " is disconnected from its parent
-> remove.";
-            cne.remove();
-            throw new InvalidItemStateException(msg);
-
-        } else if (sns.size() == 1) {
-            // no siblings -> simply return the default index.
-            return Path.INDEX_DEFAULT;
-
-        } else {
-            // siblings exist.
-            int index = Path.INDEX_DEFAULT;
-            for (NodeEntry entry : sns) {
-                if (entry == cne) { // TODO see below
-                    return index;
-                }
-                // for wsp index ignore all transiently added items.
-                // otherwise: skip entries that belong to removed or invalid states.
-                // NOTE, that in this case the node state must be available from the cne.
-                boolean isValid = wspIndex ?
-                        EntryValidation.isValidWorkspaceNodeEntry(entry) :
-                        EntryValidation.isValidNodeEntry(entry);
-                if (isValid) {
-                    index++;
-                }
-            }
-            // not found, since child entries are only connected with soft refs
-            // to the LinkNode in ChildNodeEntries, equality may not determine
-            // the correct matching entry -> return default index.
-            return Path.INDEX_DEFAULT;
-        }
-    }
-
-    /**
      * Returns {@code true} if the attic contains a matching child entry or
      * if any of the remaining child entries present in the siblings list has
      * been modified in a way that its original index is equal to the given
@@ -1368,14 +1273,14 @@ public class NodeEntry extends Hierarchy
      */
     private boolean containsAtticChild(List<NodeEntry> siblings, Name childName, int
childIndex) {
         // check if a matching entry exists in the attic
-        if (childNodeAttic.contains(childName, childIndex)) {
+        if (childNodeAttic.contains(childName)) {
             return true;
         }
         // special treatment for potentially moved/reordered/removed sns
         // TODO: check again
         if (childIndex > Path.INDEX_DEFAULT) {
-            List<NodeEntry> siblingsInAttic = childNodeAttic.get(childName);
-            if (siblings.size() < childIndex && childIndex <= siblings.size()
+ siblingsInAttic.size()) {
+            NodeEntry siblingsInAttic = childNodeAttic.get(childName);
+            if (siblings.size() < childIndex && childIndex <= siblings.size()
+ (siblingsInAttic == null ? 0 : 1)) {
                 return true;
             }
         }
@@ -1383,7 +1288,7 @@ public class NodeEntry extends Hierarchy
             for (NodeEntry child : siblings) {
                 if (!EntryValidation.isValidNodeEntry(child) ||
                         child.revertInfo != null &&
-                                child.revertInfo.oldIndex == childIndex) {
+                                Path.INDEX_DEFAULT == childIndex) {
                     
                     return true;
                 }
@@ -1396,7 +1301,7 @@ public class NodeEntry extends Hierarchy
      * If 'revertInfo' is null it gets created from the current information
      * present on this entry.
      */
-    private void createRevertInfo() throws RepositoryException {
+    private void createRevertInfo() {
         if (revertInfo == null && getStatus() != Status.NEW) {
             revertInfo = new RevertInfo();
         }
@@ -1555,14 +1460,14 @@ public class NodeEntry extends Hierarchy
         switch (operation.getStatus()) {
             case PERSISTED:
                 if (revertInfo != null && !revertInfo.isMoved()) {
-                    revertInfo.dispose(true);
+                    revertInfo.dispose();
                 }
                 break;
             case UNDO:
                 if (he.getStatus() == Status.NEW) {
                     he.revert();
                 } else if (revertInfo != null && !revertInfo.isMoved()) {
-                    revertInfo.dispose(false);
+                    revertInfo.dispose();
                 }
                 break;
             case PENDING:
@@ -1582,7 +1487,7 @@ public class NodeEntry extends Hierarchy
             case PERSISTED:
                 if (getStatus() != Status.NEW && revertInfo != null) {
                     revertInfo.oldParent.childNodeAttic.remove(this);
-                    revertInfo.dispose(true);
+                    revertInfo.dispose();
                 }
                 // and mark the moved state existing
                 // getItemState().setStatus(Status.EXISTING);
@@ -1592,7 +1497,7 @@ public class NodeEntry extends Hierarchy
                     revert();
                 } else if (revertInfo != null) {
                     revertMove();
-                    revertInfo.dispose(false);
+                    revertInfo.dispose();
                 }
                 break;
             case PENDING:
@@ -1643,33 +1548,19 @@ public class NodeEntry extends Hierarchy
      * to build the workspace id / path.
      */
     private class RevertInfo {
-
         private final NodeEntry oldParent;
         private final Name oldName;
-        private final int oldIndex;
 
-        private RevertInfo() throws RepositoryException {
+        private RevertInfo() {
             oldParent = parent;
             oldName = name;
-            oldIndex = getIndex();
         }
 
         private boolean isMoved() {
             return oldParent != getParent() || !getName().equals(oldName);
         }
 
-        private void dispose(boolean persisted) {
-            if (!persisted) {
-                NodeEntry ne = NodeEntry.this;
-                try {
-                    if (oldIndex != ne.getIndex()) {
-                        // TODO: fix
-                        log.warn("Reverting didn't restore the correct index.");
-                    }
-                } catch (RepositoryException e) {
-                    log.warn("Unable to calculate index.", e.getMessage());
-                }
-            }
+        private void dispose() {
             revertInfo = null;
         }
     }



Mime
View raw message