svn commit: r480741 - in /incubator/ofbiz/trunk/framework: entity/src/org/ofbiz/entity/transaction/TransactionUtil.java service/src/org/ofbiz/service/ServiceDispatcher.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r480741 - in /incubator/ofbiz/trunk/framework: entity/src/org/ofbiz/entity/transaction/TransactionUtil.java service/src/org/ofbiz/service/ServiceDispatcher.java

jonesde
Author: jonesde
Date: Wed Nov 29 14:24:55 2006
New Revision: 480741

URL: http://svn.apache.org/viewvc?view=rev&rev=480741
Log:
Some improvements on error handling and message passing especially for failed commits when rollbackOnly is set; based on patch from Si Chen, but quite a bit different; from Jira #OFBIZ-503

Modified:
    incubator/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java
    incubator/ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java

Modified: incubator/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java?view=diff&rev=480741&r1=480740&r2=480741
==============================================================================
--- incubator/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java (original)
+++ incubator/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java Wed Nov 29 14:24:55 2006
@@ -186,18 +186,29 @@
                     Debug.logInfo("[TransactionUtil.commit] Not committing transaction, status is STATUS_NO_TRANSACTION", module);
                 }
             } catch (RollbackException e) {
-                if (Debug.infoOn()) Thread.dumpStack();
-                //This is Java 1.4 only, but useful for certain debuggins: Throwable t = e.getCause() == null ? e : e.getCause();
-                throw new GenericTransactionException("Roll back error, could not commit transaction, was rolled back instead", e);
+                RollbackOnlyCause rollbackOnlyCause = getSetRollbackOnlyCause();
+
+                if (rollbackOnlyCause != null) {
+                    // the transaction is now definitely over, so clear stuff as normal now that we have the info from it that we want
+                    clearTransactionStamps();
+                    clearTransactionBeginStack();
+                    clearSetRollbackOnlyCause();
+                    
+                    Debug.logError(e, "Rollback Only was set when trying to commit transaction here; throwing rollbackOnly cause exception", module);
+                    throw new GenericTransactionException("Roll back error, could not commit transaction, was rolled back instead because of: " + rollbackOnlyCause.getCauseMessage(), rollbackOnlyCause.getCauseThrowable());
+                } else {
+                    Throwable t = e.getCause() == null ? e : e.getCause();
+                    throw new GenericTransactionException("Roll back error (with no rollbackOnly cause found), could not commit transaction, was rolled back instead: " + t.toString(), t);
+                }
             } catch (HeuristicMixedException e) {
-                //This is Java 1.4 only, but useful for certain debuggins: Throwable t = e.getCause() == null ? e : e.getCause();
-                throw new GenericTransactionException("Could not commit transaction, HeuristicMixed exception", e);
+                Throwable t = e.getCause() == null ? e : e.getCause();
+                throw new GenericTransactionException("Could not commit transaction, HeuristicMixed exception: " + t.toString(), t);
             } catch (HeuristicRollbackException e) {
-                //This is Java 1.4 only, but useful for certain debuggins: Throwable t = e.getCause() == null ? e : e.getCause();
-                throw new GenericTransactionException("Could not commit transaction, HeuristicRollback exception", e);
+                Throwable t = e.getCause() == null ? e : e.getCause();
+                throw new GenericTransactionException("Could not commit transaction, HeuristicRollback exception: " + t.toString(), t);
             } catch (SystemException e) {
-                //This is Java 1.4 only, but useful for certain debuggins: Throwable t = e.getCause() == null ? e : e.getCause();
-                throw new GenericTransactionException("System error, could not commit transaction", e);
+                Throwable t = e.getCause() == null ? e : e.getCause();
+                throw new GenericTransactionException("System error, could not commit transaction: " + t.toString(), t);
             }
         } else {
             Debug.logInfo("[TransactionUtil.commit] UserTransaction is null, not commiting", module);
@@ -268,7 +279,7 @@
 
                 if (status != STATUS_NO_TRANSACTION) {
                     if (status != STATUS_MARKED_ROLLBACK) {
-                        if (Debug.warningOn()) Debug.logWarning(new Exception(), "[TransactionUtil.setRollbackOnly] Calling transaction setRollbackOnly; this stack trace shows where this is happening:", module);
+                        if (Debug.warningOn()) Debug.logWarning(new Exception(causeMessage), "[TransactionUtil.setRollbackOnly] Calling transaction setRollbackOnly; this stack trace shows where this is happening:", module);
                         ut.setRollbackOnly();
                         setSetRollbackOnlyCause(causeMessage, causeThrowable);
                     } else {
@@ -620,8 +631,8 @@
     }
     public static RollbackOnlyCause getSetRollbackOnlyCause() {
         if (setRollbackOnlyCause.get() == null) {
-            Exception e2 = new Exception("Current Stack Trace");
-            Debug.logWarning("WARNING: In getSetRollbackOnlyCause no stack placeholder was in place, here is the current location: ", module);
+            Exception e = new Exception("Current Stack Trace");
+            Debug.logWarning(e, "WARNING: In getSetRollbackOnlyCause no stack placeholder was in place, here is the current location: ", module);
         }
         return (RollbackOnlyCause) setRollbackOnlyCause.get();
     }

Modified: incubator/ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java?view=diff&rev=480741&r1=480740&r2=480741
==============================================================================
--- incubator/ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java (original)
+++ incubator/ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java Wed Nov 29 14:24:55 2006
@@ -409,15 +409,19 @@
                     try {
                         TransactionUtil.rollback(beganTrans, errMsg, null);
                     } catch (GenericTransactionException e) {
-                        Debug.logError(e, "Could not rollback transaction", module);
+                        Debug.logError(e, "Could not rollback transaction: " + e.toString(), module);
                     }
                 } else {
                     // commit the transaction
                     try {
                         TransactionUtil.commit(beganTrans);
                     } catch (GenericTransactionException e) {
-                        Debug.logError(e, "Could not commit transaction", module);
-                        throw new GenericServiceException("Commit transaction failed");
+                        String errMsg = "Could not commit transaction for service [" + modelService.name + "] call";
+                        Debug.logError(e, errMsg, module);
+                        if (e.getMessage() != null) {
+                            errMsg = errMsg + ": " + e.getMessage();
+                        }
+                        throw new GenericServiceException(errMsg);
                     }
                 }
             }