User: fleury  
  Date: 00/07/14 11:36:20

  Modified:    src/main/org/jboss/ejb EntityContainer.java
  Log:
  On the pure container class I leave the "if" statement if we want to remove the 3 
stage thing ;-)
  Howeve the call is delegated to the intermediary class.  It does CMP or BMP 
accordingly.  CMP ones will delegate further to the store
  
  Revision  Changes    Path
  1.14      +74 -23    jboss/src/main/org/jboss/ejb/EntityContainer.java
  
  Index: EntityContainer.java
  ===================================================================
  RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/ejb/EntityContainer.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- EntityContainer.java      2000/07/07 23:03:49     1.13
  +++ EntityContainer.java      2000/07/14 18:36:20     1.14
  @@ -33,7 +33,7 @@
    *   @see EntityEnterpriseContext
    *   @author Rickard �berg ([EMAIL PROTECTED])
    *   @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
  - *   @version $Revision: 1.13 $
  + *   @version $Revision: 1.14 $
    */
   public class EntityContainer
      extends Container
  @@ -349,6 +349,14 @@
      }
      
      // Home interface implementation ---------------------------------
  +   
  +   /*
  +   * find(MethodInvocation)
  +   *
  +   * This methods finds the target instances by delegating to the persistence 
manager
  +   * It then manufactures EJBObject for all the involved instances found
  +   */
  +   
      public Object find(MethodInvocation mi)
         throws java.rmi.RemoteException, FinderException
      {
  @@ -361,37 +369,79 @@
         } else
         {
            // Single entity finder
  -         Object id = getPersistenceManager().findEntity(mi.getMethod(), 
mi.getArguments(), (EntityEnterpriseContext)mi.getEnterpriseContext());
  +         Object id = getPersistenceManager().findEntity(mi.getMethod(), 
  +                                                             mi.getArguments(), 
  +                                                                                    
                         (EntityEnterpriseContext)mi.getEnterpriseContext());
  +              
                 return (EJBObject)containerInvoker.getEntityEJBObject(id);
         }
      }
  +   
  +   /*
  +   * createHome(MethodInvocation)
  +   *
  +   * This method takes care of the wiring of the "EJBObject" trio (target, context, 
proxy)
  +   * It delegates to the persistence manager.
  +   *
  +   */
        
        public EJBObject createHome(MethodInvocation mi)
                throws java.rmi.RemoteException, CreateException
        {
                
  -             EntityEnterpriseContext ctx = (EntityEnterpriseContext) 
mi.getEnterpriseContext();
  +         getPersistenceManager().createEntity(mi.getMethod(), 
  +                                                                                    
  mi.getArguments(), 
  +                                                                                    
  (EntityEnterpriseContext) mi.getEnterpriseContext());
  +             return 
((EntityEnterpriseContext)mi.getEnterpriseContext()).getEJBObject();
  +     }
  +     /*
                
  -             try {
  -                     
  -                     // Call ejbCreate
  -                     getBeanClass().getMethod("ejbCreate", 
mi.getMethod().getParameterTypes())
  -                     .invoke(ctx.getInstance(),mi.getArguments());
  -                     
  -                     
  -                     // Lock instance in cache
  -                     getInstanceCache().insert(ctx);
  -                     
  -                     
  -                     // Deal with the persistence in the persistence manager
  -                     getPersistenceManager().createEntity(mi.getMethod(), 
mi.getArguments(), ctx);
  -                     
  -                     // Create EJBObject
  -                     
ctx.setEJBObject(getContainerInvoker().getEntityEJBObject(mi.getId()));
  +             try {                                                                  
                                         EntityEnterpriseContext ctx = 
(EntityEnterpriseContext) mi.getEnterpriseContext();
  +     
  +                EntityEnterpriseContext ctx = (EntityEnterpriseContext) 
mi.getEnterpriseContext();
  +     
  +                     Method createMethod = getBeanClass().getMethod("ejbCreate", 
mi.getMethod().getParameterTypes())
  +                     Method postCreateMethod = 
getBeanClass().getMethod("ejbPostCreate", mi.getMethod().getParameterTypes())
                        
  -                     // Invoke postCreate
  -                     getBeanClass().getMethod("ejbPostCreate", 
mi.getMethod().getParameterTypes())
  -                     .invoke(ctx.getInstance(),mi.getArguments());
  +                     if (((jBossEntity) bean).getPersistenceType().equals("Bean")) {
  +                             
  +                             // The return is the primaryKey
  +                             Object id = createMethod.invoke(ctx.getInstance(), 
mi.getArguments());
  +                             
  +                             // Set it on the context
  +                             ctx.setId(id);
  +                             
  +                             // Lock instance in cache
  +                             getInstanceCache().insert(ctx);
  +                     
  +                             // Deal with the persistence in the persistence manager
  +                             getPersistenceManager().createEntity(mi.getMethod(), 
mi.getArguments(), ctx);
  +                     
  +                             // Create EJBObject
  +                             
ctx.setEJBObject(getContainerInvoker().getEntityEJBObject(id));
  +                     
  +                             // Invoke postCreate
  +                             
postCreateMethod.invoke(ctx.getInstance(),mi.getArguments());
  +                     }
  +                     
  +                     else {  // We are in the CMP case
  +                     
  +                             // The primary key is computed by the PM
  +                             createMethod.invoke(ctx.getInstance(), 
mi.getArguments());
  +                             
  +                             // Lock instance in cache
  +                             getInstanceCache().insert(ctx);
  +                     
  +                             // The PM returns the PrimaryKey in case of CMP
  +                             // Compute it and set it on the context
  +                             
ctx.setId(getPersistenceManager().createEntity(mi.getMethod(), mi.getArguments(), 
ctx));
  +                     
  +                             // Create EJBObject
  +                             
ctx.setEJBObject(getContainerInvoker().getEntityEJBObject(ctx.getId()));
  +                     
  +                             // Invoke postCreate
  +                             
postCreateMethod.invoke(ctx.getInstance(),mi.getArguments());
  +                     }
                        
                        return ctx.getEJBObject();
                
  @@ -405,7 +455,8 @@
                        
                        throw new CreateException("Could not create entity:"+e);
                } 
  -     }
  +             */
  +     
                
      // EJBHome implementation ----------------------------------------
      public void removeHome(MethodInvocation mi)
  
  
  

Reply via email to