User: dsundstrom
  Date: 02/04/13 18:02:59

  Added:       src/main/org/jboss/ejb/plugins
                        EntityCreationInterceptor.java
  Log:
  Breaks entity create methods into a call down the invokeHome chain to
  invoke ejbCreate and one down the invoke chain to invoke ejbPostCreate.
  This makes ejbPostCreate look like a standard business method invocation.
  
  This should eliminate the "INSERTING AN ALREADY EXISTING BEAN" bugs.
  
  Revision  Changes    Path
  1.1                  
jboss/src/main/org/jboss/ejb/plugins/EntityCreationInterceptor.java
  
  Index: EntityCreationInterceptor.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.ejb.plugins;
  
  import java.rmi.RemoteException;
  
  import org.jboss.ejb.Container;
  import org.jboss.ejb.EntityContainer;
  import org.jboss.ejb.EntityEnterpriseContext;
  import org.jboss.invocation.Invocation;
  
  
  /**
  * The instance interceptors role is to break entity creation into two 
  * calls, one for ejbCreate and one for ejbPostCreate. The ejbCreate
  * method is passed over the invokeHome chain, and ejbPostCreate is 
  * passed over the invoke chain.
  *    
  * @author <a href="mailto:[EMAIL PROTECTED]";>Dain Sundstrom</a>
  * @version $Revision: 1.1 $
  */
  public class EntityCreationInterceptor extends AbstractInterceptor
  {
     protected EntityContainer container;
        
     public void setContainer(Container container)
     {
        this.container = (EntityContainer)container;
     }
        
     public Container getContainer()
     {
        return container;
     }
  
     public Object invokeHome(Invocation mi)
        throws Exception
     {
        // Invoke through interceptors
        Object retVal = getNext().invokeHome(mi);
  
        // Is the context now with an identity? 
        // This means that a create method was called, so invoke ejbPostCreate.
        EntityEnterpriseContext ctx = 
              (EntityEnterpriseContext) mi.getEnterpriseContext();
        if(ctx.getId() != null) {
           
           // copy from the context into the mi
           // interceptors down the chain look in the mi for the id not the ctx.
           mi.setId(ctx.getId());
           
           // invoke down the invoke chain
           // the final interceptor in EntityContainer will redirect this
           // call to postCreateEntity, which calls ejbPostCreate
           getNext().invoke(mi);
        }
        
        return retVal;
     }
  
     public Object invoke(Invocation mi)
        throws Exception
     {
        // nothing to see here... move along
        return getNext().invoke(mi);
     }
  }
  
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to