svn commit: r570759 - /lenya/trunk/src/java/org/apache/lenya/transaction/UnitOfWorkImpl.java

[email protected]
Newsgroups gmane.comp.cms.lenya.cvs
Message-ID <[email protected]>
Author: andreas
Date: Wed Aug 29 04:32:05 2007
New Revision: 570759

URL: http://svn.apache.org/viewvc?rev=570759&view=rev
Log:
Move check-in of nodes to finally block to avoid stale checked-in nodes (see bug 43163)

Modified:
    lenya/trunk/src/java/org/apache/lenya/transaction/UnitOfWorkImpl.java

Modified: lenya/trunk/src/java/org/apache/lenya/transaction/UnitOfWorkImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/transaction/UnitOfWorkImpl.java?rev=570759&r1=570758&r2=570759&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/transaction/UnitOfWorkImpl.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/transaction/UnitOfWorkImpl.java Wed Aug 29 04:32:05 2007
@@ -112,38 +112,41 @@
         involvedObjects.addAll(this.modifiedObjects);
         involvedObjects.addAll(this.removedObjects);
 
-        for (Iterator i = involvedObjects.iterator(); i.hasNext();) {
-            Transactionable t = (Transactionable) i.next();
-            t.checkout();
-        }
-
-        for (Iterator i = this.newObjects.iterator(); i.hasNext();) {
-            Transactionable t = (Transactionable) i.next();
-            t.createTransactionable();
-            t.saveTransactionable();
-        }
-        for (Iterator i = this.modifiedObjects.iterator(); i.hasNext();) {
-            Transactionable t = (Transactionable) i.next();
-            if (getLogger().isDebugEnabled()) {
-                getLogger().debug("UnitOfWorkImpl::commit() calling save on [" + t + "]");
+        try {
+            for (Iterator i = involvedObjects.iterator(); i.hasNext();) {
+                Transactionable t = (Transactionable) i.next();
+                t.checkout();
             }
-            t.saveTransactionable();
-        }
-        for (Iterator i = this.removedObjects.iterator(); i.hasNext();) {
-            Transactionable t = (Transactionable) i.next();
-            t.deleteTransactionable();
-        }
 
-        if (getIdentityMap() != null) {
-            Object[] objects = getIdentityMap().getObjects();
-            for (int i = 0; i < objects.length; i++) {
-                if (objects[i] instanceof Transactionable) {
-                    Transactionable t = (Transactionable) objects[i];
-                    if (t.isCheckedOutBySession() && !this.removedObjects.contains(t)) {
-                        t.checkin();
-                    }
-                    if (t.isLocked()) {
-                        t.unlock();
+            for (Iterator i = this.newObjects.iterator(); i.hasNext();) {
+                Transactionable t = (Transactionable) i.next();
+                t.createTransactionable();
+                t.saveTransactionable();
+            }
+            for (Iterator i = this.modifiedObjects.iterator(); i.hasNext();) {
+                Transactionable t = (Transactionable) i.next();
+                if (getLogger().isDebugEnabled()) {
+                    getLogger().debug("UnitOfWorkImpl::commit() calling save on [" + t + "]");
+                }
+                t.saveTransactionable();
+            }
+            for (Iterator i = this.removedObjects.iterator(); i.hasNext();) {
+                Transactionable t = (Transactionable) i.next();
+                t.deleteTransactionable();
+            }
+    
+        } finally {
+            if (getIdentityMap() != null) {
+                Object[] objects = getIdentityMap().getObjects();
+                for (int i = 0; i < objects.length; i++) {
+                    if (objects[i] instanceof Transactionable) {
+                        Transactionable t = (Transactionable) objects[i];
+                        if (t.isCheckedOutBySession() && !this.removedObjects.contains(t)) {
+                            t.checkin();
+                        }
+                        if (t.isLocked()) {
+                            t.unlock();
+                        }
                     }
                 }
             }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.