User: dsundstrom
  Date: 01/06/23 20:06:46

  Modified:    src/main/org/jboss/ejb/plugins AbstractInstancePool.java
                        BMPPersistenceManager.java
                        CMPPersistenceManager.java
                        SingletonStatelessSessionInstancePool.java
  Log:
  Updated containers, persistence managers and pools to deligate the task of
  creating the bean instance and initializing the bean to the persistence
  store.  The code detects checks to see if the store is an
  EntityPersistenceStore2 and if it is, the persistence manager deligates.
  In the event that the store is 'old style' default old implementation is
  invoked.
  
  Revision  Changes    Path
  1.11      +2 -2      jboss/src/main/org/jboss/ejb/plugins/AbstractInstancePool.java
  
  Index: AbstractInstancePool.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/AbstractInstancePool.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- AbstractInstancePool.java 2001/06/18 20:01:23     1.10
  +++ AbstractInstancePool.java 2001/06/24 03:06:46     1.11
  @@ -31,7 +31,7 @@
    *
    *   @see <related>
    *   @author <a href="mailto:[EMAIL PROTECTED]";>Rickard �berg</a>
  - *   @version $Revision: 1.10 $
  + *   @version $Revision: 1.11 $
    */
   public abstract class AbstractInstancePool
      implements InstancePool, XmlLoadable
  @@ -103,7 +103,7 @@
         {
            try
            {
  -            return create(container.getBeanClass().newInstance());
  +            return create(container.createBeanClassInstance());
            } catch (InstantiationException e)
            {
               throw new ServerException("Could not instantiate bean", e);
  
  
  
  1.25      +11 -2     jboss/src/main/org/jboss/ejb/plugins/BMPPersistenceManager.java
  
  Index: BMPPersistenceManager.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/BMPPersistenceManager.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- BMPPersistenceManager.java        2001/06/23 03:32:55     1.24
  +++ BMPPersistenceManager.java        2001/06/24 03:06:46     1.25
  @@ -36,7 +36,7 @@
   *   @see <related>
   *   @author <a href="mailto:[EMAIL PROTECTED]";>Rickard �berg</a>
   *  @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
  -*   @version $Revision: 1.24 $
  +*   @version $Revision: 1.25 $
   */
   public class BMPPersistenceManager
   implements EntityPersistenceManager
  @@ -88,7 +88,16 @@
         }
   
      }
  -   
  +
  +     /**
  +     * Returns a new instance of the bean class or a subclass of the bean class.
  +     * 
  +     * @return the new instance
  +     */
  +     public Object createBeanClassInstance() throws Exception {
  +             return con.getBeanClass().newInstance();
  +     }
  +
      private void createMethodCache( Method[] methods )
         throws NoSuchMethodException
      {
  
  
  
  1.24      +147 -132  jboss/src/main/org/jboss/ejb/plugins/CMPPersistenceManager.java
  
  Index: CMPPersistenceManager.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/CMPPersistenceManager.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- CMPPersistenceManager.java        2001/06/21 21:51:47     1.23
  +++ CMPPersistenceManager.java        2001/06/24 03:06:46     1.24
  @@ -32,6 +32,7 @@
   import org.jboss.ejb.EntityEnterpriseContext;
   import org.jboss.ejb.EntityCache;
   import org.jboss.ejb.EntityPersistenceStore;
  +import org.jboss.ejb.EntityPersistenceStore2;
   import org.jboss.metadata.EntityMetaData;
   
   import org.jboss.util.FinderResults;
  @@ -48,7 +49,7 @@
   *   @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
   *   @author <a href="mailto:[EMAIL PROTECTED]";>Dan Christopherson</a>
   *   @author <a href="mailto:[EMAIL PROTECTED]";>Bill Burke</a>
  -*   @version $Revision: 1.23 $
  +*   @version $Revision: 1.24 $
   *
   *   Revisions:
   *   20010621 Bill Burke: removed loadEntities call because CMP read-ahead is now
  @@ -116,6 +117,18 @@
         store.init();
      }
       
  +     /**
  +     * Returns a new instance of the bean class or a subclass of the bean class.
  +     * 
  +     * @return the new instance
  +     */
  +     public Object createBeanClassInstance() throws Exception {
  +             if(store instanceof EntityPersistenceStore2) {
  +                     return 
((EntityPersistenceStore2)store).createBeanClassInstance();
  +             }
  +             return con.getBeanClass().newInstance();
  +     }
  +
      private void createMethodCache( Method[] methods )
         throws NoSuchMethodException
      {
  @@ -145,143 +158,88 @@
         store.destroy();
      }
   
  -   public void createEntity(Method m, Object[] args, EntityEnterpriseContext ctx)
  -      throws Exception {
  -      // Get methods
  -      Method createMethod = (Method)createMethods.get(m);
  -      Method postCreateMethod = (Method)postCreateMethods.get(m);
  -
  -      // Reset all attributes to default value
  -      // The EJB 1.1 specification is not entirely clear about this,
  -      // the EJB 2.0 spec is, see page 169.
  -      // Robustness is more important than raw speed for most server
  -      // applications, and not resetting atrribute values result in
  -      // *very* weird errors (old states re-appear in different instances and the
  -      // developer thinks he's on drugs).
  -
  -             // first get cmp metadata of this entity
  -      Object instance = ctx.getInstance();
  -      Class ejbClass = instance.getClass();
  -      Field cmpField;
  -      Class cmpFieldType;
  -      for (Iterator i= 
((EntityMetaData)ctx.getContainer().getBeanMetaData()).getCMPFields();
  -           i.hasNext();) {
  -         try {
  -            // get the field declaration
  -            try{
  -               cmpField = ejbClass.getField((String)i.next());
  -               cmpFieldType = cmpField.getType();
  -               // find the type of the field and reset it
  -               // to the default value
  -               if (cmpFieldType.equals(boolean.class))  {
  -                  cmpField.setBoolean(instance,false);
  -               } else if (cmpFieldType.equals(byte.class))  {
  -                  cmpField.setByte(instance,(byte)0);
  -               } else if (cmpFieldType.equals(int.class))  {
  -                  cmpField.setInt(instance,0);
  -               } else if (cmpFieldType.equals(long.class))  {
  -                  cmpField.setLong(instance,0L);
  -               } else if (cmpFieldType.equals(short.class))  {
  -                  cmpField.setShort(instance,(short)0);
  -               } else if (cmpFieldType.equals(char.class))  {
  -                  cmpField.setChar(instance,'\u0000');
  -               } else if (cmpFieldType.equals(double.class))  {
  -                  cmpField.setDouble(instance,0d);
  -               } else if (cmpFieldType.equals(float.class))  {
  -                  cmpField.setFloat(instance,0f);
  -
  -                  //} else if (... cmr collection in ejb2.0...) {
  -                  // cmpField.set(instance,someNewCollection?);
  -
  -               } else  {
  -                  cmpField.set(instance,null);
  -               }
  -            } catch (NoSuchFieldException e){
  -               // will be here with dependant value object's private attributes
  -               // should not be a problem
  -            }
  -         } catch (Exception e) {
  -            throw new EJBException(e);
  -         }
  -      }
  +     public void createEntity(Method m, Object[] args, EntityEnterpriseContext ctx)
  +             throws Exception {
   
  -      // Call ejbCreate on the target bean
  -      try {
  -         createMethod.invoke(ctx.getInstance(), args);
  -      } catch (IllegalAccessException e)
  -      {
  -         // Throw this as a bean exception...(?)
  -         throw new EJBException(e);
  -      } catch (InvocationTargetException ite)
  -      {
  -         Throwable e = ite.getTargetException();
  -         if (e instanceof EJBException)
  -         {
  +             // Get methods
  +             Method createMethod = (Method)createMethods.get(m);
  +             Method postCreateMethod = (Method)postCreateMethods.get(m);
  +             
  +             // Deligate initialization of bean to persistence store
  +             // if the store can handle initialization.
  +      if(store instanceof EntityPersistenceStore2) {
  +                     ((EntityPersistenceStore2)store).initEntity(ctx);
  +             } else {
  +                     // for backwards compatibility
  +                     initEntity(ctx);
  +             }
  +             
  +             // Call ejbCreate on the target bean
  +             try {
  +                     createMethod.invoke(ctx.getInstance(), args);
  +             } catch (IllegalAccessException e){
  +                     // Throw this as a bean exception...(?)
  +                     throw new EJBException(e);
  +             } catch (InvocationTargetException ite) {
  +                     Throwable e = ite.getTargetException();
  +                     if(e instanceof EJBException) {
                                // Rethrow exception
  -            throw (EJBException)e;
  -         } else if (e instanceof RuntimeException)
  -         {
  +                             throw (EJBException)e;
  +                     } else if (e instanceof RuntimeException) {
                                // Wrap runtime exceptions
  -            throw new EJBException((Exception)e);
  -         } else if (e instanceof Exception)
  -         {
  +                             throw new EJBException((Exception)e);
  +                     } else if(e instanceof Exception) {
               // Remote, Create, or custom app. exception
  -            throw (Exception)e;
  -         } else
  -         {
  -            throw (Error)e;
  -         }
  -      }
  -
  -      // Have the store persist the new instance, the return is the key
  -      Object id = store.createEntity(m, args, ctx);
  -
  -      // Set the key on the target context
  -      ctx.setId(id);
  -
  -      // Create a new CacheKey
  -      Object cacheKey = ((EntityCache) con.getInstanceCache()).createCacheKey( id );
  -
  -      // Give it to the context
  -      ctx.setCacheKey(cacheKey);
  -
  -      // insert instance in cache, it is safe
  -      con.getInstanceCache().insert(ctx);
  -
  -      // Create EJBObject
  -      if (con.getContainerInvoker() != null)
  -         ctx.setEJBObject(con.getContainerInvoker().getEntityEJBObject(cacheKey));
  -      if (con.getLocalHomeClass() != null)
  -         
ctx.setEJBLocalObject(con.getLocalContainerInvoker().getEntityEJBLocalObject(cacheKey));
  -
  -      try
  -      {
  -         postCreateMethod.invoke(ctx.getInstance(), args);
  -      } catch (IllegalAccessException e)
  -      {
  -         // Throw this as a bean exception...(?)
  -         throw new EJBException(e);
  -      } catch (InvocationTargetException ite)
  -      {
  -         Throwable e = ite.getTargetException();
  -         if (e instanceof EJBException)
  -         {
  +                        throw (Exception)e;
  +                     } else {
  +                        throw (Error)e;
  +                     }
  +      }
  +
  +             // Have the store persist the new instance, the return is the key
  +             Object id = store.createEntity(m, args, ctx);
  +             
  +             // Set the key on the target context
  +             ctx.setId(id);
  +             
  +             // Create a new CacheKey
  +             Object cacheKey = ((EntityCache) 
con.getInstanceCache()).createCacheKey( id );
  +             
  +             // Give it to the context
  +             ctx.setCacheKey(cacheKey);
  +             
  +             // insert instance in cache, it is safe
  +             con.getInstanceCache().insert(ctx);
  +             
  +             // Create EJBObject
  +             if (con.getContainerInvoker() != null) {
  +                     
ctx.setEJBObject(con.getContainerInvoker().getEntityEJBObject(cacheKey));
  +             }
  +             if (con.getLocalHomeClass() != null) {
  +                     
ctx.setEJBLocalObject(con.getLocalContainerInvoker().getEntityEJBLocalObject(cacheKey));
  +             }
  +
  +             try {
  +                     postCreateMethod.invoke(ctx.getInstance(), args);
  +             } catch (IllegalAccessException e) {
  +                     // Throw this as a bean exception...(?)
  +                     throw new EJBException(e);
  +             } catch (InvocationTargetException ite) {
  +                     Throwable e = ite.getTargetException();
  +                     if (e instanceof EJBException) {
                                // Rethrow exception
  -            throw (EJBException)e;
  -         } else if (e instanceof RuntimeException)
  -         {
  +                             throw (EJBException)e;
  +                     } else if (e instanceof RuntimeException) {
                                // Wrap runtime exceptions
  -            throw new EJBException((Exception)e);
  -         } else if (e instanceof Exception)
  -         {
  -            // Remote, Create, or custom app. exception
  -            throw (Exception)e;
  -         } else
  -         {
  -            throw (Error)e;
  -         }
  -      }
  -   }
  +                             throw new EJBException((Exception)e);
  +                     } else if (e instanceof Exception) {
  +                             // Remote, Create, or custom app. exception
  +                             throw (Exception)e;
  +                     } else {
  +                             throw (Error)e;
  +                     }
  +             }
  +     }
   
      public Object findEntity(Method finderMethod, Object[] args, 
EntityEnterpriseContext ctx)
         throws Exception {
  @@ -497,6 +455,63 @@
            }
         }
      }
  +
  +     /**
  +      * Reset all attributes to default value
  +      * 
  +      * This method is supplied for backwards compatibility.
  +      * New versions of the PersistenceStore handle this for us.
  +      * 
  +      * The EJB 1.1 specification is not entirely clear about this,
  +      * the EJB 2.0 spec is, see page 169.
  +      * Robustness is more important than raw speed for most server
  +      * applications, and not resetting atrribute values result in
  +      * *very* weird errors (old states re-appear in different instances and the
  +      * developer thinks he's on drugs).
  +      */
  +     protected void initEntity(EntityEnterpriseContext ctx) {
  +             // first get cmp metadata of this entity
  +             Object instance = ctx.getInstance();
  +             Class ejbClass = instance.getClass();
  +             Field cmpField;
  +             Class cmpFieldType;
  +             Iterator i= 
((EntityMetaData)ctx.getContainer().getBeanMetaData()).getCMPFields();
  +             while(i.hasNext()) {
  +                     try {
  +                             // get the field declaration
  +                             try{
  +                                     cmpField = ejbClass.getField((String)i.next());
  +                                     cmpFieldType = cmpField.getType();
  +                                     // find the type of the field and reset it
  +                                     // to the default value
  +                                     if (cmpFieldType.equals(boolean.class))  {
  +                                             cmpField.setBoolean(instance,false);
  +                                     } else if (cmpFieldType.equals(byte.class))  {
  +                                             cmpField.setByte(instance,(byte)0);
  +                                     } else if (cmpFieldType.equals(int.class))  {
  +                                             cmpField.setInt(instance,0);
  +                                     } else if (cmpFieldType.equals(long.class))  {
  +                                             cmpField.setLong(instance,0L);
  +                                     } else if (cmpFieldType.equals(short.class))  {
  +                                             cmpField.setShort(instance,(short)0);
  +                                     } else if (cmpFieldType.equals(char.class))  {
  +                                             cmpField.setChar(instance,'\u0000');
  +                                     } else if (cmpFieldType.equals(double.class))  
{
  +                                             cmpField.setDouble(instance,0d);
  +                                     } else if (cmpFieldType.equals(float.class))  {
  +                                             cmpField.setFloat(instance,0f);
  +                                     } else  {
  +                                             cmpField.set(instance,null);
  +                                     }
  +                             } catch (NoSuchFieldException e){
  +                                     // will be here with dependant value object's 
private attributes
  +                                     // should not be a problem
  +                             }
  +                     } catch (Exception e) {
  +                             throw new EJBException(e);
  +                     }
  +             }
  +     }                       
   
      // Z implementation ----------------------------------------------
   
  
  
  
  1.8       +2 -2      
jboss/src/main/org/jboss/ejb/plugins/SingletonStatelessSessionInstancePool.java
  
  Index: SingletonStatelessSessionInstancePool.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/SingletonStatelessSessionInstancePool.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SingletonStatelessSessionInstancePool.java        2001/06/18 20:01:23     1.7
  +++ SingletonStatelessSessionInstancePool.java        2001/06/24 03:06:46     1.8
  @@ -29,7 +29,7 @@
    *      
    *   @see <related>
    *   @author <a href="mailto:[EMAIL PROTECTED]";>Rickard �berg</a>
  - *   @version $Revision: 1.7 $
  + *   @version $Revision: 1.8 $
    */
   public class SingletonStatelessSessionInstancePool
      implements InstancePool, XmlLoadable
  @@ -98,7 +98,7 @@
         {
            try
            {
  -            ctx = create(con.getBeanClass().newInstance(), con);
  +            ctx = create(con.createBeanClassInstance(), con);
            } catch (InstantiationException e)
            {
               throw new ServerException("Could not instantiate bean", e);
  
  
  

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

Reply via email to