User: fleury
Date: 00/08/17 13:11:14
Modified: src/main/org/jboss/ejb EntityEnterpriseContext.java
EntityContainer.java
Log:
Support for fastCache
Revision Changes Path
1.6 +141 -123 jboss/src/main/org/jboss/ejb/EntityEnterpriseContext.java
Index: EntityEnterpriseContext.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/EntityEnterpriseContext.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- EntityEnterpriseContext.java 2000/08/11 22:11:26 1.5
+++ EntityEnterpriseContext.java 2000/08/17 20:11:13 1.6
@@ -14,6 +14,7 @@
import javax.ejb.EntityContext;
import javax.transaction.Transaction;
+import org.jboss.util.FastKey;
/**
* The EntityEnterpriseContext is used to associate EntityBean instances with
metadata about it.
@@ -21,132 +22,149 @@
* @see EnterpriseContext
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
-* @version $Revision: 1.5 $
+* @version $Revision: 1.6 $
*/
public class EntityEnterpriseContext
extends EnterpriseContext
{
- // Attributes ----------------------------------------------------
- EJBObject ejbObject;
-
- // True if this instance has been invoked since it was synchronized with DB
- // If true, then we have to store it to synch back to DB
- boolean invoked = false;
-
- // True if this instances' state is valid
- // when a bean is called the state is not synchronized with the DB
- // but "valid" as long as the transaction runs
- boolean valid = false;
-
- // The instance cache may attach any metadata it wishes to this context here
- Object cacheCtx;
-
- // The persistence manager may attach any metadata it wishes to this context
here
- Object persistenceCtx;
-
- // Constructors --------------------------------------------------
- public EntityEnterpriseContext(Object instance, Container con)
- throws RemoteException
- {
- super(instance, con);
- ((EntityBean)instance).setEntityContext(new EntityContextImpl());
- }
-
- // Public --------------------------------------------------------
- public void discard()
- throws RemoteException
- {
- ((EntityBean)instance).unsetEntityContext();
- }
-
- public void setEJBObject(EJBObject eo)
- {
- ejbObject = eo;
- }
-
- public EJBObject getEJBObject()
- {
- // Context can have no EJBObject (created by finds) in which case we
need to wire it at call time
-
- return ejbObject;
- }
-
-
- public void setPersistenceContext(Object ctx)
- {
- this.persistenceCtx = ctx;
- }
-
- public Object getPersistenceContext()
- {
- return persistenceCtx;
- }
-
- public void setCacheContext(Object ctx)
- {
- this.cacheCtx = ctx;
- }
-
- public Object getCacheContext()
- {
- return cacheCtx;
- }
-
- public void setInvoked(boolean invoked)
- {
- /*
- System.out.println("&&&&&&&&&&& in setInvoked("+invoked+")");
- Exception e = new Exception();
- e.printStackTrace();
- */
- this.invoked = invoked;
- }
-
- public boolean isInvoked()
- {
- return invoked;
- }
-
- public void setValid(boolean valid)
- {
- /*System.out.println("&&&&&&&&&&& in setSynchronized("+synched+")");
- Exception e = new Exception();
- e.printStackTrace();
- */
- this.valid = valid;
- }
-
- public boolean isValid()
- {
- return valid;
- }
-
- // Inner classes -------------------------------------------------
- protected class EntityContextImpl
- extends EJBContextImpl
- implements EntityContext
- {
- public EJBObject getEJBObject()
- {
- if (ejbObject == null) {
-
- try {
-
- ejbObject =
((EntityContainer)con).getContainerInvoker().getEntityEJBObject(id);
- }
- catch (RemoteException re) {
- // ...
- throw new IllegalStateException();
- }
- }
-
- return ejbObject;
- }
-
- public Object getPrimaryKey()
- {
- return id;
- }
- }
+ // Attributes ----------------------------------------------------
+ EJBObject ejbObject;
+
+ // True if this instance has been invoked since it was synchronized with DB
+ // If true, then we have to store it to synch back to DB
+ boolean invoked = false;
+
+ // True if this instances' state is valid
+ // when a bean is called the state is not synchronized with the DB
+ // but "valid" as long as the transaction runs
+ boolean valid = false;
+
+ // The instance cache may attach any metadata it wishes to this context here
+ Object cacheCtx;
+
+ // The persistence manager may attach any metadata it wishes to this context
here
+ Object persistenceCtx;
+
+ // This is ONLY used at construction time. The association from FastKey to EEC
+ // Is a many to one. the one held here uses the EEC as a "vehicle" nothing more
+ // It usually corresponds to the FastKey of the EJBObject that build it.
+ // It is pretty and we keep the API of the cache.
+ public FastKey fastKey;
+
+ // Constructors --------------------------------------------------
+ public EntityEnterpriseContext(Object instance, Container con)
+ throws RemoteException
+ {
+ super(instance, con);
+ ((EntityBean)instance).setEntityContext(new EntityContextImpl());
+ }
+
+ // Public --------------------------------------------------------
+ public void discard()
+ throws RemoteException
+ {
+ ((EntityBean)instance).unsetEntityContext();
+ }
+
+ public void setEJBObject(EJBObject eo)
+ {
+ ejbObject = eo;
+ }
+
+ public EJBObject getEJBObject()
+ {
+ // Context can have no EJBObject (created by finds) in which case we need to
wire it at call time
+
+ return ejbObject;
+ }
+
+
+ public void setPersistenceContext(Object ctx)
+ {
+ this.persistenceCtx = ctx;
+ }
+
+ public Object getPersistenceContext()
+ {
+ return persistenceCtx;
+ }
+
+ public void setCacheContext(Object ctx)
+ {
+ this.cacheCtx = ctx;
+ }
+
+ public Object getCacheContext()
+ {
+ return cacheCtx;
+ }
+
+ public void setInvoked(boolean invoked)
+ {
+ /*
+ System.out.println("&&&&&&&&&&& in setInvoked("+invoked+")");
+ Exception e = new Exception();
+ e.printStackTrace();
+ */
+ this.invoked = invoked;
+ }
+
+ public boolean isInvoked()
+ {
+ return invoked;
+ }
+
+ public void setValid(boolean valid)
+ {
+ /*System.out.println("&&&&&&&&&&& in setSynchronized("+synched+")");
+ Exception e = new Exception();
+ e.printStackTrace();
+ */
+ this.valid = valid;
+ }
+
+ public boolean isValid()
+ {
+ return valid;
+ }
+
+ public void setFastKey(FastKey fastKey) {
+
+ this.fastKey = fastKey;
+ }
+
+ public FastKey getFastKey() {
+
+ return fastKey;
+ }
+
+
+ // Inner classes -------------------------------------------------
+ protected class EntityContextImpl
+ extends EJBContextImpl
+ implements EntityContext
+ {
+ public EJBObject getEJBObject()
+ {
+ if (ejbObject == null) {
+
+ try {
+
+ ejbObject =
((EntityContainer)con).getContainerInvoker().getEntityEJBObject(new FastKey(id));
+ }
+ catch (RemoteException re) {
+ // ...
+ throw new IllegalStateException();
+ }
+ }
+
+ return ejbObject;
+ }
+
+ public Object getPrimaryKey()
+ {
+ return id;
+ }
+ }
}
1.22 +490 -474 jboss/src/main/org/jboss/ejb/EntityContainer.java
Index: EntityContainer.java
===================================================================
RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/ejb/EntityContainer.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- EntityContainer.java 2000/08/14 15:12:01 1.21
+++ EntityContainer.java 2000/08/17 20:11:13 1.22
@@ -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;
import java.lang.reflect.Method;
@@ -25,25 +25,26 @@
import javax.ejb.RemoveException;
import org.jboss.logging.Logger;
+import org.jboss.util.FastKey;
import org.jboss.util.SerializableEnumeration;
/**
- * This is a Container for EntityBeans (both BMP and CMP).
- *
- * @see Container
- * @see EntityEnterpriseContext
- * @author Rickard �berg ([EMAIL PROTECTED])
- * @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
- * @author <a href="mailto:[EMAIL PROTECTED]">Sebastien Alborini</a>
- * @version $Revision: 1.21 $
- */
+* This is a Container for EntityBeans (both BMP and CMP).
+*
+* @see Container
+* @see EntityEnterpriseContext
+* @author Rickard �berg ([EMAIL PROTECTED])
+* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
+* @author <a href="mailto:[EMAIL PROTECTED]">Sebastien Alborini</a>
+* @version $Revision: 1.22 $
+*/
public class EntityContainer
- extends Container
- implements ContainerInvokerContainer, InstancePoolContainer
+extends Container
+implements ContainerInvokerContainer, InstancePoolContainer
{
- // Constants -----------------------------------------------------
+ // Constants -----------------------------------------------------
- // Attributes ----------------------------------------------------
+ // Attributes ----------------------------------------------------
// These are the mappings between the home interface methods and the container
methods
protected Map homeMapping;
@@ -54,173 +55,173 @@
// This is the container invoker for this container
protected ContainerInvoker containerInvoker;
- // This is the persistence manager for this container
- protected EntityPersistenceManager persistenceManager;
+ // This is the persistence manager for this container
+ protected EntityPersistenceManager persistenceManager;
- // This is the instance cache for this container
- protected InstanceCache instanceCache;
-
- // This is the instancepool that is to be used
- protected InstancePool instancePool;
-
- // This is the first interceptor in the chain. The last interceptor must be
provided by the container itself
- protected Interceptor interceptor;
-
- // Public --------------------------------------------------------
- public void setContainerInvoker(ContainerInvoker ci)
- {
- if (ci == null)
- throw new IllegalArgumentException("Null invoker");
-
- this.containerInvoker = ci;
- ci.setContainer(this);
- }
-
- public ContainerInvoker getContainerInvoker()
- {
- return containerInvoker;
- }
-
- public void setInstancePool(InstancePool ip)
- {
- if (ip == null)
- throw new IllegalArgumentException("Null pool");
-
- this.instancePool = ip;
- ip.setContainer(this);
- }
-
- public InstancePool getInstancePool()
- {
- return instancePool;
- }
-
- public void setInstanceCache(InstanceCache ic)
- {
- if (ic == null)
- throw new IllegalArgumentException("Null cache");
-
- this.instanceCache = ic;
- ic.setContainer(this);
- }
-
- public InstanceCache getInstanceCache()
- {
- return instanceCache;
- }
-
- public EntityPersistenceManager getPersistenceManager()
+ // This is the instance cache for this container
+ protected InstanceCache instanceCache;
+
+ // This is the instancepool that is to be used
+ protected InstancePool instancePool;
+
+ // This is the first interceptor in the chain. The last interceptor must be
provided by the container itself
+ protected Interceptor interceptor;
+
+ // Public --------------------------------------------------------
+ public void setContainerInvoker(ContainerInvoker ci)
+ {
+ if (ci == null)
+ throw new IllegalArgumentException("Null invoker");
+
+ this.containerInvoker = ci;
+ ci.setContainer(this);
+ }
+
+ public ContainerInvoker getContainerInvoker()
+ {
+ return containerInvoker;
+ }
+
+ public void setInstancePool(InstancePool ip)
+ {
+ if (ip == null)
+ throw new IllegalArgumentException("Null pool");
+
+ this.instancePool = ip;
+ ip.setContainer(this);
+ }
+
+ public InstancePool getInstancePool()
+ {
+ return instancePool;
+ }
+
+ public void setInstanceCache(InstanceCache ic)
+ {
+ if (ic == null)
+ throw new IllegalArgumentException("Null cache");
+
+ this.instanceCache = ic;
+ ic.setContainer(this);
+ }
+
+ public InstanceCache getInstanceCache()
+ {
+ return instanceCache;
+ }
+
+ public EntityPersistenceManager getPersistenceManager()
{
return persistenceManager;
}
- public void setPersistenceManager(EntityPersistenceManager pm)
- {
- if (pm == null)
- throw new IllegalArgumentException("Null persistence manager");
-
- persistenceManager = pm;
- pm.setContainer(this);
- }
-
- public void addInterceptor(Interceptor in)
- {
- if (interceptor == null)
- {
- interceptor = in;
- } else
- {
-
- Interceptor current = interceptor;
- while ( current.getNext() != null)
- {
- current = current.getNext();
- }
-
- current.setNext(in);
- }
- }
-
- public Interceptor getInterceptor()
- {
- return interceptor;
- }
-
- public Class getHomeClass()
- {
- return homeInterface;
- }
-
- public Class getRemoteClass()
- {
- return remoteInterface;
- }
-
- // Container implementation --------------------------------------
- public void init()
- throws Exception
- {
+ public void setPersistenceManager(EntityPersistenceManager pm)
+ {
+ if (pm == null)
+ throw new IllegalArgumentException("Null persistence manager");
+
+ persistenceManager = pm;
+ pm.setContainer(this);
+ }
+
+ public void addInterceptor(Interceptor in)
+ {
+ if (interceptor == null)
+ {
+ interceptor = in;
+ } else
+ {
+
+ Interceptor current = interceptor;
+ while ( current.getNext() != null)
+ {
+ current = current.getNext();
+ }
+
+ current.setNext(in);
+ }
+ }
+
+ public Interceptor getInterceptor()
+ {
+ return interceptor;
+ }
+
+ public Class getHomeClass()
+ {
+ return homeInterface;
+ }
+
+ public Class getRemoteClass()
+ {
+ return remoteInterface;
+ }
+
+ // Container implementation --------------------------------------
+ public void init()
+ throws Exception
+ {
// Associate thread with classloader
- ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(getClassLoader());
-
+ ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(getClassLoader());
+
// Acquire classes from CL
homeInterface = classLoader.loadClass(metaData.getHome());
remoteInterface = classLoader.loadClass(metaData.getRemote());
// Call default init
- super.init();
+ super.init();
+
+ // Map the bean methods
+ setupBeanMapping();
- // Map the bean methods
- setupBeanMapping();
-
- // Map the home methods
- setupHomeMapping();
-
- // Initialize pool
- instancePool.init();
-
- // Init container invoker
- containerInvoker.init();
-
- // Init instance cache
- instanceCache.init();
-
- // Init persistence
- persistenceManager.init();
-
- // Initialize the interceptor by calling the chain
- Interceptor in = interceptor;
- while (in != null)
- {
- in.setContainer(this);
- in.init();
- in = in.getNext();
- }
-
- // Reset classloader
- Thread.currentThread().setContextClassLoader(oldCl);
- }
-
- public void start()
- throws Exception
- {
- // Associate thread with classloader
- ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(getClassLoader());
-
+ // Map the home methods
+ setupHomeMapping();
+
+ // Initialize pool
+ instancePool.init();
+
+ // Init container invoker
+ containerInvoker.init();
+
+ // Init instance cache
+ instanceCache.init();
+
+ // Init persistence
+ persistenceManager.init();
+
+ // Initialize the interceptor by calling the chain
+ Interceptor in = interceptor;
+ while (in != null)
+ {
+ in.setContainer(this);
+ in.init();
+ in = in.getNext();
+ }
+
+ // Reset classloader
+ Thread.currentThread().setContextClassLoader(oldCl);
+ }
+
+ public void start()
+ throws Exception
+ {
+ // Associate thread with classloader
+ ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(getClassLoader());
+
// Call default start
- super.start();
-
- // Start container invoker
- containerInvoker.start();
-
- // Start instance cache
- instanceCache.start();
-
- // Start persistence
- persistenceManager.start();
-
+ super.start();
+
+ // Start container invoker
+ containerInvoker.start();
+
+ // Start instance cache
+ instanceCache.start();
+
+ // Start persistence
+ persistenceManager.start();
+
// Start the instance pool
instancePool.start();
@@ -228,197 +229,212 @@
Interceptor in = interceptor;
while (in != null)
{
- in.start();
- in = in.getNext();
+ in.start();
+ in = in.getNext();
}
// Reset classloader
- Thread.currentThread().setContextClassLoader(oldCl);
- }
-
- public void stop()
- {
- // Associate thread with classloader
- ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(getClassLoader());
+ Thread.currentThread().setContextClassLoader(oldCl);
+ }
+
+ public void stop()
+ {
+ // Associate thread with classloader
+ ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(getClassLoader());
// Call default stop
- super.stop();
+ super.stop();
- // Stop container invoker
- containerInvoker.stop();
-
- // Stop instance cache
- instanceCache.stop();
-
- // Stop persistence
- persistenceManager.stop();
-
- // Stop the instance pool
- instancePool.stop();
-
- // Stop all interceptors in the chain
- Interceptor in = interceptor;
- while (in != null)
- {
- in.stop();
- in = in.getNext();
- }
-
- // Reset classloader
- Thread.currentThread().setContextClassLoader(oldCl);
- }
-
- public void destroy()
- {
- // Associate thread with classloader
- ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(getClassLoader());
-
- // Call default destroy
- super.destroy();
-
- // Destroy container invoker
- containerInvoker.destroy();
-
- // Destroy instance cache
- instanceCache.destroy();
-
- // Destroy persistence
- persistenceManager.destroy();
-
- // Destroy the pool
- instancePool.destroy();
-
- // Destroy all the interceptors in the chain
- Interceptor in = interceptor;
- while (in != null)
- {
- in.destroy();
- in = in.getNext();
- }
-
- // Reset classloader
- Thread.currentThread().setContextClassLoader(oldCl);
- }
-
- public Object invokeHome(MethodInvocation mi)
- throws Exception
- {
- return getInterceptor().invokeHome(mi);
- }
-
- public Object invoke(MethodInvocation mi)
- throws Exception
- {
- // Invoke through interceptors
- return getInterceptor().invoke(mi);
- }
-
- // EJBObject implementation --------------------------------------
- public void remove(MethodInvocation mi)
- throws java.rmi.RemoteException, RemoveException
- {
- // Get the persistence manager to do the dirty work
-
getPersistenceManager().removeEntity((EntityEnterpriseContext)mi.getEnterpriseContext());
-
- // We signify "removed" with a null id
- mi.getEnterpriseContext().setId(null);
- }
-
- /**
- * MF FIXME these are implemented on the client
- */
- public Handle getHandle(MethodInvocation mi)
- throws java.rmi.RemoteException
- {
- // TODO
+ // Stop container invoker
+ containerInvoker.stop();
+
+ // Stop instance cache
+ instanceCache.stop();
+
+ // Stop persistence
+ persistenceManager.stop();
+
+ // Stop the instance pool
+ instancePool.stop();
+
+ // Stop all interceptors in the chain
+ Interceptor in = interceptor;
+ while (in != null)
+ {
+ in.stop();
+ in = in.getNext();
+ }
+
+ // Reset classloader
+ Thread.currentThread().setContextClassLoader(oldCl);
+ }
+
+ public void destroy()
+ {
+ // Associate thread with classloader
+ ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(getClassLoader());
+
+ // Call default destroy
+ super.destroy();
+
+ // Destroy container invoker
+ containerInvoker.destroy();
+
+ // Destroy instance cache
+ instanceCache.destroy();
+
+ // Destroy persistence
+ persistenceManager.destroy();
+
+ // Destroy the pool
+ instancePool.destroy();
+
+ // Destroy all the interceptors in the chain
+ Interceptor in = interceptor;
+ while (in != null)
+ {
+ in.destroy();
+ in = in.getNext();
+ }
+
+ // Reset classloader
+ Thread.currentThread().setContextClassLoader(oldCl);
+ }
+
+ public Object invokeHome(MethodInvocation mi)
+ throws Exception
+ {
+ return getInterceptor().invokeHome(mi);
+ }
+
+ public Object invoke(MethodInvocation mi)
+ throws Exception
+ {
+ // Invoke through interceptors
+ return getInterceptor().invoke(mi);
+ }
+
+ // EJBObject implementation --------------------------------------
+ public void remove(MethodInvocation mi)
+ throws java.rmi.RemoteException, RemoveException
+ {
+ // Get the persistence manager to do the dirty work
+
getPersistenceManager().removeEntity((EntityEnterpriseContext)mi.getEnterpriseContext());
+
+ // We signify "removed" with a null id
+ mi.getEnterpriseContext().setId(null);
+ }
+
+ /**
+ * MF FIXME these are implemented on the client
+ */
+ public Handle getHandle(MethodInvocation mi)
+ throws java.rmi.RemoteException
+ {
+ // TODO
throw new Error("Not yet implemented");
- }
-
- public Object getPrimaryKey(MethodInvocation mi)
- throws java.rmi.RemoteException
- {
- // TODO
- throw new Error("Not yet implemented");
- }
-
- public EJBHome getEJBHome(MethodInvocation mi)
- throws java.rmi.RemoteException
- {
- return containerInvoker.getEJBHome();
- }
-
-
- public boolean isIdentical(MethodInvocation mi)
- throws java.rmi.RemoteException
- {
+ }
+
+ public Object getPrimaryKey(MethodInvocation mi)
+ throws java.rmi.RemoteException
+ {
+ // TODO
+ throw new Error("Not yet implemented");
+ }
+
+ public EJBHome getEJBHome(MethodInvocation mi)
+ throws java.rmi.RemoteException
+ {
+ return containerInvoker.getEJBHome();
+ }
+
+
+ public boolean isIdentical(MethodInvocation mi)
+ throws java.rmi.RemoteException
+ {
return
((EJBObject)mi.getArguments()[0]).getPrimaryKey().equals(mi.getEnterpriseContext().getId());
// TODO - should also check type
- }
-
-
- // Home interface implementation ---------------------------------
-
- /*
- * find(MethodInvocation)
- *
- * This methods finds the target instances by delegating to the persistence
manager
- * It then manufactures EJBObject for all the involved instances found
- */
-
- public Object find(MethodInvocation mi)
- throws java.rmi.RemoteException, FinderException
- {
-
- // Multi-finder?
- if (!mi.getMethod().getReturnType().equals(getRemoteClass()))
- {
- // Iterator finder
- Collection c = getPersistenceManager().findEntities(mi.getMethod(),
mi.getArguments(), (EntityEnterpriseContext)mi.getEnterpriseContext());
- Collection ec = containerInvoker.getEntityCollection(c);
+ }
+
+
+ // Home interface implementation ---------------------------------
+
+ /*
+ * find(MethodInvocation)
+ *
+ * This methods finds the target instances by delegating to the persistence
manager
+ * It then manufactures EJBObject for all the involved instances found
+ */
+
+ public Object find(MethodInvocation mi)
+ throws java.rmi.RemoteException, FinderException
+ {
- // BMP entity finder methods are allowed to return java.util.Enumeration.
- // We need a serializable Enumeration, so we can't use
Collections.enumeration()
- try {
- if
(mi.getMethod().getReturnType().equals(Class.forName("java.util.Enumeration"))) {
- return new SerializableEnumeration(ec);
- } else {
- return ec;
- }
- } catch (ClassNotFoundException e) {
- // shouldn't happen
- return ec;
- }
-
- } else
- {
- // Single entity finder
- Object id = getPersistenceManager().findEntity(mi.getMethod(),
- mi.getArguments(),
-
(EntityEnterpriseContext)mi.getEnterpriseContext());
-
- //create the EJBObject
- return (EJBObject)containerInvoker.getEntityEJBObject(id);
- }
- }
-
- /**
- * createHome(MethodInvocation)
- *
- * This method takes care of the wiring of the "EJBObject" trio (target, context,
proxy)
- * It delegates to the persistence manager.
- *
- */
+ // Multi-finder?
+ if (!mi.getMethod().getReturnType().equals(getRemoteClass()))
+ {
+ // Iterator finder
+ Collection c = getPersistenceManager().findEntities(mi.getMethod(),
mi.getArguments(), (EntityEnterpriseContext)mi.getEnterpriseContext());
+ Collection ec = containerInvoker.getEntityCollection(c);
+
+ // BMP entity finder methods are allowed to return
java.util.Enumeration.
+ // We need a serializable Enumeration, so we can't use
Collections.enumeration()
+ try {
+ if
(mi.getMethod().getReturnType().equals(Class.forName("java.util.Enumeration"))) {
+ return new SerializableEnumeration(ec);
+ } else {
+ return ec;
+ }
+ } catch (ClassNotFoundException e) {
+ // shouldn't happen
+ return ec;
+ }
+
+ } else
+ {
+ System.out.println("Single FINDER");
+
+ // Single entity finder
+ Object id = getPersistenceManager().findEntity(mi.getMethod(),
+ mi.getArguments(),
+ (EntityEnterpriseContext)mi.getEnterpriseContext());
+
+ System.out.println("I Found it "+id.toString());
+
+
+ EJBObject ejbObject = null;
+ try {
+ ejbObject = (EJBObject)containerInvoker.getEntityEJBObject(new
FastKey(id));
+ if (ejbObject != null) System.out.println("OBJECT IS OK ABOUT TO
RETURN");
+ return ejbObject;
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ //create the EJBObject
+ //return (EJBObject)containerInvoker.getEntityEJBObject(new
FastKey(id));
+ }
+ }
+ /**
+ * createHome(MethodInvocation)
+ *
+ * This method takes care of the wiring of the "EJBObject" trio (target,
context, proxy)
+ * It delegates to the persistence manager.
+ *
+ */
+
public EJBObject createHome(MethodInvocation mi)
- throws java.rmi.RemoteException, CreateException
+ throws java.rmi.RemoteException, CreateException
{
-
+
getPersistenceManager().createEntity(mi.getMethod(),
- mi.getArguments(),
- (EntityEnterpriseContext) mi.getEnterpriseContext());
- return ((EntityEnterpriseContext)mi.getEnterpriseContext()).getEJBObject();
+ mi.getArguments(),
+ (EntityEnterpriseContext) mi.getEnterpriseContext());
+ return ((EntityEnterpriseContext)mi.getEnterpriseContext()).getEJBObject();
}
/**
@@ -426,38 +442,38 @@
*
*/
public EJBObject getEJBObject(MethodInvocation mi)
- throws java.rmi.RemoteException {
-
+ throws java.rmi.RemoteException {
+
// All we need is an EJBObject for this Id;
- return (EJBObject)containerInvoker.getEntityEJBObject(mi.getId());
+ return (EJBObject)containerInvoker.getEntityEJBObject(new
FastKey(mi.getId()));
}
-
-
-
- // EJBHome implementation ----------------------------------------
-
+
+
+
+ // EJBHome implementation ----------------------------------------
+
// MF The following are implemented on the client
+
+ public void removeHome(MethodInvocation mi)
+ throws java.rmi.RemoteException, RemoveException
+ {
+ throw new Error("Not yet implemented");
+ }
+
+ public EJBMetaData getEJBMetaDataHome(MethodInvocation mi)
+ throws java.rmi.RemoteException
+ {
+ return getContainerInvoker().getEJBMetaData();
+ }
+
+ public HomeHandle getHomeHandleHome(MethodInvocation mi)
+ throws java.rmi.RemoteException
+ {
+ // TODO
+ throw new Error("Not yet implemented");
+ }
- public void removeHome(MethodInvocation mi)
- throws java.rmi.RemoteException, RemoveException
- {
- throw new Error("Not yet implemented");
- }
-
- public EJBMetaData getEJBMetaDataHome(MethodInvocation mi)
- throws java.rmi.RemoteException
- {
- return getContainerInvoker().getEJBMetaData();
- }
-
- public HomeHandle getHomeHandleHome(MethodInvocation mi)
- throws java.rmi.RemoteException
- {
- // TODO
- throw new Error("Not yet implemented");
- }
-
- // Private -------------------------------------------------------
+ // Private -------------------------------------------------------
protected void setupHomeMapping()
throws DeploymentException
{
@@ -512,112 +528,112 @@
homeMapping = map;
}
- protected void setupBeanMapping()
- throws DeploymentException
- {
- Map map = new HashMap();
-
- Method[] m = remoteInterface.getMethods();
- for (int i = 0; i < m.length; i++)
- {
+ protected void setupBeanMapping()
+ throws DeploymentException
+ {
+ Map map = new HashMap();
+
+ Method[] m = remoteInterface.getMethods();
+ for (int i = 0; i < m.length; i++)
+ {
try
+ {
+ if
(!m[i].getDeclaringClass().getName().equals("javax.ejb.EJBObject"))
+ {
+ // Implemented by bean
+ map.put(m[i], beanClass.getMethod(m[i].getName(),
m[i].getParameterTypes()));
+ }
+ else
+ {
+ // Implemented by container
+ map.put(m[i], getClass().getMethod(m[i].getName(), new Class[]
{ MethodInvocation.class }));
+ }
+ } catch (NoSuchMethodException e)
{
- if (!m[i].getDeclaringClass().getName().equals("javax.ejb.EJBObject"))
- {
- // Implemented by bean
- map.put(m[i], beanClass.getMethod(m[i].getName(),
m[i].getParameterTypes()));
- }
- else
- {
- // Implemented by container
- map.put(m[i], getClass().getMethod(m[i].getName(), new Class[] {
MethodInvocation.class }));
- }
- } catch (NoSuchMethodException e)
- {
- throw new DeploymentException("Could not find matching method for
"+m[i], e);
- }
- }
-
- beanMapping = map;
-
- }
-
- public Interceptor createContainerInterceptor()
- {
- return new ContainerInterceptor();
- }
-
+ throw new DeploymentException("Could not find matching method for
"+m[i], e);
+ }
+ }
+
+ beanMapping = map;
+
+ }
+
+ public Interceptor createContainerInterceptor()
+ {
+ return new ContainerInterceptor();
+ }
+
// Inner classes -------------------------------------------------
- // This is the last step before invocation - all interceptors are done
- class ContainerInterceptor
- implements Interceptor
- {
- public void setContainer(Container con) {}
-
- public void setNext(Interceptor interceptor) {}
- public Interceptor getNext() { return null; }
-
- public void init() {}
- public void start() {}
- public void stop() {}
- public void destroy() {}
-
- public Object invokeHome(MethodInvocation mi)
- throws Exception
- {
- // Invoke and handle exceptions
- Method m = (Method)homeMapping.get(mi.getMethod());
-
- try
- {
- return m.invoke(EntityContainer.this, new Object[] { mi });
- } catch (InvocationTargetException e)
- {
- Throwable ex = e.getTargetException();
- if (ex instanceof Exception)
- throw (Exception)ex;
- else
- throw (Error)ex;
- }
- }
-
- public Object invoke(MethodInvocation mi)
- throws Exception
- {
- // Get method
- Method m = (Method)beanMapping.get(mi.getMethod());
-
- // Select instance to invoke (container or bean)
- if (m.getDeclaringClass().equals(EntityContainer.class))
- {
+ // This is the last step before invocation - all interceptors are done
+ class ContainerInterceptor
+ implements Interceptor
+ {
+ public void setContainer(Container con) {}
+
+ public void setNext(Interceptor interceptor) {}
+ public Interceptor getNext() { return null; }
+
+ public void init() {}
+ public void start() {}
+ public void stop() {}
+ public void destroy() {}
+
+ public Object invokeHome(MethodInvocation mi)
+ throws Exception
+ {
// Invoke and handle exceptions
+ Method m = (Method)homeMapping.get(mi.getMethod());
+
try
{
- return m.invoke(EntityContainer.this, new Object[] { mi });
+ return m.invoke(EntityContainer.this, new Object[] { mi });
} catch (InvocationTargetException e)
{
- Throwable ex = e.getTargetException();
- if (ex instanceof Exception)
- throw (Exception)ex;
- else
- throw (Error)ex;
- }
- } else
- {
- // Invoke and handle exceptions
- try
+ Throwable ex = e.getTargetException();
+ if (ex instanceof Exception)
+ throw (Exception)ex;
+ else
+ throw (Error)ex;
+ }
+ }
+
+ public Object invoke(MethodInvocation mi)
+ throws Exception
+ {
+ // Get method
+ Method m = (Method)beanMapping.get(mi.getMethod());
+
+ // Select instance to invoke (container or bean)
+ if (m.getDeclaringClass().equals(EntityContainer.class))
{
- return m.invoke(mi.getEnterpriseContext().getInstance(),
mi.getArguments());
- } catch (InvocationTargetException e)
+ // Invoke and handle exceptions
+ try
+ {
+ return m.invoke(EntityContainer.this, new Object[] { mi });
+ } catch (InvocationTargetException e)
+ {
+ Throwable ex = e.getTargetException();
+ if (ex instanceof Exception)
+ throw (Exception)ex;
+ else
+ throw (Error)ex;
+ }
+ } else
{
- Throwable ex = e.getTargetException();
- if (ex instanceof Exception)
- throw (Exception)ex;
- else
- throw (Error)ex;
- }
- }
- }
- }
+ // Invoke and handle exceptions
+ try
+ {
+ return m.invoke(mi.getEnterpriseContext().getInstance(),
mi.getArguments());
+ } catch (InvocationTargetException e)
+ {
+ Throwable ex = e.getTargetException();
+ if (ex instanceof Exception)
+ throw (Exception)ex;
+ else
+ throw (Error)ex;
+ }
+ }
+ }
+ }
}