[JBoss-dev] CVS update: jboss/src/main/org/jboss/ejb/plugins CMPFilePersistenceManager.java CMPPersistenceManager.java

2001-12-01 Thread Dain Sundstrom

  User: dsundstrom
  Date: 01/12/01 16:05:44

  Modified:src/main/org/jboss/ejb/plugins
CMPFilePersistenceManager.java
CMPPersistenceManager.java
  Log:
  Moved createBeanInstance and initEntity back into the PersistenceStore.
  
  Revision  ChangesPath
  1.14  +118 -54   
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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- CMPFilePersistenceManager.java2001/11/24 20:43:22 1.13
  +++ CMPFilePersistenceManager.java2001/12/02 00:05:44 1.14
  @@ -17,14 +17,14 @@
   import java.io.IOException;
   import java.lang.reflect.Method;
   import java.lang.reflect.Field;
  -import java.rmi.RemoteException;
  -import java.rmi.ServerException;
   import java.util.ArrayList;
  +import java.util.Iterator;
   
   import javax.ejb.EJBObject;
   import javax.ejb.Handle;
   import javax.ejb.CreateException;
   import javax.ejb.DuplicateKeyException;
  +import javax.ejb.EJBException;
   import javax.ejb.FinderException;
   import javax.ejb.RemoveException;
   
  @@ -32,20 +32,22 @@
   import org.jboss.ejb.EntityContainer;
   import org.jboss.ejb.EntityPersistenceStore;
   import org.jboss.ejb.EntityEnterpriseContext;
  +import org.jboss.metadata.EntityMetaData;
   import org.jboss.util.FinderResults;
   
   /**
  -* 
  -*  
  -*   @see 
  -*   @author mailto:[EMAIL PROTECTED]";>Rickard Öberg
  -*   @author mailto:[EMAIL PROTECTED]";>Marc Fleury
  -*   @version $Revision: 1.13 $
  -*   20010801 marc fleury:
  -*   
  -*   - insertion in cache upon create in now done in the instance interceptor
  -*   
  -*/
  + * @author mailto:[EMAIL PROTECTED]";>Rickard Öberg
  + * @author mailto:[EMAIL PROTECTED]";>Marc Fleury
  + * @version $Revision: 1.14 $
  + * 20010801 marc fleury:
  + * 
  + * - insertion in cache upon create in now done in the instance interceptor
  + * 
  + * 20011201 Dain Sundstrom:
  + * 
  + * - added createBeanInstance and initiEntity methods
  + * 
  + */
   public class CMPFilePersistenceManager
  implements EntityPersistenceStore
   {
  @@ -53,14 +55,6 @@
   
  // Attributes 
  EntityContainer con;
  -   
  -   /* The Methods are taken care of by CMPPersistenceManager
  -   Method ejbStore;
  -   Method ejbLoad;
  -   Method ejbActivate;
  -   Method ejbPassivate;
  -   Method ejbRemove;
  -   */
  File dir;
  Field idField;
   
  @@ -77,15 +71,6 @@
  public void init()
 throws Exception
  {
  -// The methods are now taken care of by CMPPersistenceManager
  -   /*
  -  ejbStore = EntityBean.class.getMethod("ejbStore", new Class[0]);
  -  ejbLoad = EntityBean.class.getMethod("ejbLoad", new Class[0]);
  -  ejbActivate = EntityBean.class.getMethod("ejbActivate", new Class[0]);
  -  ejbPassivate = EntityBean.class.getMethod("ejbPassivate", new Class[0]);
  -  ejbRemove = EntityBean.class.getMethod("ejbRemove", new Class[0]);
  -   */
  -   
 String ejbName = con.getBeanMetaData().getEjbName();
 dir = new 
File(getClass().getResource("/db/"+ejbName+"/db.properties").getFile()).getParentFile();
 idField = con.getBeanClass().getField("id");
  @@ -103,7 +88,94 @@
  {
  }
  
  -   public Object createEntity(Method m, Object[] args, EntityEnterpriseContext ctx)
  +   public Object createBeanClassInstance() throws Exception {
  +  return con.getBeanClass().newInstance();
  +   }
  +
  +   /**
  +* 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).
  +*/
  +   public void initEntity(EntityEnterpriseContext ctx)
  +   {
  +  // first get cmp metadata of this entity
  +  Object instance = ctx.getInstance();
  +  Class ejbClass = instance.getClass();
  +  Field cmpField;
  +  Class cmpFieldType;
  +
  +  EntityMetaData metaData = (EntityMetaData)con.getBeanMetaData();
  +  Iterator i= metaData.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 de

[JBoss-dev] CVS update: jboss/src/main/org/jboss/ejb/plugins CMPFilePersistenceManager.java CMPPersistenceManager.java

2001-05-26 Thread danch

  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  ChangesPath
  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.java2000/12/07 15:44:23 1.8
  +++ CMPFilePersistenceManager.java2001/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;
   
   /**
*
  @@ -42,7 +43,7 @@
*   @see 
*   @author Rickard Öberg ([EMAIL PROTECTED])
*  @author mailto:[EMAIL PROTECTED]";>Marc Fleury
  - *   @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 -39jboss/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.java2001/05/02 11:03:16 1.18
  +++ CMPPersistenceManager.java2001/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 
   *   @author mailto:[EMAIL PROTECTED]";>Marc Fleury
  -*   @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()));
  - }