jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r433610 - in /jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state: ChangeLog.java SessionItemStateManager.java TransientItemStateManager.java
Date Tue, 22 Aug 2006 12:23:42 GMT
Author: mreutegg
Date: Tue Aug 22 05:23:42 2006
New Revision: 433610

URL: http://svn.apache.org/viewvc?rev=433610&view=rev
Log:
- Remove AtticItemStateManager (not needed anymore)
- Remove dispose methods from TransientItemStateManager. TransientItemStateManager is a listener
on all modified ItemStates and maintains its ChangeLog according to the callbacks.
- Move method SessionItemStateManager.checkIsSelfContained() to ChangeLog.

Modified:
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java?rev=433610&r1=433609&r2=433610&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChangeLog.java
Tue Aug 22 05:23:42 2006
@@ -17,10 +17,12 @@
 package org.apache.jackrabbit.jcr2spi.state;
 
 import org.apache.jackrabbit.jcr2spi.operation.Operation;
+import org.apache.commons.collections.iterators.IteratorChain;
 
 import java.util.Iterator;
 import java.util.Set;
 import java.util.LinkedHashSet;
+import java.util.HashSet;
 
 /**
  * Registers changes made to states and references and consolidates
@@ -161,6 +163,71 @@
      */
     public Iterator modifiedRefs() {
         return modifiedRefs.iterator();
+    }
+
+    /**
+     * Make sure that this ChangeLog is totally 'self-contained'
+     * and independant; items within the scope of this update operation
+     * must not have 'external' dependencies;
+     * (e.g. moving a node requires that the target node including both
+     * old and new parents are saved)
+     */
+    public void checkIsSelfContained()
+            throws ItemStateException {
+        Set affectedStates = new HashSet();
+        affectedStates.addAll(modifiedStates);
+        affectedStates.addAll(deletedStates);
+        Iterator it = new IteratorChain(modifiedStates(), deletedStates());
+        while (it.hasNext()) {
+            ItemState transientState = (ItemState) it.next();
+            if (transientState.isNode()) {
+                NodeState nodeState = (NodeState) transientState;
+                Set dependentStates = new HashSet();
+                if (nodeState.hasOverlayedState()) {
+                    // TODO: oldParentState is overlayed state from workspace. do not use!
+                    NodeState oldParentState = nodeState.getOverlayedState().getParent();
+                    NodeState newParentState = nodeState.getParent();
+                    if (oldParentState != null) {
+                        if (newParentState == null) {
+                            // node has been removed, add old parent
+                            // to dependencies
+                            dependentStates.add(oldParentState);
+                        } else {
+                            if (!oldParentState.equals(newParentState)) {
+                                // node has been moved, add old and new parent
+                                // to dependencies
+                                dependentStates.add(oldParentState);
+                                dependentStates.add(newParentState);
+                            }
+                        }
+                    }
+                }
+                // removed child node entries
+                Iterator cneIt = nodeState.getRemovedChildNodeEntries().iterator();
+                while (cneIt.hasNext()) {
+                    ChildNodeEntry cne = (ChildNodeEntry) cneIt.next();
+                    dependentStates.add(cne.getNodeState());
+                }
+                // added child node entries
+                cneIt = nodeState.getAddedChildNodeEntries().iterator();
+                while (cneIt.hasNext()) {
+                    ChildNodeEntry cne = (ChildNodeEntry) cneIt.next();
+                    dependentStates.add(cne.getNodeState());
+                }
+
+                // now walk through dependencies and check whether they
+                // are within the scope of this save operation
+                Iterator depIt = dependentStates.iterator();
+                while (depIt.hasNext()) {
+                    NodeState dependantState = (NodeState) depIt.next();
+                    if (!affectedStates.contains(dependantState)) {
+                        // need to save the parent as well
+                        String msg = dependantState.getNodeId().toString() + " needs to be
saved as well.";
+                        throw new ItemStateException(msg);
+                    }
+                }
+            }
+        }
     }
 
     //-----------------------------< Inform ChangeLog about Success/Failure >---

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java?rev=433610&r1=433609&r2=433610&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
Tue Aug 22 05:23:42 2006
@@ -265,25 +265,6 @@
             workspaceItemStateMgr.execute(changeLog);
         }
 
