jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r208759 - in /incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core: ItemImpl.java state/SessionItemStateManager.java
Date Fri, 01 Jul 2005 13:56:40 GMT
Author: stefan
Date: Fri Jul  1 06:56:39 2005
New Revision: 208759

URL: http://svn.apache.org/viewcvs?rev=208759&view=rev
Log:
optimized performance of Item.save() 

Modified:
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/ItemImpl.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/SessionItemStateManager.java

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/ItemImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/ItemImpl.java?rev=208759&r1=208758&r2=208759&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/ItemImpl.java (original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/ItemImpl.java Fri
Jul  1 06:56:39 2005
@@ -349,6 +349,14 @@
                         throw new InvalidItemStateException(msg);
                     }
 
+                case ItemState.STATUS_UNDEFINED:
+                    {
+                        String msg = safeGetJCRPath()
+                                + ": the item cannot be saved; it seems to have been removed
externally.";
+                        log.debug(msg);
+                        throw new InvalidItemStateException(msg);
+                    }
+
                 default:
                     log.debug("unexpected state status (" + state.getStatus() + ")");
                     // ignore
@@ -357,7 +365,7 @@
         }
 
         if (isNode()) {
-            // build list of 'new' or 'modified' descendents
+            // build list of 'new' or 'modified' descendants
             Iterator iter = stateMgr.getDescendantTransientItemStates((NodeId) id);
             while (iter.hasNext()) {
                 transientState = (ItemState) iter.next();
@@ -384,6 +392,14 @@
                             throw new InvalidItemStateException(msg);
                         }
 
+                    case ItemState.STATUS_UNDEFINED:
+                        {
+                            String msg = safeGetJCRPath()
+                                    + ": the item cannot be saved; it seems to have been
removed externally.";
+                            log.debug(msg);
+                            throw new InvalidItemStateException(msg);
+                        }
+
                     default:
                         log.debug("unexpected state status (" + transientState.getStatus()
+ ")");
                         // ignore
@@ -1174,7 +1190,7 @@
             }
 
             /**
-             * build list of transient descendents in the attic
+             * build list of transient descendants in the attic
              * (i.e. those marked as 'removed')
              */
             Collection removed = getRemovedStates();
@@ -1401,7 +1417,7 @@
         }
 
         if (isNode()) {
-            // build list of 'new', 'modified' or 'stale' descendents
+            // build list of 'new', 'modified' or 'stale' descendants
             Iterator iter = stateMgr.getDescendantTransientItemStates((NodeId) id);
             while (iter.hasNext()) {
                 transientState = (ItemState) iter.next();
@@ -1433,7 +1449,7 @@
         }
 
         if (isNode()) {
-            // discard all transient descendents in the attic (i.e. those marked
+            // discard all transient descendants in the attic (i.e. those marked
             // as 'removed'); this will resurrect the removed items
             iter = stateMgr.getDescendantTransientItemStatesInAttic((NodeId) id);
             while (iter.hasNext()) {

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/SessionItemStateManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/SessionItemStateManager.java?rev=208759&r1=208758&r2=208759&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/SessionItemStateManager.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/state/SessionItemStateManager.java
Fri Jul  1 06:56:39 2005
@@ -316,7 +316,8 @@
         if (!transientStateMgr.hasAnyItemStates()) {
             return Collections.EMPTY_LIST.iterator();
         }
-        // collection of descendant transient states:
+/*
+        // build ordered collection of descendant transient states:
         // the path serves as key and sort criteria
         TreeMap descendants = new TreeMap(new PathComparator());
 
@@ -362,7 +363,7 @@
         /**
          * walk through list of transient states and check if
          * they are descendants of the specified parent
-         */
+         * /
         try {
             Iterator iter = transientStateMgr.getEntries();
             while (iter.hasNext()) {
@@ -380,7 +381,7 @@
                      * a descendant is affected;
                      * => throw InvalidItemStateException for now
                      * todo FIXME
-                     */
+                     * /
                     // unable to build path, assume that it (or any of
                     // its ancestors) has been removed externally
                     String msg = id
@@ -401,6 +402,71 @@
         }
 
         return descendants.values().iterator();
+*/
+        // build ordered collection of descendant transient states
+        // sorted by decreasing relative depth
+
+        // use an array of lists to group the descendants by relative depth;
+        // the depth is used as array index
+        List[] la = new List[10];
+        try {
+            Iterator iter = transientStateMgr.getEntries();
+            while (iter.hasNext()) {
+                ItemState state = (ItemState) iter.next();
+                // determine relative depth: > 0 means it's a descendant
+                int depth;
+                try {
+                    depth = hierMgr.getRelativeDepth(parentId, state.getId());
+                } catch (ItemNotFoundException infe) {
+                    /**
+                     * one of the parents of the specified item has been
+                     * removed externally; as we don't know its path,
+                     * we can't determine if it is a descendant;
+                     * InvalidItemStateException should only be thrown if
+                     * a descendant is affected;
+                     * => throw InvalidItemStateException for now
+                     * todo FIXME
+                     */
+                    // unable to determine relative depth, assume that the item
+                    // (or any of its ancestors) has been removed externally
+                    String msg = state.getId()
+                            + ": the item seems to have been removed externally.";
+                    log.debug(msg);
+                    throw new InvalidItemStateException(msg);
+                }
+
+                if (depth < 1) {
+                    // not a descendant
+                    continue;
+                }
+
+                // ensure capacity
+                if (depth > la.length) {
+                    List old[] = la;
+                    la = new List[depth + 10];
+                    System.arraycopy(old, 0, la, 0, old.length);
+                }
+
+                List list = la[depth - 1];
+                if (list == null) {
+                    list = new ArrayList();
+                    la[depth - 1] = list;
+                }
+                list.add(state);
+            }
+        } catch (RepositoryException re) {
+            log.warn("inconsistent hierarchy state", re);
+        }
+        // create an iterator over the collected descendants
+        // in decreasing depth order
+        IteratorChain resultIter = new IteratorChain();
+        for (int i = la.length - 1; i >= 0; i--) {
+            List list = la[i];
+            if (list != null) {
+                resultIter.addIterator(list.iterator());
+            }
+        }
+        return resultIter;
     }
 
     /**
@@ -500,7 +566,6 @@
             }
         }
         return resultIter;
-
     }
 
     //------< methods for creating & discarding transient ItemState instances >



Mime
View raw message