User: fleury
Date: 00/08/24 18:56:28
Modified: src/main/org/jboss/ejb/plugins CMPPersistenceManager.java
Log:
New CMP PM deals with cache keys
Revision Changes Path
1.5 +34 -16 jboss/src/main/org/jboss/ejb/plugins/CMPPersistenceManager.java
Index: CMPPersistenceManager.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/CMPPersistenceManager.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- CMPPersistenceManager.java 2000/08/18 03:20:56 1.4
+++ CMPPersistenceManager.java 2000/08/25 01:56:28 1.5
@@ -10,7 +10,9 @@
import java.lang.reflect.InvocationTargetException;
import java.rmi.RemoteException;
import java.rmi.ServerException;
-import java.util.Collection;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.ArrayList;
import javax.ejb.EntityBean;
import javax.ejb.CreateException;
@@ -21,8 +23,8 @@
import org.jboss.ejb.EntityContainer;
import org.jboss.ejb.EntityPersistenceManager;
import org.jboss.ejb.EntityEnterpriseContext;
+import org.jboss.ejb.EntityInstanceCache;
import org.jboss.ejb.EntityPersistenceStore;
-import org.jboss.util.FastKey;
/**
* The CMP Persistence Manager implements the semantics of the CMP
@@ -33,7 +35,7 @@
*
* @see <related>
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
-* @version $Revision: 1.4 $
+* @version $Revision: 1.5 $
*/
public class CMPPersistenceManager
implements EntityPersistenceManager {
@@ -114,17 +116,17 @@
// Set the key on the target context
ctx.setId(id);
- // Create a new FastKey
- FastKey fastKey = new FastKey(id);
-
- // Pass it implicitely!
- ctx.setFastKey(fastKey);
-
- // Lock instance in cache
- con.getInstanceCache().insert(ctx);
-
+ // Create a new CacheKey
+ Object cacheKey = ((EntityInstanceCache)
con.getInstanceCache()).createCacheKey( id );
+
+ // Give it to the context
+ ctx.setCacheKey(cacheKey);
+
+ // Lock instance in cache
+ ((EntityInstanceCache) con.getInstanceCache()).insert(ctx);
+
// Create EJBObject
- ctx.setEJBObject(con.getContainerInvoker().getEntityEJBObject(fastKey));
+
ctx.setEJBObject(con.getContainerInvoker().getEntityEJBObject(cacheKey));
postCreateMethod.invoke(ctx.getInstance(), args);
@@ -143,13 +145,29 @@
public Object findEntity(Method finderMethod, Object[] args,
EntityEnterpriseContext ctx)
throws RemoteException, FinderException {
- return store.findEntity(finderMethod, args, ctx);
+ // The store will find the entity and return the primaryKey
+ Object id = store.findEntity(finderMethod, args, ctx);
+
+ // We return the cache key
+ return ((EntityInstanceCache) con.getInstanceCache()).createCacheKey(id);
}
public Collection findEntities(Method finderMethod, Object[] args,
EntityEnterpriseContext ctx)
throws RemoteException, FinderException {
-
- return store.findEntities(finderMethod, args, ctx);
+
+ // The store will find the id and return a collection of PrimaryKeys
+ Collection ids = store.findEntities(finderMethod, args, ctx);
+
+ // 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(((EntityInstanceCache)
con.getInstanceCache()).createCacheKey(idEnum.next()));
+ }
+
+ return list;
}
/*