-        // dispose the transient states marked 'new' or 'modified'
-        Iterator it = new IteratorChain(changeLog.addedStates(), changeLog.modifiedStates());
-        while (it.hasNext()) {
-            ItemState transientState = (ItemState) it.next();
-            // dispose the transient state, it is no longer used
-            transientStateMgr.disposeItemState(transientState);
-        }
-
-        // dispose the transient states marked 'removed'.
-        // item states in attic are removed after store, because
-        // the observation mechanism needs to build paths of removed
-        // items in update().
-        it = changeLog.deletedStates();
-        while (it.hasNext()) {
-            ItemState transientState = (ItemState) it.next();
-            // dispose the transient state, it is no longer used
-            transientStateMgr.disposeItemStateInAttic(transientState);
-        }
-
         // remove operations just processed
         transientStateMgr.disposeOperations(changeLog.getOperations());
     }
@@ -299,12 +280,15 @@
      *                            to be canceled as well in another sub-tree.
      */
     public void undo(ItemState itemState) throws ItemStateException {
-        // TODO: check if self contained
+        // check if self contained
+        ChangeLog changeLog = new ChangeLog();
+        collectTransientStates(itemState, changeLog, false);
+        changeLog.checkIsSelfContained();
 
+        // now do it for real
         Set affectedItemStates = new HashSet();
         itemState.revert(affectedItemStates);
 
-        ChangeLog changeLog = new ChangeLog();
         collectOperations(affectedItemStates, changeLog);
 
         // remove all canceled operations
@@ -358,10 +342,10 @@
         ChangeLog changeLog = new ChangeLog();
 
         // build changelog for affected and decendant states only
-        collectTransientStates(itemState, changeLog);
+        collectTransientStates(itemState, changeLog, true);
 
         /**
-         * build set of item id's which are within the scope of
+         * build set of item states which are within the scope of
          * (i.e. affected by) this save operation
          */
         Iterator it = new IteratorChain(changeLog.modifiedStates(), changeLog.deletedStates());
@@ -370,7 +354,7 @@
             affectedStates.add(it.next());
         }
 
-        checkIsSelfContained(affectedStates, changeLog);
+        changeLog.checkIsSelfContained();
         collectOperations(affectedStates, changeLog);
 
         return changeLog;
@@ -391,7 +375,7 @@
      *                                 if such an exception is thrown.
      * @throws ItemStateException if <code>state</code> is a new item state.
      */
-    private void collectTransientStates(ItemState state, ChangeLog changeLog)
+    private void collectTransientStates(ItemState state, ChangeLog changeLog, boolean throwOnStale)
             throws StaleItemStateException, ItemStateException {
         // fail-fast test: check status of this item's state
         if (state.isTransient()) {
@@ -402,24 +386,28 @@
                         log.debug(msg);
                         throw new ItemStateException(msg);
                     }
-                case ItemState.STATUS_STALE_MODIFIED:
-                    {
-                        String msg = LogUtil.safeGetJCRPath(state, nsResolver, hierMgr) +
": the item cannot be saved because it has been modified externally.";
-                        log.debug(msg);
-                        throw new StaleItemStateException(msg);
-                    }
-                case ItemState.STATUS_STALE_DESTROYED:
-                    {
-                        String msg = LogUtil.safeGetJCRPath(state, nsResolver, hierMgr) +
": the item cannot be saved because it has been deleted externally.";
-                        log.debug(msg);
-                        throw new StaleItemStateException(msg);
-                    }
-                case ItemState.STATUS_UNDEFINED:
-                    {
-                        String msg = LogUtil.safeGetJCRPath(state, nsResolver, hierMgr) +
": the item cannot be saved; it seems to have been removed externally.";
-                        log.debug(msg);
-                        throw new StaleItemStateException(msg);
-                    }
+            }
+            if (throwOnStale) {
+                switch (state.getStatus()) {
+                    case ItemState.STATUS_STALE_MODIFIED:
+                        {
+                            String msg = LogUtil.safeGetJCRPath(state, nsResolver, hierMgr)
+ ": the item cannot be saved because it has been modified externally.";
+                            log.debug(msg);
+                            throw new StaleItemStateException(msg);
+                        }
+                    case ItemState.STATUS_STALE_DESTROYED:
+                        {
+                            String msg = LogUtil.safeGetJCRPath(state, nsResolver, hierMgr)
+ ": the item cannot be saved because it has been deleted externally.";
+                            log.debug(msg);
+                            throw new StaleItemStateException(msg);
+                        }
+                    case ItemState.STATUS_UNDEFINED:
+                        {
+                            String msg = LogUtil.safeGetJCRPath(state, nsResolver, hierMgr)
+ ": the item cannot be saved; it seems to have been removed externally.";
+                            log.debug(msg);
+                            throw new StaleItemStateException(msg);
+                        }
+                }
             }
         }
 
