Author: doogie
Date: Wed Sep 16 18:06:54 2009
New Revision: 815914
URL: http://svn.apache.org/viewvc?rev=815914&view=rev
Log:
Move this code to TransactionUtil.
Modified:
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java
ofbiz/trunk/framework/webslinger/src/org/ofbiz/webslinger/EntityTransactionUtil.java
Modified:
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java?rev=815914&r1=815913&r2=815914&view=diff
==============================================================================
---
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java
(original)
+++
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java
Wed Sep 16 18:06:54 2009
@@ -26,6 +26,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.Callable;
import javax.sql.XAConnection;
import javax.transaction.HeuristicMixedException;
@@ -72,6 +73,54 @@
private static ThreadLocal<Timestamp> transactionStartStamp = new
ThreadLocal<Timestamp>();
private static ThreadLocal<Timestamp> transactionLastNowStamp = new
ThreadLocal<Timestamp>();
+ public static <V> V doNewTransaction(String ifErrorMessage, Callable<V>
callable) throws Throwable {
+ return doNewTransaction(ifErrorMessage, true, callable);
+ }
+
+ public static <V> V doNewTransaction(String ifErrorMessage, boolean
printException, Callable<V> callable) throws Throwable {
+ Transaction tx = TransactionUtil.suspend();
+ try {
+ return doTransaction(ifErrorMessage, printException, callable);
+ } finally {
+ TransactionUtil.resume(tx);
+ }
+ }
+
+ public static <V> V doTransaction(String ifErrorMessage, Callable<V>
callable) throws Throwable {
+ return doTransaction(ifErrorMessage, true, callable);
+ }
+
+ public static <V> V doTransaction(String ifErrorMessage, boolean
printException, Callable<V> callable) throws Throwable {
+ boolean tx = TransactionUtil.begin();
+ Throwable transactionAbortCause = null;
+ try {
+ try {
+ return callable.call();
+ } catch (Throwable t) {
+ while (t.getCause() != null) {
+ t = t.getCause();
+ }
+ throw t;
+ }
+ } catch (Error e) {
+ transactionAbortCause = e;
+ throw e;
+ } catch (RuntimeException e) {
+ transactionAbortCause = e;
+ throw e;
+ } catch (Throwable t) {
+ transactionAbortCause = t;
+ throw t;
+ } finally {
+ if (transactionAbortCause == null) {
+ TransactionUtil.commit(tx);
+ } else {
+ if (printException) transactionAbortCause.printStackTrace();
+ TransactionUtil.rollback(tx, ifErrorMessage,
transactionAbortCause);
+ }
+ }
+ }
+
/** Begins a transaction in the current thread IF transactions are
available; only
* tries if the current transaction status is ACTIVE, if not active it
returns false.
* If and on only if it begins a transaction it will return true. In other
words, if
Modified:
ofbiz/trunk/framework/webslinger/src/org/ofbiz/webslinger/EntityTransactionUtil.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/webslinger/src/org/ofbiz/webslinger/EntityTransactionUtil.java?rev=815914&r1=815913&r2=815914&view=diff
==============================================================================
---
ofbiz/trunk/framework/webslinger/src/org/ofbiz/webslinger/EntityTransactionUtil.java
(original)
+++
ofbiz/trunk/framework/webslinger/src/org/ofbiz/webslinger/EntityTransactionUtil.java
Wed Sep 16 18:06:54 2009
@@ -18,49 +18,20 @@
*******************************************************************************/
package org.ofbiz.webslinger;
-import javax.transaction.Transaction;
import org.ofbiz.entity.transaction.TransactionUtil;
import java.util.concurrent.Callable;
public class EntityTransactionUtil {
+ /** @deprecated use TransactionUtil.doNewTransaction */
+ @Deprecated
public static <V> V doNewTransaction(String ifErrorMessage, Callable<V>
callable) throws Throwable {
- Transaction tx = TransactionUtil.suspend();
- try {
- return doTransaction(ifErrorMessage, callable);
- } finally {
- TransactionUtil.resume(tx);
- }
+ return TransactionUtil.doNewTransaction(ifErrorMessage, callable);
}
+ /** @deprecated use TransactionUtil.doNewTransaction */
+ @Deprecated
public static <V> V doTransaction(String ifErrorMessage, Callable<V>
callable) throws Throwable {
- boolean tx = TransactionUtil.begin();
- Throwable transactionAbortCause = null;
- try {
- try {
- return callable.call();
- } catch (Throwable t) {
- while (t.getCause() != null) {
- t = t.getCause();
- }
- throw t;
- }
- } catch (Error e) {
- transactionAbortCause = e;
- throw e;
- } catch (RuntimeException e) {
- transactionAbortCause = e;
- throw e;
- } catch (Throwable t) {
- transactionAbortCause = t;
- throw t;
- } finally {
- if (transactionAbortCause == null) {
- TransactionUtil.commit(tx);
- } else {
- transactionAbortCause.printStackTrace();
- TransactionUtil.rollback(tx, ifErrorMessage,
transactionAbortCause);
- }
- }
+ return TransactionUtil.doTransaction(ifErrorMessage, callable);
}
}