You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by dj...@apache.org on 2010/08/24 21:05:52 UTC

svn commit: r988667 - /openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/BaseContext.java

Author: djencks
Date: Tue Aug 24 19:05:52 2010
New Revision: 988667

URL: http://svn.apache.org/viewvc?rev=988667&view=rev
Log:
OPENEJB-1341 IllegalStateException based on tx policy, not presence of actual tx

Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/BaseContext.java

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/BaseContext.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/BaseContext.java?rev=988667&r1=988666&r2=988667&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/BaseContext.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/BaseContext.java Tue Aug 24 19:05:52 2010
@@ -22,6 +22,7 @@ import org.apache.openejb.core.timer.Ejb
 import org.apache.openejb.core.timer.TimerServiceImpl;
 import org.apache.openejb.core.transaction.EjbUserTransaction;
 import org.apache.openejb.core.transaction.TransactionPolicy;
+import org.apache.openejb.core.transaction.TransactionType;
 import org.apache.openejb.spi.SecurityService;
 
 import javax.ejb.EJBContext;
@@ -142,9 +143,10 @@ public abstract class BaseContext implem
         if (txPolicy == null) {
             throw new IllegalStateException("ThreadContext does not contain a TransactionEnvironment");
         }
-        if (!txPolicy.isTransactionActive()) {
-            // this would be true for Supports tx attribute where no tx was propagated
-            throw new IllegalStateException("No current transaction");
+        if (txPolicy.getTransactionType() == TransactionType.Never
+                || txPolicy.getTransactionType() == TransactionType.NotSupported
+                || txPolicy.getTransactionType() == TransactionType.Supports) {
+            throw new IllegalStateException("setRollbackOnly accessible only from MANDATORY, REQUIRED, or REQUIRES_NEW");
         }
         txPolicy.setRollbackOnly();
     }
@@ -158,15 +160,16 @@ public abstract class BaseContext implem
             throw new IllegalStateException("bean-managed transaction beans can not access the getRollbackOnly() method: deploymentId=" + di.getDeploymentID());
         }
 
-        TransactionPolicy transactionPolicy = threadContext.getTransactionPolicy();
-        if (transactionPolicy == null) {
+        TransactionPolicy txPolicy = threadContext.getTransactionPolicy();
+        if (txPolicy == null) {
             throw new IllegalStateException("ThreadContext does not contain a TransactionEnvironment");
         }
-        if (!transactionPolicy.isTransactionActive()) {
-            // this would be true for Supports tx attribute where no tx was propagated
-            throw new IllegalStateException("No current transaction");
+        if (txPolicy.getTransactionType() == TransactionType.Never
+                || txPolicy.getTransactionType() == TransactionType.NotSupported
+                || txPolicy.getTransactionType() == TransactionType.Supports) {
+            throw new IllegalStateException("getRollbackOnly accessible only from MANDATORY, REQUIRED, or REQUIRES_NEW");
         }
-        return transactionPolicy.isRollbackOnly();
+        return txPolicy.isRollbackOnly();
     }
 
     public TimerService getTimerService() throws IllegalStateException {