User: fleury  
  Date: 00/08/24 18:58:13

  Modified:    src/main/org/jboss/ejb/plugins
                        EntityInstanceInterceptor.java
  Log:
  The instance interceptor can work without FastKey
  
  Revision  Changes    Path
  1.7       +114 -113  
jboss/src/main/org/jboss/ejb/plugins/EntityInstanceInterceptor.java
  
  Index: EntityInstanceInterceptor.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/EntityInstanceInterceptor.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- EntityInstanceInterceptor.java    2000/08/18 03:20:56     1.6
  +++ EntityInstanceInterceptor.java    2000/08/25 01:58:13     1.7
  @@ -1,9 +1,9 @@
   /*
  - * jBoss, the OpenSource EJB server
  - *
  - * Distributable under GPL license.
  - * See terms of license at gnu.org.
  - */
  +* jBoss, the OpenSource EJB server
  +*
  +* Distributable under GPL license.
  +* See terms of license at gnu.org.
  +*/
   package org.jboss.ejb.plugins;
   
   import java.lang.reflect.Method;
  @@ -33,117 +33,118 @@
   import org.jboss.ejb.InstanceCache;
   import org.jboss.ejb.InstancePool;
   import org.jboss.ejb.MethodInvocation;
  -import org.jboss.util.FastKey;
  +import org.jboss.ejb.CacheKey;
   
   /**
  - *   This container acquires the given instance. 
  - *
  - *   @see <related>
  - *   @author Rickard �berg ([EMAIL PROTECTED])
  - *   @version $Revision: 1.6 $
  - */
  +*   This container acquires the given instance. 
  +*
  +*   @see <related>
  +*   @author Rickard �berg ([EMAIL PROTECTED])
  +*   @author <a href="[EMAIL PROTECTED]">Marc Fleury</a>
  +*   @version $Revision: 1.7 $
  +*/
   public class EntityInstanceInterceptor
  -   extends AbstractInterceptor
  +extends AbstractInterceptor
   {
  -   // Constants -----------------------------------------------------
  -    
  -   // Attributes ----------------------------------------------------
  -    protected EntityContainer container;
  -   
  -   // Static --------------------------------------------------------
  -
  -   // Constructors --------------------------------------------------
  -   
  -   // Public --------------------------------------------------------
  -   public void setContainer(Container container) 
  -   { 
  -    this.container = (EntityContainer)container; 
  -   }
  -    
  -   public  Container getContainer()
  -   {
  -    return container;
  -   }
  -
  -   // Interceptor implementation --------------------------------------
  -   public Object invokeHome(MethodInvocation mi)
  -      throws Exception
  -   {
  -      // Get context
  -      
mi.setEnterpriseContext(((EntityContainer)getContainer()).getInstancePool().get());
  -      
  -      try
  -      {
  -         // Invoke through interceptors
  -         return getNext().invokeHome(mi);
  -      } finally
  -      {
  -         // Still free? Not free if create() was called successfully
  -         if (mi.getEnterpriseContext().getId() == null)
  -         {
  -            container.getInstancePool().free(mi.getEnterpriseContext());
  -         } else
  -         {
  -//            Logger.log("Entity was created; not returned to pool");
  -            
((EntityContainer)getContainer()).getInstanceCache().release(mi.getEnterpriseContext());
  -         }
  -      }
  -   }
  -
  -   public Object invoke(MethodInvocation mi)
  -      throws Exception
  -   {
  -       // The id store is a FastKey in the case of Entity 
  -       FastKey fastKey = (FastKey) mi.getId();
  -       
  -      // Get context
  -      // The cache will properly managed the tx-ctx locking, in case the mi 
transaction is different.
  -      
mi.setEnterpriseContext(((EntityContainer)getContainer()).getInstanceCache().get(fastKey));
  -      try
  -      {
  -         // Invoke through interceptors
  -         return getNext().invoke(mi);
  -      } catch (RemoteException e)
  -       {
  -         // Discard instance
  -         // EJB 1.1 spec 12.3.1
  -         ((EntityContainer)getContainer()).getInstanceCache().remove(fastKey.id);
  -         
  -         throw e;
  -       } catch (RuntimeException e)
  -       {
  -         // Discard instance
  -         // EJB 1.1 spec 12.3.1
  -         ((EntityContainer)getContainer()).getInstanceCache().remove(fastKey.id);
  -         
  -         throw e;
  -       } catch (Error e)
  -       {
  -         // Discard instance
  -         // EJB 1.1 spec 12.3.1
  -         ((EntityContainer)getContainer()).getInstanceCache().remove(fastKey.id);
  -         
  -         throw e;
  -       } finally
  -      {
  -//         Logger.log("Release instance for "+id);
  -         EnterpriseContext ctx = mi.getEnterpriseContext();
  -         if (ctx != null)
  -         {
  -          if (ctx.getId() == null)
  -          {
  -             // Remove from cache
  -             
((EntityContainer)getContainer()).getInstanceCache().remove(fastKey.id);
  -             
  -             // It has been removed -> send to free pool
  -             container.getInstancePool().free(ctx);
  -          }
  -          {
  -             // Return context
  -             ((EntityContainer)getContainer()).getInstanceCache().release(ctx);
  -          }
  -         }
  -      }
  -   }
  +     // Constants -----------------------------------------------------
  +     
  +     // Attributes ----------------------------------------------------
  +     protected EntityContainer container;
  +     
  +     // Static --------------------------------------------------------
  +     
  +     // Constructors --------------------------------------------------
  +     
  +     // Public --------------------------------------------------------
  +     public void setContainer(Container container) 
  +     { 
  +             this.container = (EntityContainer)container; 
  +     }
  +     
  +     public  Container getContainer()
  +     {
  +             return container;
  +     }
  +     
  +     // Interceptor implementation --------------------------------------
  +     public Object invokeHome(MethodInvocation mi)
  +     throws Exception
  +     {
  +             // Get context
  +             
mi.setEnterpriseContext(((EntityContainer)getContainer()).getInstancePool().get());
  +             
  +             try
  +             {
  +                     // Invoke through interceptors
  +                     return getNext().invokeHome(mi);
  +             } finally
  +             {
  +                     // Still free? Not free if create() was called successfully
  +                     if (mi.getEnterpriseContext().getId() == null)
  +                     {
  +                             
container.getInstancePool().free(mi.getEnterpriseContext());
  +                     } else
  +                     {
  +                             //            Logger.log("Entity was created; not 
returned to pool");
  +                             
((EntityContainer)getContainer()).getInstanceCache().release(mi.getEnterpriseContext());
  +                     }
  +             }
  +     }
  +     
  +     public Object invoke(MethodInvocation mi)
  +     throws Exception
  +     {
  +             // The id store is a CacheKey in the case of Entity 
  +             CacheKey key = (CacheKey) mi.getId();
  +             
  +             // Get context
  +             // The cache will properly managed the tx-ctx locking, in case the mi 
transaction is different.
  +             
mi.setEnterpriseContext(((EntityContainer)getContainer()).getInstanceCache().get(key));
  +             try
  +             {
  +                     // Invoke through interceptors
  +                     return getNext().invoke(mi);
  +             } catch (RemoteException e)
  +             {
  +                     // Discard instance
  +                     // EJB 1.1 spec 12.3.1
  +                     
((EntityContainer)getContainer()).getInstanceCache().remove(key.id);
  +                     
  +                     throw e;
  +             } catch (RuntimeException e)
  +             {
  +                     // Discard instance
  +                     // EJB 1.1 spec 12.3.1
  +                     
((EntityContainer)getContainer()).getInstanceCache().remove(key.id);
  +                     
  +                     throw e;
  +             } catch (Error e)
  +             {
  +                     // Discard instance
  +                     // EJB 1.1 spec 12.3.1
  +                     
((EntityContainer)getContainer()).getInstanceCache().remove(key.id);
  +                     
  +                     throw e;
  +             } finally
  +             {
  +                     //         Logger.log("Release instance for "+id);
  +                     EnterpriseContext ctx = mi.getEnterpriseContext();
  +                     if (ctx != null)
  +                     {
  +                             if (ctx.getId() == null)
  +                             {
  +                                     // Remove from cache
  +                                     
((EntityContainer)getContainer()).getInstanceCache().remove(key.id);
  +                                     
  +                                     // It has been removed -> send to free pool
  +                                     container.getInstancePool().free(ctx);
  +                             }
  +                             {
  +                                     // Return context
  +                                     
((EntityContainer)getContainer()).getInstanceCache().release(ctx);
  +                             }
  +                     }
  +             }
  +     }
   }
   
  
  
  

Reply via email to