Author: jonesde
Date: Tue Sep 11 01:52:18 2007 New Revision: 574514 URL: http://svn.apache.org/viewvc?rev=574514&view=rev Log: Fixed problem with service engine and TransactionUtil where if rollback only was set in a service it could not run sub-services even in their own transaction; the test case for this now passes with no problems Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/transaction/TransactionUtil.java ofbiz/trunk/framework/service/servicedef/services_test_se.xml ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.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=574514&r1=574513&r2=574514&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 Tue Sep 11 01:52:18 2007 @@ -146,6 +146,10 @@ return STATUS_NO_TRANSACTION; } } + + public static String getStatusString() throws GenericTransactionException { + return getTransactionStateString(getStatus()); + } public static boolean isTransactionInPlace() throws GenericTransactionException { int status = getStatus(); @@ -311,7 +315,7 @@ public static Transaction suspend() throws GenericTransactionException { try { - if (TransactionUtil.getStatus() == TransactionUtil.STATUS_ACTIVE) { + if (TransactionUtil.getStatus() != TransactionUtil.STATUS_NO_TRANSACTION) { TransactionManager txMgr = TransactionFactory.getTransactionManager(); if (txMgr != null) { pushTransactionBeginStackSave(clearTransactionBeginStack()); @@ -323,7 +327,7 @@ return null; } } else { - Debug.logWarning("No transaction active, so not suspending.", module); + Debug.logWarning("No transaction in place, so not suspending.", module); return null; } } catch (SystemException e) { @@ -409,6 +413,19 @@ } public static String getTransactionStateString(int state) { + /* + * javax.transaction.Status + * STATUS_ACTIVE 0 + * STATUS_MARKED_ROLLBACK 1 + * STATUS_PREPARED 2 + * STATUS_COMMITTED 3 + * STATUS_ROLLEDBACK 4 + * STATUS_UNKNOWN 5 + * STATUS_NO_TRANSACTION 6 + * STATUS_PREPARING 7 + * STATUS_COMMITTING 8 + * STATUS_ROLLING_BACK 9 + */ switch (state) { case Status.STATUS_ACTIVE: return "Transaction Active (" + state + ")"; Modified: ofbiz/trunk/framework/service/servicedef/services_test_se.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/servicedef/services_test_se.xml?rev=574514&r1=574513&r2=574514&view=diff ============================================================================== --- ofbiz/trunk/framework/service/servicedef/services_test_se.xml (original) +++ ofbiz/trunk/framework/service/servicedef/services_test_se.xml Tue Sep 11 01:52:18 2007 @@ -32,7 +32,7 @@ <service name="testServiceDeadLockRetryThreadA" engine="java" auth="false" transaction-timeout="10" location="org.ofbiz.service.test.ServiceEngineTestServices" invoke="testServiceDeadLockRetryThreadA"> </service> - <service name="testServiceDeadLockRetryThreadB" engine="java" auth="false" transaction-timeout="4" + <service name="testServiceDeadLockRetryThreadB" engine="java" auth="false" transaction-timeout="10" location="org.ofbiz.service.test.ServiceEngineTestServices" invoke="testServiceDeadLockRetryThreadB"> </service> Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java?rev=574514&r1=574513&r2=574514&view=diff ============================================================================== --- ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java (original) +++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java Tue Sep 11 01:52:18 2007 @@ -22,20 +22,20 @@ import java.util.List; import java.util.Locale; import java.util.Map; + import javax.transaction.Transaction; import javolution.util.FastList; import javolution.util.FastMap; -import org.apache.commons.collections.map.LRUMap; -import org.w3c.dom.Element; +import org.apache.commons.collections.map.LRUMap; import org.ofbiz.base.config.GenericConfigException; import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.GeneralRuntimeException; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilTimer; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.UtilXml; -import org.ofbiz.base.util.GeneralRuntimeException; import org.ofbiz.entity.GenericDelegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; @@ -53,6 +53,7 @@ import org.ofbiz.service.jms.JmsListenerFactory; import org.ofbiz.service.job.JobManager; import org.ofbiz.service.job.JobManagerException; +import org.w3c.dom.Element; /** * Global Service Dispatcher @@ -277,11 +278,17 @@ boolean beganTrans = false; try { if (modelService.useTransaction) { - beganTrans = TransactionUtil.begin(modelService.transactionTimeout); - // isolate the transaction if defined - if (modelService.requireNewTransaction && !beganTrans) { - parentTransaction = TransactionUtil.suspend(); - // now start a new transaction + if (TransactionUtil.isTransactionInPlace()) { + // if a new transaction is needed, do it here; if not do nothing, just use current tx + if (modelService.requireNewTransaction) { + parentTransaction = TransactionUtil.suspend(); + if (TransactionUtil.isTransactionInPlace()) { + throw new GenericTransactionException("In service " + modelService.name + " transaction is still in place after suspend, status is " + TransactionUtil.getStatusString()); + } + // now start a new transaction + beganTrans = TransactionUtil.begin(modelService.transactionTimeout); + } + } else { beganTrans = TransactionUtil.begin(modelService.transactionTimeout); } // enlist for XAResource debugging @@ -481,7 +488,7 @@ } finally { // if there was an error, rollback transaction, otherwise commit if (isError) { - String errMsg = "Error is Service [" + modelService.name + "]: " + ServiceUtil.getErrorMessage(result); + String errMsg = "Error in Service [" + modelService.name + "]: " + ServiceUtil.getErrorMessage(result); Debug.logError(errMsg, module); // rollback the transaction @@ -585,11 +592,14 @@ try { if (service.useTransaction) { - beganTrans = TransactionUtil.begin(service.transactionTimeout); - // isolate the transaction if defined - if (service.requireNewTransaction && !beganTrans) { - parentTransaction = TransactionUtil.suspend(); - // now start a new transaction + if (TransactionUtil.isTransactionInPlace()) { + // if a new transaction is needed, do it here; if not do nothing, just use current tx + if (service.requireNewTransaction) { + parentTransaction = TransactionUtil.suspend(); + // now start a new transaction + beganTrans = TransactionUtil.begin(service.transactionTimeout); + } + } else { beganTrans = TransactionUtil.begin(service.transactionTimeout); } // enlist for XAResource debugging |
Free forum by Nabble | Edit this page |