User: danch   
  Date: 01/05/26 17:49:15

  Modified:    src/main/org/jboss/ejb/plugins
                        CMPFilePersistenceManager.java
                        CMPPersistenceManager.java
  Log:
  added 'read-ahead' option for finders in JAWS
  
  Revision  Changes    Path
  1.9       +10 -5     
jboss/src/main/org/jboss/ejb/plugins/CMPFilePersistenceManager.java
  
  Index: CMPFilePersistenceManager.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/CMPFilePersistenceManager.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- CMPFilePersistenceManager.java    2000/12/07 15:44:23     1.8
  +++ CMPFilePersistenceManager.java    2001/05/27 00:49:15     1.9
  @@ -35,6 +35,7 @@
   import org.jboss.ejb.EntityContainer;
   import org.jboss.ejb.EntityPersistenceStore;
   import org.jboss.ejb.EntityEnterpriseContext;
  +import org.jboss.util.FinderResults;
   
   /**
    *   <description> 
  @@ -42,7 +43,7 @@
    *   @see <related>
    *   @author Rickard �berg ([EMAIL PROTECTED])
    *  @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
  - *   @version $Revision: 1.8 $
  + *   @version $Revision: 1.9 $
    */
   public class CMPFilePersistenceManager
      implements EntityPersistenceStore
  @@ -137,7 +138,7 @@
            return null;
      }
        
  -   public Collection findEntities(Method finderMethod, Object[] args, 
EntityEnterpriseContext ctx)
  +   public FinderResults findEntities(Method finderMethod, Object[] args, 
EntityEnterpriseContext ctx)
         throws RemoteException
      {
         if (finderMethod.getName().equals("findAll"))
  @@ -154,10 +155,10 @@
               }
               
   //         Logger.debug("Find all entities done");
  -         return result;
  +         return new FinderResults(result,null,null,null);
         } else
         {
  -         return new java.util.ArrayList();
  +         return new FinderResults(new java.util.ArrayList(),null,null,null);
         }
      }
   
  @@ -191,7 +192,11 @@
         }
      }
         
  -     private void storeEntity(Object id, Object obj) 
  +   public void loadEntities(FinderResults keys) {
  +      //this is a no op for this persistence store.
  +   }
  +   
  +   private void storeEntity(Object id, Object obj) 
        throws RemoteException {
          
         try
  
  
  
  1.19      +69 -39    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.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- CMPPersistenceManager.java        2001/05/02 11:03:16     1.18
  +++ CMPPersistenceManager.java        2001/05/27 00:49:15     1.19
  @@ -15,6 +15,7 @@
   import java.util.Iterator;
   import java.util.ArrayList;
   import java.util.HashMap;
  +import java.util.Map;
   
   import javax.ejb.EntityBean;
   import javax.ejb.CreateException;
  @@ -33,6 +34,9 @@
   import org.jboss.ejb.EntityPersistenceStore;
   import org.jboss.metadata.EntityMetaData;
   
  +import org.jboss.util.FinderResults;
  +import org.jboss.util.Sync;
  +
   /**
   *   The CMP Persistence Manager implements the semantics of the CMP
   *  EJB 1.1 call back specification.
  @@ -42,7 +46,7 @@
   *
   *   @see <related>
   *   @author <a href="mailto:[EMAIL PROTECTED]";>Marc Fleury</a>
  -*   @version $Revision: 1.18 $
  +*   @version $Revision: 1.19 $
   */
   public class CMPPersistenceManager
   implements EntityPersistenceManager {
  @@ -278,21 +282,43 @@
       }
   
       public Collection findEntities(Method finderMethod, Object[] args, 
EntityEnterpriseContext ctx)
  -    throws Exception {
  -
  +        throws Exception 
  +    {
          // The store will find the id and return a collection of PrimaryKeys
  -       Collection ids = store.findEntities(finderMethod, args, ctx);
  +       FinderResults ids = store.findEntities(finderMethod, args, ctx);
  +
  +       AbstractInstanceCache cache = (AbstractInstanceCache)con.getInstanceCache();
  +       Map contextMap = new HashMap();
  +       ArrayList keyList = new ArrayList();
  +       Iterator idEnum = ids.iterator();
  +       while(idEnum.hasNext()) {
  +          Object key = idEnum.next();
  +          Object cacheKey = ((EntityCache)cache).createCacheKey(key);
  +          keyList.add(cacheKey);
  +                   
  +          Sync mutex = (Sync)cache.getLock(cacheKey);
  +          try
  +          {
  +             mutex.acquire();
   
  -       // Build a collection of cacheKeys
  -       ArrayList list = new ArrayList(ids.size());
  -        Iterator idEnum = ids.iterator();
  -        while(idEnum.hasNext()) {
  -
  -         // Get a cache key for it
  -         list.add(((EntityCache) 
con.getInstanceCache()).createCacheKey(idEnum.next()));
  -         }
  +             // Get context
  +             ctx = (EntityEnterpriseContext)cache.get(cacheKey);
  +             // if ctx has a transaction, we skip it - either it's our Tx
  +             //    or we plain don't want to block here.
  +             if (ctx.getTransaction() == null) {
  +                contextMap.put(key, ctx);
  +             } 
  +          } catch (InterruptedException ignored) {
  +          } finally {
  +             mutex.release();
  +          }
  +       }
  +       
  +       ids.setEntityMap(contextMap);
  +       
  +       store.loadEntities(ids);
   
  -       return list;
  +       return keyList;
       }
   
       /*
  @@ -343,33 +369,8 @@
   
           // Have the store load the fields of the instance
           store.loadEntity(ctx);
  -
  -        try {
  -
  -            // Call ejbLoad on bean instance, wake up!
  -            ejbLoad.invoke(ctx.getInstance(), new Object[0]);
   
  -        } catch (IllegalAccessException e)
  -        {
  -             // Throw this as a bean exception...(?)
  -             throw new EJBException(e);
  -        } catch (InvocationTargetException ite)
  -        {
  -             Throwable e = ite.getTargetException();
  -             if (e instanceof RemoteException)
  -             {
  -                     // Rethrow exception
  -                     throw (RemoteException)e;
  -             } else if (e instanceof EJBException)
  -             {
  -                     // Rethrow exception
  -                     throw (EJBException)e;
  -             } else if (e instanceof RuntimeException)
  -             {
  -                     // Wrap runtime exceptions
  -                     throw new EJBException((Exception)e);
  -             }
  -        }
  +        invokeLoad(ctx);
       }
   
       public void storeEntity(EntityEnterpriseContext ctx)
  @@ -468,6 +469,35 @@
           }
   
           store.removeEntity(ctx);
  +    }
  +    
  +    protected void invokeLoad(EntityEnterpriseContext ctx) throws RemoteException { 
       
  +        try {
  +
  +           // Call ejbLoad on bean instance, wake up!
  +           ejbLoad.invoke(ctx.getInstance(), new Object[0]);
  +
  +        } catch (IllegalAccessException e)
  +        {
  +           // Throw this as a bean exception...(?)
  +               throw new EJBException(e);
  +        } catch (InvocationTargetException ite)
  +        {
  +               Throwable e = ite.getTargetException();
  +               if (e instanceof RemoteException)
  +               {
  +                       // Rethrow exception
  +                       throw (RemoteException)e;
  +               } else if (e instanceof EJBException)
  +               {
  +                       // Rethrow exception
  +                       throw (EJBException)e;
  +               } else if (e instanceof RuntimeException)
  +               {
  +                       // Wrap runtime exceptions
  +                       throw new EJBException((Exception)e);
  +               }
  +        }
       }
   
       // Z implementation ----------------------------------------------
  
  
  

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

Reply via email to