You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by da...@apache.org on 2007/05/30 00:19:41 UTC

svn commit: r542676 - in /incubator/openejb/trunk/openejb3/container/openejb-core/src: main/java/org/apache/openejb/core/stateful/ test/java/org/apache/openejb/core/stateful/

Author: dain
Date: Tue May 29 15:19:40 2007
New Revision: 542676

URL: http://svn.apache.org/viewvc?view=rev&rev=542676
Log:
Attempted removal of a stateful EJB enrolled in a transaction should cause a RemoveException

Modified:
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulInstanceManager.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulContainerTest.java
    incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulSessionBeanTest.java

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java?view=diff&rev=542676&r1=542675&r2=542676
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java Tue May 29 15:19:40 2007
@@ -28,6 +28,7 @@
 import javax.ejb.EJBException;
 import javax.ejb.EJBHome;
 import javax.ejb.EJBLocalHome;
+import javax.ejb.RemoveException;
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.transaction.TransactionManager;
@@ -303,6 +304,11 @@
         ThreadContext oldCallContext = ThreadContext.enter(callContext);
         try {
             checkAuthorization(deploymentInfo, callMethod, callInterface);
+
+            if (instanceManager.getBeanTransaction(callContext) != null) {
+                throw new ApplicationException(new RemoveException("A stateful EJB enrolled in a transaction can not be removed"));
+            }
+
             Method runMethod = deploymentInfo.getMatchingBeanMethod(callMethod);
             StatefulInstanceManager.Instance instance = (StatefulInstanceManager.Instance) instanceManager.obtainInstance(primKey, callContext);
 

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulInstanceManager.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulInstanceManager.java?view=diff&rev=542676&r1=542675&r2=542676
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulInstanceManager.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulInstanceManager.java Tue May 29 15:19:40 2007
@@ -116,6 +116,7 @@
 
     public Transaction getBeanTransaction(ThreadContext callContext) throws OpenEJBException {
         BeanEntry entry = getBeanEntry(callContext);
+        if (entry == null) return null;
         return entry.beanTransaction;
     }
 

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulContainerTest.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulContainerTest.java?view=diff&rev=542676&r1=542675&r2=542676
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulContainerTest.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulContainerTest.java Tue May 29 15:19:40 2007
@@ -178,7 +178,7 @@
     }
 
     public static enum Lifecycle {
-        CONSTRUCTOR, INJECTION, POST_CONSTRUCT, PRE_PASSIVATE1, POST_ACTIVATE1, BUSINESS_METHOD, PRE_PASSIVATE2, POST_ACTIVATE2, REMOVE, PRE_DESTROY
+        CONSTRUCTOR, INJECTION, POST_CONSTRUCT, PRE_PASSIVATE1, POST_ACTIVATE1, BUSINESS_METHOD, PRE_PASSIVATE2, POST_ACTIVATE2, PRE_PASSIVATE3, POST_ACTIVATE3, REMOVE, PRE_DESTROY, 
     }
 
     public static class WidgetBean implements Widget, RemoteWidget, Serializable {

Modified: incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulSessionBeanTest.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulSessionBeanTest.java?view=diff&rev=542676&r1=542675&r2=542676
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulSessionBeanTest.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/StatefulSessionBeanTest.java Tue May 29 15:19:40 2007
@@ -101,7 +101,7 @@
     public static List<Call> calls = new ArrayList<Call>();
 
     public static enum Call {
-        Constructor, SetSessionContext, EjbCreate, EjbPassivate1, EjbActivate1, BusinessMethod, EjbPassivate2, EjbActivate2, EjbRemove
+        Constructor, SetSessionContext, EjbCreate, EjbPassivate1, EjbActivate1, BusinessMethod, EjbPassivate2, EjbActivate2, EjbPassivate3, EjbActivate3, EjbRemove
     }
 
     public static class TargetBean implements SessionBean {



Re: Activation/Passivation and Transactions (Re: svn commit: r542676)

Posted by Dain Sundstrom <da...@iq80.com>.
On May 30, 2007, at 9:35 AM, David Blevins wrote:

> On May 29, 2007, at 3:19 PM, dain@apache.org wrote:
>
>> +++ incubator/openejb/trunk/openejb3/container/openejb-core/src/ 
>> main/java/org/apache/openejb/core/stateful/StatefulContainer.java  
>> Tue May 29 15:19:40 2007
>> +
>> +            if (instanceManager.getBeanTransaction(callContext) ! 
>> = null) {
>> +                throw new ApplicationException(new RemoveException 
>> ("A stateful EJB enrolled in a transaction can not be removed"));
>> +            }
>> +
> [...]
>> +++ incubator/openejb/trunk/openejb3/container/openejb-core/src/ 
>> main/java/org/apache/openejb/core/stateful/ 
>> StatefulInstanceManager.java Tue May 29 15:19:40 2007
>> @@ -116,6 +116,7 @@
>>
>>      public Transaction getBeanTransaction(ThreadContext  
>> callContext) throws OpenEJBException {
>>          BeanEntry entry = getBeanEntry(callContext);
>> +        if (entry == null) return null;
>>          return entry.beanTransaction;
>>      }
> [...]
>> +++ incubator/openejb/trunk/openejb3/container/openejb-core/src/ 
>> test/java/org/apache/openejb/core/stateful/ 
>> StatefulSessionBeanTest.java Tue May 29 15:19:40 2007
>> @@ -101,7 +101,7 @@
>>      public static List<Call> calls = new ArrayList<Call>();
>>
>>      public static enum Call {
>> -        Constructor, SetSessionContext, EjbCreate, EjbPassivate1,  
>> EjbActivate1, BusinessMethod, EjbPassivate2, EjbActivate2, EjbRemove
>> +        Constructor, SetSessionContext, EjbCreate, EjbPassivate1,  
>> EjbActivate1, BusinessMethod, EjbPassivate2, EjbActivate2,  
>> EjbPassivate3, EjbActivate3, EjbRemove
>
> We have some bad logic in here somewhere as we shouldn't need to  
> activate a bean instance to check it's transaction state as beans  
> with transactions can never be passivated.
>
> Seems the getBeanTransaction method should just call 'getBeanIndex 
> (callContext).get(primaryKey)' instead of 'getBeanEntry 
> (callContext)' which has the side effect of activating/passivating  
> an instance.

I was wondering why this was happening.  I'll fix it later today.

-dain

Activation/Passivation and Transactions (Re: svn commit: r542676)

Posted by David Blevins <da...@visi.com>.
On May 29, 2007, at 3:19 PM, dain@apache.org wrote:

> +++ incubator/openejb/trunk/openejb3/container/openejb-core/src/ 
> main/java/org/apache/openejb/core/stateful/StatefulContainer.java  
> Tue May 29 15:19:40 2007
> +
> +            if (instanceManager.getBeanTransaction(callContext) !=  
> null) {
> +                throw new ApplicationException(new RemoveException 
> ("A stateful EJB enrolled in a transaction can not be removed"));
> +            }
> +
[...]
> +++ incubator/openejb/trunk/openejb3/container/openejb-core/src/ 
> main/java/org/apache/openejb/core/stateful/ 
> StatefulInstanceManager.java Tue May 29 15:19:40 2007
> @@ -116,6 +116,7 @@
>
>      public Transaction getBeanTransaction(ThreadContext  
> callContext) throws OpenEJBException {
>          BeanEntry entry = getBeanEntry(callContext);
> +        if (entry == null) return null;
>          return entry.beanTransaction;
>      }
[...]
> +++ incubator/openejb/trunk/openejb3/container/openejb-core/src/ 
> test/java/org/apache/openejb/core/stateful/ 
> StatefulSessionBeanTest.java Tue May 29 15:19:40 2007
> @@ -101,7 +101,7 @@
>      public static List<Call> calls = new ArrayList<Call>();
>
>      public static enum Call {
> -        Constructor, SetSessionContext, EjbCreate, EjbPassivate1,  
> EjbActivate1, BusinessMethod, EjbPassivate2, EjbActivate2, EjbRemove
> +        Constructor, SetSessionContext, EjbCreate, EjbPassivate1,  
> EjbActivate1, BusinessMethod, EjbPassivate2, EjbActivate2,  
> EjbPassivate3, EjbActivate3, EjbRemove

We have some bad logic in here somewhere as we shouldn't need to  
activate a bean instance to check it's transaction state as beans  
with transactions can never be passivated.

Seems the getBeanTransaction method should just call 'getBeanIndex 
(callContext).get(primaryKey)' instead of 'getBeanEntry(callContext)'  
which has the side effect of activating/passivating an instance.


-David