jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpfis...@apache.org
Subject svn commit: r160150 - in incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state: ChangeLog.java LocalItemStateManager.java SharedItemStateManager.java
Date Tue, 05 Apr 2005 09:58:52 GMT
Author: dpfister
Date: Tue Apr  5 02:58:51 2005
New Revision: 160150

URL: http://svn.apache.org/viewcvs?view=rev&rev=160150
Log:
Added guard to disconnect item states from their overlaid shared state
in case of some failure. 

Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/ChangeLog.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/ChangeLog.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/ChangeLog.java?view=diff&r1=160149&r2=160150
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/ChangeLog.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/ChangeLog.java Tue
Apr  5 02:58:51 2005
@@ -238,6 +238,25 @@
     }
 
     /**
+     * Disconnect all states in the change log from their overlaid
+     * states.
+     */
+    public void disconnect() {
+        Iterator iter = modifiedStates();
+        while (iter.hasNext()) {
+            ((ItemState) iter.next()).disconnect();
+        }
+        iter = deletedStates();
+        while (iter.hasNext()) {
+            ((ItemState) iter.next()).disconnect();
+        }
+        iter = addedStates();
+        while (iter.hasNext()) {
+            ((ItemState) iter.next()).disconnect();
+        }
+    }
+
+    /**
      * Undo changes made to items in the change log. Discards
      * added items, refreshes modified and resurrects deleted
      * items.

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java?view=diff&r1=160149&r2=160150
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/LocalItemStateManager.java
Tue Apr  5 02:58:51 2005
@@ -318,9 +318,12 @@
     protected void update(ChangeLog changeLog)
             throws ItemStateException {
 
+        ObservationManagerImpl obsMgr = null;
+
         try {
-            sharedStateMgr.store(changeLog,
-                    (wspImpl != null) ? (ObservationManagerImpl) wspImpl.getObservationManager()
: null);
+            if (wspImpl != null) {
+                obsMgr = (ObservationManagerImpl) wspImpl.getObservationManager();
+            }
         } catch (RepositoryException e) {
             // should never get here
             String msg = "ObservationManager unavailable";
@@ -328,6 +331,7 @@
             throw new ItemStateException(msg, e);
         }
 
+        sharedStateMgr.store(changeLog, obsMgr);
         changeLog.persisted();
     }
 

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java?view=diff&r1=160149&r2=160150
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
Tue Apr  5 02:58:51 2005
@@ -448,43 +448,58 @@
             }
         }
 
-        /**
-         * Reconnect all items contained in the change log to their
-         * respective shared item and add the shared items to a
-         * new change log.
-         */
-        iter = local.modifiedStates();
-        while (iter.hasNext()) {
-            ItemState state = (ItemState) iter.next();
-            state.connect(getItemState(state.getId()));
-            shared.modified(state.getOverlayedState());
-        }
-        iter = local.deletedStates();
-        while (iter.hasNext()) {
-            ItemState state = (ItemState) iter.next();
-            state.connect(getItemState(state.getId()));
-            shared.deleted(state.getOverlayedState());
-        }
-        iter = local.addedStates();
-        while (iter.hasNext()) {
-            ItemState state = (ItemState) iter.next();
-            state.connect(createInstance(state));
-            shared.added(state.getOverlayedState());
-        }
-
-        /* prepare the events */
         EventStateCollection events = null;
-        if (obsMgr != null) {
-            events = obsMgr.createEventStateCollection();
-            events.createEventStates(root.getUUID(), local, this);
-            events.prepare();
-        }
+        boolean succeeded = false;
 
-        /* Push all changes from the local items to the shared items */
-        local.push();
+        try {
+            /**
+             * Reconnect all items contained in the change log to their
+             * respective shared item and add the shared items to a
+             * new change log.
+             */
+            iter = local.modifiedStates();
+            while (iter.hasNext()) {
+                ItemState state = (ItemState) iter.next();
+                state.connect(getItemState(state.getId()));
+                shared.modified(state.getOverlayedState());
+            }
+            iter = local.deletedStates();
+            while (iter.hasNext()) {
+                ItemState state = (ItemState) iter.next();
+                state.connect(getItemState(state.getId()));
+                shared.deleted(state.getOverlayedState());
+            }
+            iter = local.addedStates();
+            while (iter.hasNext()) {
+                ItemState state = (ItemState) iter.next();
+                state.connect(createInstance(state));
+                shared.added(state.getOverlayedState());
+            }
 
-        /* Store items in the underlying persistence manager */
-        persistMgr.store(shared);
+            /* prepare the events */
+            if (obsMgr != null) {
+                events = obsMgr.createEventStateCollection();
+                events.createEventStates(root.getUUID(), local, this);
+                events.prepare();
+            }
+
+            /* Push all changes from the local items to the shared items */
+            local.push();
+
+            /* Store items in the underlying persistence manager */
+            persistMgr.store(shared);
+            succeeded = true;
+
+        } finally {
+
+            /**
+             * If some store operation was unsuccessful, we have to restore
+             * the original state of all items in the local change log.
+             */
+            if (!succeeded) {
+                local.disconnect();
+            }
+        }
 
         /* Let the shared item listeners know about the change */
         shared.persisted();



Mime
View raw message