@@ -441,19 +429,21 @@
                     changeLog.deleted(transientState);
                     break;
                 case ItemState.STATUS_STALE_MODIFIED:
-                    {
+                    if (throwOnStale) {
                         String msg = transientState.getId() + ": the item cannot be saved
because it has been modified externally.";
                         log.debug(msg);
                         throw new StaleItemStateException(msg);
+                    } else {
+                        changeLog.modified(transientState);
                     }
                 case ItemState.STATUS_STALE_DESTROYED:
-                    {
+                    if (throwOnStale) {
                         String msg = transientState.getId() + ": the item cannot be saved
because it has been deleted externally.";
                         log.debug(msg);
                         throw new StaleItemStateException(msg);
                     }
                 case ItemState.STATUS_UNDEFINED:
-                    {
+                    if (throwOnStale) {
                         String msg = transientState.getId() + ": the item cannot be saved;
it seems to have been removed externally.";
                         log.debug(msg);
                         throw new StaleItemStateException(msg);
@@ -488,71 +478,8 @@
         }
     }
 
-    /**
-     * Make sure that this save operation is totally 'self-contained'
-     * and independant; items within the scope of this update operation
-     * must not have 'external' dependencies;
-     * (e.g. moving a node requires that the target node including both
-     * old and new parents are saved)
-     *
-     * @param affectedStates
-     * @param changeLog
-     */
-    private void checkIsSelfContained(Set affectedStates, ChangeLog changeLog) throws ItemStateException
{
-        Iterator it = new IteratorChain(changeLog.modifiedStates(), changeLog.deletedStates());
-        while (it.hasNext()) {
-            ItemState transientState = (ItemState) it.next();
-            if (transientState.isNode()) {
-                NodeState nodeState = (NodeState) transientState;
-                Set dependentStates = new HashSet();
-                if (nodeState.hasOverlayedState()) {
-                    NodeState oldParentState = nodeState.getOverlayedState().getParent();
-                    NodeState newParentState = nodeState.getParent();
-                    if (oldParentState != null) {
-                        if (newParentState == null) {
-                            // node has been removed, add old parent
-                            // to dependencies
-                            dependentStates.add(oldParentState);
-                        } else {
-                            if (!oldParentState.equals(newParentState)) {
-                                // node has been moved, add old and new parent
-                                // to dependencies
-                                dependentStates.add(oldParentState);
-                                dependentStates.add(newParentState);
-                            }
-                        }
-                    }
-                }
-                // removed child node entries
-                Iterator cneIt = nodeState.getRemovedChildNodeEntries().iterator();
-                while (cneIt.hasNext()) {
-                    ChildNodeEntry cne = (ChildNodeEntry) cneIt.next();
-                    dependentStates.add(cne.getNodeState());
-                }
-                // added child node entries
-                cneIt = nodeState.getAddedChildNodeEntries().iterator();
-                while (cneIt.hasNext()) {
-                    ChildNodeEntry cne = (ChildNodeEntry) cneIt.next();
-                    dependentStates.add(cne.getNodeState());
-                }
-
-                // now walk through dependencies and check whether they
-                // are within the scope of this save operation
-                Iterator depIt = dependentStates.iterator();
-                while (depIt.hasNext()) {
-                    NodeState dependantState = (NodeState) depIt.next();
-                    if (!affectedStates.contains(dependantState)) {
-                        // need to save the parent as well
-                        String msg = LogUtil.safeGetJCRPath(dependantState, nsResolver, hierMgr)
+ " needs to be saved as well.";
-                        log.debug(msg);
-                        throw new ItemStateException(msg);
-                    }
-                }
-            }
-        }
-    }
-
     //--------------------------------------------------------------------------
+
     /**
      * @inheritDoc
      */

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java?rev=433610&r1=433609&r2=433610&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java
Tue Aug 22 05:23:42 2006
@@ -40,8 +40,8 @@
  * still valid. This item state manager also provides methods to create new
  * item states. While all other modifications can be invoked on the item state
  * instances itself, creating a new node state is done using
- * {@link #createNewNodeState(QName,String,QName,NodeState)} and
- * {@link #createNewPropertyState(NodeState, QName)}.
+ * {@link #createNewNodeState(QName, String, QName, QNodeDefinition, NodeState)}
+ * and {@link #createNewPropertyState(QName, NodeState, QPropertyDefinition)}.
  */
 public class TransientItemStateManager extends CachingItemStateManager
         implements ItemStateLifeCycleListener {
@@ -70,12 +70,6 @@
     private final TransientISFactory isf;
 
     /**
-     * ItemStateManager view of the states in the attic; lazily instantiated
-     * in {@link #getAttic()}
-     */
-    private AtticItemStateManager attic;
-
-    /**
      * The root node state or <code>null</code> if it hasn't been retrieved yet.
      */
     private NodeState rootNodeState;
@@ -258,35 +252,6 @@
     }
 
     /**
-     * Disposes a single item <code>state</code>. The state is discarded removed
-     * from the map of added or modified states and disconnected from the
-     * underlying state. This method does not take states into account that are
-     * marked as deleted.
-     *
-     * @param state the item state to dispose.
-     */
-    public void disposeItemState(ItemState state) {
-        state.discard();
-        if (changeLog.addedStates.remove(state)) {
-            changeLog.modifiedStates.remove(state);
-        }
-        state.onDisposed();
-    }
-
-    /**
-     * Disposes a single item <code>state</code> that is marked as deleted. The
-     * state is discarded removed from the map of removed states and
-     * disconnected from the underlying state.
-     *
-     * @param state the item state to dispose.
-     */
-    public void disposeItemStateInAttic(ItemState state) {
-        state.discard();
-        changeLog.deletedStates.remove(state);
-        state.onDisposed();
-    }
-
-    /**
      * Disposes all transient item states in the cache and in the attic.
      */
     public void disposeAllItemStates() {
@@ -303,19 +268,6 @@
     }
 
     /**
-     * Return the attic item state provider that holds all items
-     * moved into the attic.
-     *
-     * @return attic
-     */
-    public ItemStateManager getAttic() {
-        if (attic == null) {
-            attic = new AtticItemStateManager();
-        }
-        return attic;
-    }
-
-    /**
      * Disposes a collection of {@link org.apache.jackrabbit.jcr2spi.operation.Operation}s.
      *
      * @param operations the operations.
@@ -450,93 +402,6 @@
                 break;
             default:
                 log.warn("ItemState has invalid status: " + state.getStatus());
-        }
-    }
-
-    //--------------------------------------------------------< inner classes >
-
-    /**
-     * ItemStateManager view of the states in the attic
-     *
-     * @see TransientItemStateManager#getAttic()
-     */
-    private class AtticItemStateManager implements ItemStateManager {
-
-        AtticItemStateManager() {
-        }
-
-        /**
-         * Since the root node may never be removed, this method always returns
-         * <code>null</code>.
-         *
-         * @return <code>null</code> since the root node cannot be removed.
-         * @throws ItemStateException
-         * @see ItemStateManager#getRootState()
-         */
-        public NodeState getRootState() throws ItemStateException {
-            return null;
-        }
-
-        /**
-         * {@inheritDoc}
-         */
-        public ItemState getItemState(ItemId id)
-                throws NoSuchItemStateException, ItemStateException {
-
-            // TODO: too expensive. rather lookup item and check state
-            ItemState state = null;
-            for (Iterator it = changeLog.deletedStates(); it.hasNext(); ) {
-                ItemState s = (ItemState) it.next();
-                if (s.getId().equals(id)) {
-                    state = s;
-                }
-            }
-            if (state != null) {
-                return state;
-            } else {
-                throw new NoSuchItemStateException(id.toString());
-            }
-        }
-
-        /**
-         * {@inheritDoc}
-         */
-        public boolean hasItemState(ItemId id) {
-            // TODO: too expensive. rather lookup item and check state
-            for (Iterator it = changeLog.deletedStates(); it.hasNext(); ) {
-                ItemState s = (ItemState) it.next();
-                if (s.getId().equals(id)) {
-                    return true;
-                }
-            }
-            return false;
-        }
-
-        /**
-         * Always throws <code>UnsupportedOperationException</code>. Within the
-         * transient space node references cannot be managed.
-         *
-         * @param nodeState
-         * @throws UnsupportedOperationException
-         * @see ItemStateManager#getReferingStates(NodeState)
-         */
-        public Collection getReferingStates(NodeState nodeState)
-                throws NoSuchItemStateException, ItemStateException {
-            // n/a
-            throw new UnsupportedOperationException("getNodeReferences() not implemented");
-        }
-
-        /**
-         * Always throws <code>UnsupportedOperationException</code>. Within the
-         * transient space node references cannot be managed.
-         *
-         * @param nodeState
-         * @throws UnsupportedOperationException
-         * @see ItemStateManager#hasReferingStates(NodeState)
-         */
-        public boolean hasReferingStates(NodeState nodeState) {
-            // n/a
-            throw new UnsupportedOperationException("getNodeReferences() not implemented");
         }
     }
 



Mime
View raw message