User: docodan
Date: 01/06/04 13:47:29
Modified: src/main/org/jboss/ejb EntityContainer.java
EntityEnterpriseContext.java
Log:
Added support for entity local interfaces.
Revision Changes Path
1.40 +115 -15 jboss/src/main/org/jboss/ejb/EntityContainer.java
Index: EntityContainer.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/EntityContainer.java,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- EntityContainer.java 2001/06/04 15:16:08 1.39
+++ EntityContainer.java 2001/06/04 20:47:29 1.40
@@ -18,7 +18,9 @@
import javax.ejb.Handle;
import javax.ejb.HomeHandle;
import javax.ejb.EJBObject;
+import javax.ejb.EJBLocalObject;
import javax.ejb.EJBHome;
+import javax.ejb.EJBLocalHome;
import javax.ejb.EJBMetaData;
import javax.ejb.EJBException;
import javax.ejb.CreateException;
@@ -37,7 +39,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Sebastien Alborini</a>
* @author Daniel OConnor ([EMAIL PROTECTED])
-* @version $Revision: 1.39 $
+* @version $Revision: 1.40 $
*/
public class EntityContainer
extends Container
@@ -386,7 +388,76 @@
* MF FIXME these are implemented on the client
*/
+ public EJBLocalHome getEJBLocalHome(MethodInvocation mi)
+ {
+ return localContainerInvoker.getEJBLocalHome();
+ }
+
+ public void removeLocalHome(MethodInvocation mi)
+ throws java.rmi.RemoteException, RemoveException
+ {
+ throw new Error("Not Yet Implemented");
+ }
+
+ // Local home interface implementation
+
+ public EJBLocalObject createLocalHome(MethodInvocation mi)
+ throws Exception
+ {
+
+ // The persistence manager takes care of the wiring and creating the
EJBLocalObject
+ getPersistenceManager().createEntity(mi.getMethod(),mi.getArguments(),
+ (EntityEnterpriseContext) mi.getEnterpriseContext());
+
+ // The context implicitely carries the EJBObject
+ return
((EntityEnterpriseContext)mi.getEnterpriseContext()).getEJBLocalObject();
+ }
+
+
+ public Object findLocal(MethodInvocation mi)
+ throws Exception
+ {
+
+ // Multi-finder?
+ if (!mi.getMethod().getReturnType().equals(getLocalClass()))
+ {
+ // Iterator finder
+ Collection c = getPersistenceManager().findEntities(mi.getMethod(),
mi.getArguments(), (EntityEnterpriseContext)mi.getEnterpriseContext());
+
+ // Get the EJBObjects with that
+ Collection ec = localContainerInvoker.getEntityLocalCollection(c);
+
+ // BMP entity finder methods are allowed to return java.util.Enumeration.
+ try {
+ if
(mi.getMethod().getReturnType().equals(Class.forName("java.util.Enumeration")))
+ {
+ return java.util.Collections.enumeration(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 (EJBLocalObject)localContainerInvoker.getEntityEJBLocalObject(id);
+ }
+ }
+
+
// Home interface implementation ---------------------------------
/*
@@ -498,12 +569,10 @@
// Private -------------------------------------------------------
- protected void setupHomeMapping()
- throws DeploymentException
+
+ private void setupHomeMappingImpl( Map map, Method[] m, String finderName,
String append )
+ throws DeploymentException
{
- Map map = new HashMap();
-
- Method[] m = homeInterface.getMethods();
for (int i = 0; i < m.length; i++)
{
try
@@ -522,17 +591,34 @@
// Implemented by container (in both cases)
if (m[i].getName().startsWith("find"))
{
- map.put(m[i], this.getClass().getMethod("find", new Class[] {
MethodInvocation.class }));
+ map.put(m[i], this.getClass().getMethod(finderName, new Class[] {
MethodInvocation.class }));
}else
{
- map.put(m[i], this.getClass().getMethod(m[i].getName()+"Home", new
Class[] { MethodInvocation.class }));
+ map.put(m[i], this.getClass().getMethod(m[i].getName()+append, new
Class[] { MethodInvocation.class }));
}
} catch (NoSuchMethodException e)
{
throw new DeploymentException("Could not find matching method for
"+m[i]);
}
}
+ }
+
+ protected void setupHomeMapping()
+ throws DeploymentException
+ {
+ Map map = new HashMap();
+ if (homeInterface != null)
+ {
+ Method[] m = homeInterface.getMethods();
+ setupHomeMappingImpl( map, m, "find", "Home" );
+ }
+ if (localHomeInterface != null)
+ {
+ Method[] m = localHomeInterface.getMethods();
+ setupHomeMappingImpl( map, m, "findLocal", "LocalHome" );
+ }
+
// Special methods
try {
@@ -574,18 +660,15 @@
// We are done keep the home map
homeMapping = map;
}
-
- protected void setupBeanMapping()
- throws DeploymentException
+
+ private void setupBeanMappingImpl( Map map, Method[] m, String intfName )
+ 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"))
+ if (!m[i].getDeclaringClass().getName().equals(intfName))
{
// Implemented by bean
map.put(m[i], beanClass.getMethod(m[i].getName(),
m[i].getParameterTypes()));
@@ -601,6 +684,23 @@
{
throw new DeploymentException("Could not find matching method for
"+m[i], e);
}
+ }
+ }
+
+ protected void setupBeanMapping()
+ throws DeploymentException
+ {
+ Map map = new HashMap();
+
+ if (remoteInterface != null)
+ {
+ Method[] m = remoteInterface.getMethods();
+ setupBeanMappingImpl( map, m, "javax.ejb.EJBObject" );
+ }
+ if (localInterface != null)
+ {
+ Method[] m = localInterface.getMethods();
+ setupBeanMappingImpl( map, m, "javax.ejb.EJBLocalObject" );
}
beanMapping = map;
1.17 +28 -6 jboss/src/main/org/jboss/ejb/EntityEnterpriseContext.java
Index: EntityEnterpriseContext.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/ejb/EntityEnterpriseContext.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- EntityEnterpriseContext.java 2001/06/04 17:22:24 1.16
+++ EntityEnterpriseContext.java 2001/06/04 20:47:29 1.17
@@ -10,6 +10,8 @@
import javax.ejb.EJBContext;
import javax.ejb.EJBHome;
+import javax.ejb.EJBObject;
+import javax.ejb.EJBLocalObject;
import javax.ejb.EJBLocalObject;
import javax.ejb.EJBObject;
import javax.ejb.EntityBean;
@@ -22,14 +24,16 @@
*
* @see EnterpriseContext
* @author Rickard �berg ([EMAIL PROTECTED])
-* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
-* @version $Revision: 1.16 $
+* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
+* @author Daniel OConnor ([EMAIL PROTECTED])
+* @version $Revision: 1.17 $
*/
public class EntityEnterpriseContext
extends EnterpriseContext
{
// Attributes ----------------------------------------------------
EJBObject ejbObject;
+ EJBLocalObject ejbLocalObject;
EntityContext ctx;
// True if this instance has been invoked since it was synchronized with DB
@@ -90,6 +94,16 @@
return ejbObject;
}
+
+ public void setEJBLocalObject( EJBLocalObject eo )
+ {
+ ejbLocalObject = eo;
+ }
+
+ public EJBLocalObject getEJBLocalObject()
+ {
+ return ejbLocalObject;
+ }
public void setCacheKey(Object key) {
this.key = (CacheKey) key;
@@ -153,10 +167,10 @@
try {
- // Create a new CacheKey
- Object cacheKey = ((EntityCache) ((EntityContainer)
con).getInstanceCache()).createCacheKey( id );
+ // Create a new CacheKey
+ Object cacheKey = ((EntityCache) ((EntityContainer)
con).getInstanceCache()).createCacheKey( id );
- ejbObject =
((EntityContainer)con).getContainerInvoker().getEntityEJBObject(cacheKey);
+ ejbObject =
((EntityContainer)con).getContainerInvoker().getEntityEJBObject(cacheKey);
}
catch (RemoteException re) {
// ...
@@ -169,7 +183,15 @@
public EJBLocalObject getEJBLocalObject()
{
- throw new IllegalStateException();
+ if (ejbLocalObject == null)
+ {
+ Object cacheKey = ((EntityCache) ((EntityContainer)
con).getInstanceCache())
+ .createCacheKey( id );
+ ejbLocalObject = ((EntityContainer)con).getLocalContainerInvoker()
+ .getEntityEJBLocalObject(cacheKey);
+ }
+
+ return ejbLocalObject;
}
public Object getPrimaryKey()
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development