[jboss-cvs] JBossAS SVN: r59062 - trunk/server/src/main/org/jboss/ejb

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Dec 15 12:02:20 EST 2006


Author: alex.loubyansky at jboss.com
Date: 2006-12-15 12:02:18 -0500 (Fri, 15 Dec 2006)
New Revision: 59062

Modified:
   trunk/server/src/main/org/jboss/ejb/StatefulSessionContainer.java
Log:
JBAS-3946 remove() called on home of a sfsb in tx must fail

Modified: trunk/server/src/main/org/jboss/ejb/StatefulSessionContainer.java
===================================================================
--- trunk/server/src/main/org/jboss/ejb/StatefulSessionContainer.java	2006-12-15 12:42:46 UTC (rev 59061)
+++ trunk/server/src/main/org/jboss/ejb/StatefulSessionContainer.java	2006-12-15 17:02:18 UTC (rev 59062)
@@ -66,6 +66,8 @@
     */
    protected InstanceCache instanceCache;
    protected Method getEJBObject;
+   protected Method ejbObjectRemove;
+   protected Method ejbLocalObjectRemove;
 
    public void setInstanceCache(InstanceCache ic)
    {
@@ -116,13 +118,15 @@
       // Get the Handle.getEJBObject method for permission checks
       try
       {
-         getEJBObject = Handle.class.getMethod("getEJBObject",
-            new Class[0]);
+         getEJBObject = Handle.class.getMethod("getEJBObject", new Class[0]);
       }
       catch (Exception e)
       {
          log.warn("Failed to grant access to the Handle.getEJBObject method");
       }
+
+      ejbObjectRemove = EJBObject.class.getMethod("remove", null);
+      ejbLocalObjectRemove = EJBLocalObject.class.getMethod("remove", null);
    }
 
    /**
@@ -217,10 +221,6 @@
    public void remove(Invocation mi)
       throws RemoteException, RemoveException
    {
-      // 7.6 EJB2.0, it is illegal to remove a bean while in a transaction
-      // if (((EnterpriseContext) mi.getEnterpriseContext()).getTransaction() != null)
-      // throw new RemoveException("StatefulSession bean in transaction, cannot remove (EJB2.0 7.6)");
-
       // if the session is removed already then let the user know they have a problem
       StatefulSessionEnterpriseContext ctx = (StatefulSessionEnterpriseContext) mi.getEnterpriseContext();
       if (ctx.getId() == null)
@@ -551,12 +551,6 @@
 
       public Object invoke(Invocation mi) throws Exception
       {
-         // wire the transaction on the context, this is how the instance remember the tx
-         // Unlike Entity beans we can't do that in the previous interceptors (ordering)
-         EnterpriseContext ctx = (EnterpriseContext) mi.getEnterpriseContext();
-         if (ctx.getTransaction() == null)
-            ctx.setTransaction(mi.getTransaction());
-
          // Get method
          Method miMethod = mi.getMethod();
          Method m = (Method) getBeanMapping().get(miMethod);
@@ -567,6 +561,19 @@
             throw new EJBException(msg);
          }
 
+         // wire the transaction on the context, this is how the instance remember the tx
+         // Unlike Entity beans we can't do that in the previous interceptors (ordering)
+         EnterpriseContext ctx = (EnterpriseContext) mi.getEnterpriseContext();
+         if (ctx.getTransaction() == null)
+            ctx.setTransaction(mi.getTransaction());
+         else if(ejbObjectRemove.equals(miMethod) || ejbLocalObjectRemove.equals(miMethod))
+         {
+            throw new RemoveException("An attempt to remove a session " +
+               "object while the object is in a transaction " +
+               "(EJB2.1, 7.6.4 Restrictions for Transactions): ejb-name=" +
+               metaData.getEjbName() + ", method=" + mi.getMethod() + ", tx=" + ctx.getTransaction());
+         }
+
          // Select instance to invoke (container or bean)
          if (m.getDeclaringClass().equals(StatefulSessionContainer.class)
             || m.getDeclaringClass().equals(SessionContainer.class))




More information about the jboss-cvs-commits mailing list