User: fleury
Date: 00/09/29 14:25:19
Modified: src/main/org/jboss/ejb/plugins BMPPersistenceManager.java
CMPPersistenceManager.java
EntityInstanceInterceptor.java LogInterceptor.java
StatefulSessionInstanceInterceptor.java
StatelessSessionInstanceInterceptor.java
TxInterceptorBMT.java TxInterceptorCMT.java
Log:
Updated exception handling in entire server
Log is now inherited in child threads (e.g. useful for Tomcat which spawns threads)
Revision Changes Path
1.13 +220 -89 jboss/src/main/org/jboss/ejb/plugins/BMPPersistenceManager.java
Index: BMPPersistenceManager.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/BMPPersistenceManager.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- BMPPersistenceManager.java 2000/09/28 01:17:00 1.12
+++ BMPPersistenceManager.java 2000/09/29 21:25:17 1.13
@@ -14,10 +14,13 @@
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
+import java.util.HashMap;
import javax.ejb.EntityBean;
import javax.ejb.CreateException;
import javax.ejb.FinderException;
+import javax.ejb.RemoveException;
+import javax.ejb.EJBException;
import org.jboss.ejb.Container;
import org.jboss.ejb.EntityContainer;
@@ -33,7 +36,7 @@
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
-* @version $Revision: 1.12 $
+* @version $Revision: 1.13 $
*/
public class BMPPersistenceManager
implements EntityPersistenceManager
@@ -48,6 +51,10 @@
Method ejbActivate;
Method ejbPassivate;
Method ejbRemove;
+
+ HashMap createMethods = new HashMap();
+ HashMap postCreateMethods = new HashMap();
+ HashMap finderMethods = new HashMap();
// Static --------------------------------------------------------
@@ -67,6 +74,26 @@
ejbActivate = EntityBean.class.getMethod("ejbActivate", new Class[0]);
ejbPassivate = EntityBean.class.getMethod("ejbPassivate", new Class[0]);
ejbRemove = EntityBean.class.getMethod("ejbRemove", new Class[0]);
+
+ // Create cache of create methods
+ Method[] methods = con.getHomeClass().getMethods();
+ for (int i = 0; i < methods.length; i++)
+ {
+ if (methods[i].getName().equals("create"))
+ {
+ createMethods.put(methods[i],
con.getBeanClass().getMethod("ejbCreate", methods[i].getParameterTypes()));
+ postCreateMethods.put(methods[i],
con.getBeanClass().getMethod("ejbPostCreate", methods[i].getParameterTypes()));
+ }
+ }
+
+ // Create cache of finder methods
+ for (int i = 0; i < methods.length; i++)
+ {
+ if (methods[i].getName().startsWith("find"))
+ {
+ finderMethods.put(methods[i],
con.getBeanClass().getMethod("ejbF" + methods[i].getName().substring(1),
methods[i].getParameterTypes()));
+ }
+ }
}
public void start()
@@ -84,32 +111,37 @@
public void createEntity(Method m, Object[] args, EntityEnterpriseContext ctx)
throws RemoteException, CreateException
{
- // Get methods
- try
- {
- Method createMethod = null;
- Method postCreateMethod = null;
-
- // try to get the create method
- try {
- createMethod = con.getBeanClass().getMethod("ejbCreate",
m.getParameterTypes());
- } catch (NoSuchMethodException nsme) {
- throw new CreateException("corresponding ejbCreate not found " +
parametersToString(m.getParameterTypes()) + nsme);
- }
+ Method createMethod = (Method)createMethods.get(m);
+ Method postCreateMethod = (Method)postCreateMethods.get(m);
- // try to get the post create method
- try {
- postCreateMethod = con.getBeanClass().getMethod("ejbPostCreate",
m.getParameterTypes());
- } catch (NoSuchMethodException nsme) {
- throw new CreateException("corresponding ejbPostCreate not found " +
parametersToString(m.getParameterTypes()) + nsme);
- }
-
Object id = null;
try {
// Call ejbCreate
id = createMethod.invoke(ctx.getInstance(), args);
- } catch (InvocationTargetException ite) {
- throw new CreateException("Create failed(could not call
ejbCreate):"+ite.getTargetException());
+ } catch (IllegalAccessException e)
+ {
+ // Throw this as a bean exception...(?)
+ throw new EJBException(e);
+ } catch (InvocationTargetException ite)
+ {
+ Throwable e = ite.getTargetException();
+ if (e instanceof CreateException)
+ {
+ // Rethrow exception
+ throw (CreateException)e;
+ } else 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);
+ }
}
// set the id
@@ -129,20 +161,31 @@
try {
postCreateMethod.invoke(ctx.getInstance(), args);
- } catch (InvocationTargetException ite) {
- throw new CreateException("Create failed(could not call ejbPostCreate):"
+ ite.getTargetException());
+ } catch (IllegalAccessException e)
+ {
+ // Throw this as a bean exception...(?)
+ throw new EJBException(e);
+ } catch (InvocationTargetException ite)
+ {
+ Throwable e = ite.getTargetException();
+ if (e instanceof CreateException)
+ {
+ // Rethrow exception
+ throw (CreateException)e;
+ } else 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);
+ }
}
-
- // } catch (InvocationTargetException e)
- // {
- // throw new CreateException("Create failed:"+e);
- // } catch (NoSuchMethodException e)
- // {
- // throw new CreateException("Create methods not found:"+e);
- } catch (IllegalAccessException e)
- {
- throw new CreateException("Could not create entity:"+e);
- }
}
public Object findEntity(Method finderMethod, Object[] args,
EntityEnterpriseContext ctx)
@@ -198,13 +241,30 @@
public void activateEntity(EntityEnterpriseContext ctx)
throws RemoteException
{
- try
- {
- ejbActivate.invoke(ctx.getInstance(), new Object[0]);
- } catch (Exception e)
- {
- throw new ServerException("Activate failed", e);
- }
+ try
+ {
+ ejbActivate.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);
+ }
+ }
}
public void loadEntity(EntityEnterpriseContext ctx)
@@ -213,10 +273,27 @@
try
{
ejbLoad.invoke(ctx.getInstance(), new Object[0]);
- } catch (Exception e)
- {
- throw new ServerException("Load failed", e);
- }
+ } 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);
+ }
+ }
}
public void storeEntity(EntityEnterpriseContext ctx)
@@ -226,10 +303,27 @@
try
{
ejbStore.invoke(ctx.getInstance(), new Object[0]);
- } catch (Exception e)
- {
- throw new ServerException("Store failed", e);
- }
+ } 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);
+ }
+ }
}
public void passivateEntity(EntityEnterpriseContext ctx)
@@ -238,22 +332,60 @@
try
{
ejbPassivate.invoke(ctx.getInstance(), new Object[0]);
- } catch (Exception e)
- {
- throw new ServerException("Passivate failed", e);
- }
+ } 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);
+ }
+ }
}
public void removeEntity(EntityEnterpriseContext ctx)
- throws RemoteException
+ throws RemoteException, RemoveException
{
try
{
ejbRemove.invoke(ctx.getInstance(), new Object[0]);
- } catch (Exception e)
- {
- throw new ServerException("Remove failed", e);
- }
+ } catch (IllegalAccessException e)
+ {
+ // Throw this as a bean exception...(?)
+ throw new EJBException(e);
+ } catch (InvocationTargetException ite)
+ {
+ Throwable e = ite.getTargetException();
+ if (e instanceof RemoveException)
+ {
+ // Rethrow exception
+ throw (RemoveException)e;
+ } else 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 ----------------------------------------------
@@ -266,46 +398,45 @@
throws RemoteException, FinderException
{
// get the finder method
- Method callMethod = null;
- try {
- callMethod = getFinderMethod(con.getBeanClass(), finderMethod, args);
- } catch (NoSuchMethodException me) {
- // debug
- //Logger.exception(me);
- throw new RemoteException("couldn't find finder method in bean class. " +
me.toString());
+ Method callMethod = (Method)finderMethods.get(finderMethod);
+
+ if (callMethod == null) {
+ throw new RemoteException("couldn't find finder method in bean class. " +
finderMethod.toString());
}
// invoke the finder method
Object result = null;
try {
result = callMethod.invoke(ctx.getInstance(), args);
- } catch (InvocationTargetException e) {
- Throwable targetException = e.getTargetException();
- if (targetException instanceof FinderException) {
- throw (FinderException)targetException;
- }
- else {
- throw new ServerException("exception occured while invoking finder
method", (Exception)targetException);
- }
- } catch (Exception e) {
- // debug
- // DEBUG Logger.exception(e);
- throw new ServerException("exception occured while invoking finder
method",e);
- }
+ } catch (IllegalAccessException e)
+ {
+ // Throw this as a bean exception...(?)
+ throw new EJBException(e);
+ } catch (InvocationTargetException ite)
+ {
+ Throwable e = ite.getTargetException();
+ if (e instanceof FinderException)
+ {
+ // Rethrow exception
+ throw (FinderException)e;
+ } else 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);
+ }
+ }
return result;
}
- private Method getFinderMethod(Class beanClass, Method finderMethod, Object[]
args) throws NoSuchMethodException {
- String methodName = "ejbF" + finderMethod.getName().substring(1);
- return beanClass.getMethod(methodName, finderMethod.getParameterTypes());
- }
-
- private String parametersToString(Object []a) {
- String r = new String();
- for(int i=0;i<a.length;i++) r = r + ", " + a[i];
- return r;
- }
// Inner classes -------------------------------------------------
}
1.10 +204 -62 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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- CMPPersistenceManager.java 2000/09/28 01:17:01 1.9
+++ CMPPersistenceManager.java 2000/09/29 21:25:17 1.10
@@ -13,11 +13,13 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.ArrayList;
+import java.util.HashMap;
import javax.ejb.EntityBean;
import javax.ejb.CreateException;
import javax.ejb.FinderException;
import javax.ejb.RemoveException;
+import javax.ejb.EJBException;
import org.jboss.ejb.Container;
import org.jboss.ejb.EntityContainer;
@@ -35,7 +37,7 @@
*
* @see <related>
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
-* @version $Revision: 1.9 $
+* @version $Revision: 1.10 $
*/
public class CMPPersistenceManager
implements EntityPersistenceManager {
@@ -53,6 +55,9 @@
Method ejbPassivate;
Method ejbRemove;
+ HashMap createMethods = new HashMap();
+ HashMap postCreateMethods = new HashMap();
+
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
@@ -81,7 +86,18 @@
ejbPassivate = EntityBean.class.getMethod("ejbPassivate", new Class[0]);
ejbRemove = EntityBean.class.getMethod("ejbRemove", new Class[0]);
- // Initialize the sto re
+ // Create cache of create methods
+ Method[] methods = con.getHomeClass().getMethods();
+ for (int i = 0; i < methods.length; i++)
+ {
+ if (methods[i].getName().equals("create"))
+ {
+ createMethods.put(methods[i],
con.getBeanClass().getMethod("ejbCreate", methods[i].getParameterTypes()));
+ postCreateMethods.put(methods[i],
con.getBeanClass().getMethod("ejbPostCreate", methods[i].getParameterTypes()));
+ }
+ }
+
+ // Initialize the store
store.init();
}
@@ -102,44 +118,85 @@
public void createEntity(Method m, Object[] args, EntityEnterpriseContext ctx)
throws RemoteException, CreateException {
// Get methods
- try {
-
- Method createMethod = con.getBeanClass().getMethod("ejbCreate",
m.getParameterTypes());
- Method postCreateMethod = con.getBeanClass().getMethod("ejbPostCreate",
m.getParameterTypes());
-
- // Call ejbCreate on the target bean
- createMethod.invoke(ctx.getInstance(), args);
-
- // Have the store persist the new instance, the return is the key
- Object id = store.createEntity(m, args, ctx);
+ Method createMethod = (Method)createMethods.get(m);
+ Method postCreateMethod = (Method)postCreateMethods.get(m);
- // Set the key on the target context
- ctx.setId(id);
-
- // Create a new CacheKey
- Object cacheKey = ((EntityInstanceCache)
con.getInstanceCache()).createCacheKey( id );
-
- // Give it to the context
- ctx.setCacheKey(cacheKey);
-
- // insert instance in cache, it is safe
- ((EntityInstanceCache) con.getInstanceCache()).insert(ctx);
-
- // Create EJBObject
-
ctx.setEJBObject(con.getContainerInvoker().getEntityEJBObject(cacheKey));
+ // Call ejbCreate on the target bean
+ try {
- postCreateMethod.invoke(ctx.getInstance(), args);
-
- }
- catch (InvocationTargetException e) {
- throw new CreateException("Create failed:"+e.getTargetException());
- }
- catch (NoSuchMethodException e) {
- throw new CreateException("Create methods not found:"+e);
- }
- catch (IllegalAccessException e) {
- throw new CreateException("Could not create entity:"+e);
+ createMethod.invoke(ctx.getInstance(), args);
+ } catch (IllegalAccessException e)
+ {
+ // Throw this as a bean exception...(?)
+ throw new EJBException(e);
+ } catch (InvocationTargetException ite)
+ {
+ Throwable e = ite.getTargetException();
+ if (e instanceof CreateException)
+ {
+ // Rethrow exception
+ throw (CreateException)e;
+ } else 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);
+ }
}
+
+ // Have the store persist the new instance, the return is the key
+ Object id = store.createEntity(m, args, ctx);
+
+ // Set the key on the target context
+ ctx.setId(id);
+
+ // Create a new CacheKey
+ Object cacheKey = ((EntityInstanceCache)
con.getInstanceCache()).createCacheKey( id );
+
+ // Give it to the context
+ ctx.setCacheKey(cacheKey);
+
+ // insert instance in cache, it is safe
+ ((EntityInstanceCache) con.getInstanceCache()).insert(ctx);
+
+ // Create EJBObject
+ ctx.setEJBObject(con.getContainerInvoker().getEntityEJBObject(cacheKey));
+
+ try
+ {
+ postCreateMethod.invoke(ctx.getInstance(), args);
+ } catch (IllegalAccessException e)
+ {
+ // Throw this as a bean exception...(?)
+ throw new EJBException(e);
+ } catch (InvocationTargetException ite)
+ {
+ Throwable e = ite.getTargetException();
+ if (e instanceof CreateException)
+ {
+ // Rethrow exception
+ throw (CreateException)e;
+ } else 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);
+ }
+ }
}
public Object findEntity(Method finderMethod, Object[] args,
EntityEnterpriseContext ctx)
@@ -188,27 +245,62 @@
try
{
ejbActivate.invoke(ctx.getInstance(), new Object[0]);
- } catch (Exception e)
+ } catch (IllegalAccessException e)
+ {
+ // Throw this as a bean exception...(?)
+ throw new EJBException(e);
+ } catch (InvocationTargetException ite)
{
- throw new ServerException("Activation failed", e);
+ 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);
+ }
}
- store.activateEntity(ctx);
+ store.activateEntity(ctx);
}
public void loadEntity(EntityEnterpriseContext ctx)
throws RemoteException {
+ // Have the store load the fields of the instance
+ store.loadEntity(ctx);
+
try {
- // Have the store deal with create the fields of the instance
- store.loadEntity(ctx);
-
// Call ejbLoad on bean instance, wake up!
ejbLoad.invoke(ctx.getInstance(), new Object[0]);
- }
- catch (Exception e) {
- throw new ServerException("Load failed", e);
+
+ } 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);
+ }
}
}
@@ -219,14 +311,31 @@
// Prepare the instance for storage
ejbStore.invoke(ctx.getInstance(), new Object[0]);
-
- // Have the store deal with storing the fields of the instance
- store.storeEntity(ctx);
- }
-
- catch (Exception e) {
- throw new ServerException("Store failed", e);
+ } 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);
+ }
}
+
+ // Have the store deal with storing the fields of the instance
+ store.storeEntity(ctx);
+
}
public void passivateEntity(EntityEnterpriseContext ctx)
@@ -236,10 +345,26 @@
// Prepare the instance for passivation
ejbPassivate.invoke(ctx.getInstance(), new Object[0]);
- }
- catch (Exception e) {
-
- throw new ServerException("Passivation failed", e);
+ } 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);
+ }
}
store.passivateEntity(ctx);
@@ -249,17 +374,34 @@
throws RemoteException, RemoveException {
try {
-
+
// Call ejbRemove
ejbRemove.invoke(ctx.getInstance(), new Object[0]);
- }
- catch (Exception e){
-
- throw new RemoveException("Could not remove "+ctx.getId());
+ } 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);
+ }
}
store.removeEntity(ctx);
}
+
// Z implementation ----------------------------------------------
// Package protected ---------------------------------------------
1.13 +8 -11
jboss/src/main/org/jboss/ejb/plugins/EntityInstanceInterceptor.java
Index: EntityInstanceInterceptor.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/EntityInstanceInterceptor.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- EntityInstanceInterceptor.java 2000/09/28 01:17:01 1.12
+++ EntityInstanceInterceptor.java 2000/09/29 21:25:18 1.13
@@ -35,6 +35,7 @@
import org.jboss.ejb.MethodInvocation;
import org.jboss.ejb.CacheKey;
import org.jboss.metadata.EntityMetaData;
+import org.jboss.logging.Logger;
/**
* This container acquires the given instance.
@@ -42,7 +43,7 @@
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="[EMAIL PROTECTED]">Marc Fleury</a>
-* @version $Revision: 1.12 $
+* @version $Revision: 1.13 $
*/
public class EntityInstanceInterceptor
extends AbstractInterceptor
@@ -131,7 +132,10 @@
// Let's put the thread to sleep a lock
release will wake the thread
synchronized (ctx)
{
- try{ctx.wait();}
+ // Possible deadlock
+ Logger.log("LOCKING-WAITING for id
"+ctx.getId()+" ctx.hash "+ctx.hashCode()+" tx.hash "+ctx.hashCode());
+
+ try{ctx.wait(5000);}
catch (InterruptedException
ie) {}
}
@@ -150,16 +154,9 @@
{
if (!isCallAllowed(mi)) {
- // Let's put the thread to sleep a
lock release will wake the thread
- synchronized (ctx)
- {
- try{ctx.wait();}
- catch
(InterruptedException ie) {}
- }
+ // Not allowed reentrant call
+ throw new RemoteException("Reentrant
call");
- // Try your luck again
- ctx = null;
- continue;
} else
{
//take it!
1.9 +72 -11 jboss/src/main/org/jboss/ejb/plugins/LogInterceptor.java
Index: LogInterceptor.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/LogInterceptor.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- LogInterceptor.java 2000/09/28 01:17:01 1.8
+++ LogInterceptor.java 2000/09/29 21:25:18 1.9
@@ -8,6 +8,7 @@
import java.lang.reflect.Method;
import java.rmi.RemoteException;
+import java.rmi.ServerException;
import java.util.Map;
import java.util.HashMap;
import java.util.Enumeration;
@@ -16,9 +17,11 @@
import javax.ejb.HomeHandle;
import javax.ejb.EJBObject;
import javax.ejb.EJBMetaData;
+import javax.ejb.EJBException;
import javax.ejb.CreateException;
import javax.ejb.FinderException;
import javax.ejb.RemoveException;
+import javax.transaction.TransactionRolledbackException;
import org.jboss.ejb.Container;
import org.jboss.ejb.EnterpriseContext;
@@ -33,7 +36,7 @@
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.8 $
+ * @version $Revision: 1.9 $
*/
public class LogInterceptor
extends AbstractInterceptor
@@ -73,6 +76,9 @@
// Should we log all calls?
callLogging =
getContainer().getBeanMetaData().getContainerConfiguration().getCallLogging();
+ // DEBUG
+ callLogging = true;
+
log = new Log(name);
}
@@ -103,14 +109,40 @@
return getNext().invokeHome(mi);
} catch (Exception e)
{
- // Log system exceptions
- if (e instanceof RemoteException ||
- e instanceof RuntimeException)
+ // Log system exceptions
+ if (e instanceof EJBException)
+ {
+ Logger.error("BEAN EXCEPTION:"+e.getMessage());
+ if (((EJBException)e).getCausedByException() != null)
+
Logger.exception(((EJBException)e).getCausedByException());
+
+ // Client sees RemoteException
+ throw new ServerException("Bean exception. Notify the
application administrator", e);
+ } else if (e instanceof RuntimeException)
+ {
+ Logger.error("CONTAINER EXCEPTION:"+e.getMessage());
+ Logger.exception(e);
+
+ // Client sees RemoteException
+ throw new ServerException("Container exception. Notify the
container developers :-)", e);
+ } else if (e instanceof TransactionRolledbackException)
+ {
+ Logger.error("TRANSACTION ROLLBACK EXCEPTION:"+e.getMessage());
+ // Log the rollback cause
+ Logger.exception(((RemoteException)e).detail);
+
+ throw e;
+ } else
+ {
+ // Application exception, or (in case of RemoteException)
already handled system exc
+ // Call debugging -> show exceptions
+ if (callLogging)
{
- Logger.log(e.getMessage());
+ Logger.warning(e.getMessage());
}
- throw e;
+ throw e;
+ }
} finally
{
Log.unsetLog();
@@ -156,11 +188,40 @@
return getNext().invoke(mi);
} catch (Exception e)
{
- // RO TODO: make a finer grained exception logging, the app stuff needs to
go through and the server stuff needs to be logged
- log.exception(e);
- if (e.getMessage() != null)
- log.log(e.getMessage());
- throw e;
+ // Log system exceptions
+ if (e instanceof EJBException)
+ {
+ Logger.error("BEAN EXCEPTION:"+e.getMessage());
+ if (((EJBException)e).getCausedByException() != null)
+
Logger.exception(((EJBException)e).getCausedByException());
+
+ // Client sees RemoteException
+ throw new ServerException("Bean exception. Notify the
application administrator", e);
+ } else if (e instanceof RuntimeException)
+ {
+ Logger.error("CONTAINER EXCEPTION:"+e.getMessage());
+ Logger.exception(e);
+
+ // Client sees RemoteException
+ throw new ServerException("Container exception. Notify the
container developers :-)", e);
+ } else if (e instanceof TransactionRolledbackException)
+ {
+ Logger.error("TRANSACTION ROLLBACK EXCEPTION:"+e.getMessage());
+ // Log the rollback cause
+ Logger.exception(((RemoteException)e).detail);
+
+ throw e;
+ } else
+ {
+ // Application exception, or (in case of RemoteException)
already handled system exc
+ // Call debugging -> show exceptions
+ if (callLogging)
+ {
+ Logger.warning(e.getMessage());
+ }
+
+ throw e;
+ }
} finally
{
Log.unsetLog();
1.9 +2 -5
jboss/src/main/org/jboss/ejb/plugins/StatefulSessionInstanceInterceptor.java
Index: StatefulSessionInstanceInterceptor.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/StatefulSessionInstanceInterceptor.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- StatefulSessionInstanceInterceptor.java 2000/09/28 01:17:02 1.8
+++ StatefulSessionInstanceInterceptor.java 2000/09/29 21:25:18 1.9
@@ -32,7 +32,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 StatefulSessionInstanceInterceptor
extends AbstractInterceptor
@@ -155,11 +155,8 @@
//take it!
ctx.lock();
- }
-
- else
+ } else
{
-
// Calls must be in the same transaction
throw new RemoteException("Application Error: no
concurrent calls on stateful beans");
}
1.4 +17 -5
jboss/src/main/org/jboss/ejb/plugins/StatelessSessionInstanceInterceptor.java
Index: StatelessSessionInstanceInterceptor.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/StatelessSessionInstanceInterceptor.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- StatelessSessionInstanceInterceptor.java 2000/09/26 18:58:32 1.3
+++ StatelessSessionInstanceInterceptor.java 2000/09/29 21:25:18 1.4
@@ -39,7 +39,7 @@
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
*/
public class StatelessSessionInstanceInterceptor
extends AbstractInterceptor
@@ -68,6 +68,7 @@
public Object invokeHome(MethodInvocation mi)
throws Exception
{
+ // We don't need an instance since the call will be handled by container
return getNext().invokeHome(mi);
}
@@ -84,12 +85,23 @@
{
// Invoke through interceptors
return getNext().invoke(mi);
- } finally
+ } catch (RuntimeException e) // Instance will be GC'ed at MI return
{
- // Return context
- container.getInstancePool().free(mi.getEnterpriseContext());
+ throw e;
+ } catch (RemoteException e) // Instance will be GC'ed at MI return
+ {
+ throw e;
+ } catch (Error e) // Instance will be GC'ed at MI return
+ {
+ throw e;
+ } catch (Exception e)
+ {
+ // Application exception
+ // Return context
+ container.getInstancePool().free(mi.getEnterpriseContext());
+
+ throw e;
}
-
}
}
1.5 +43 -1 jboss/src/main/org/jboss/ejb/plugins/TxInterceptorBMT.java
Index: TxInterceptorBMT.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/TxInterceptorBMT.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TxInterceptorBMT.java 2000/09/28 02:31:41 1.4
+++ TxInterceptorBMT.java 2000/09/29 21:25:18 1.5
@@ -49,7 +49,7 @@
* @see <related>
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Sebastien Alborini</a>
-* @version $Revision: 1.4 $
+* @version $Revision: 1.5 $
*/
public class TxInterceptorBMT
extends AbstractInterceptor
@@ -133,6 +133,27 @@
return getNext().invokeHome(mi);
+ } catch (RuntimeException e)
+ {
+ // EJB 2.0 17.3, table 16
+ if (mi.getEnterpriseContext().getTransaction() != null)
+
mi.getEnterpriseContext().getTransaction().setRollbackOnly();
+
+ throw new ServerException("Transaction rolled back",
e);
+ } catch (RemoteException e)
+ {
+ // EJB 2.0 17.3, table 16
+ if (mi.getEnterpriseContext().getTransaction() != null)
+
mi.getEnterpriseContext().getTransaction().setRollbackOnly();
+
+ throw new ServerException("Transaction rolled back",
e);
+ } catch (Error e)
+ {
+ // EJB 2.0 17.3, table 16
+ if (mi.getEnterpriseContext().getTransaction() != null)
+
mi.getEnterpriseContext().getTransaction().setRollbackOnly();
+
+ throw new ServerException("Transaction rolled
back:"+e.getMessage());
} finally {
// Reset user Tx
@@ -207,6 +228,27 @@
return getNext().invoke(mi);
+ } catch (RuntimeException e)
+ {
+ // EJB 2.0 17.3, table 16
+ if (mi.getEnterpriseContext().getTransaction() != null)
+
mi.getEnterpriseContext().getTransaction().setRollbackOnly();
+
+ throw new ServerException("Transaction rolled back", e);
+ } catch (RemoteException e)
+ {
+ // EJB 2.0 17.3, table 16
+ if (mi.getEnterpriseContext().getTransaction() != null)
+
mi.getEnterpriseContext().getTransaction().setRollbackOnly();
+
+ throw new ServerException("Transaction rolled back", e);
+ } catch (Error e)
+ {
+ // EJB 2.0 17.3, table 16
+ if (mi.getEnterpriseContext().getTransaction() != null)
+
mi.getEnterpriseContext().getTransaction().setRollbackOnly();
+
+ throw new ServerException("Transaction rolled
back:"+e.getMessage());
} finally {
// Reset user Tx
1.4 +52 -6 jboss/src/main/org/jboss/ejb/plugins/TxInterceptorCMT.java
Index: TxInterceptorCMT.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/TxInterceptorCMT.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TxInterceptorCMT.java 2000/09/28 01:17:02 1.3
+++ TxInterceptorCMT.java 2000/09/29 21:25:18 1.4
@@ -18,6 +18,7 @@
import javax.transaction.TransactionManager;
import javax.transaction.RollbackException;
import javax.transaction.TransactionRequiredException;
+import javax.transaction.TransactionRolledbackException;
import javax.transaction.SystemException;
import javax.ejb.EJBException;
@@ -39,7 +40,7 @@
* @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.3 $
+* @version $Revision: 1.4 $
*/
public class TxInterceptorCMT
extends AbstractInterceptor
@@ -126,11 +127,56 @@
}
private Object invokeNext(boolean remoteInvocation, MethodInvocation mi) throws
Exception {
- if (remoteInvocation) {
- return getNext().invoke(mi);
- } else {
- return getNext().invokeHome(mi);
- }
+ try
+ {
+ if (remoteInvocation) {
+ return getNext().invoke(mi);
+ } else {
+ return getNext().invokeHome(mi);
+ }
+ } catch (RuntimeException e)
+ {
+ // EJB 2.0 17.3, table 15
+ if (mi.getEnterpriseContext().getTransaction() != null)
+ {
+
mi.getEnterpriseContext().getTransaction().setRollbackOnly();
+ RemoteException tre = new
TransactionRolledbackException(e.getMessage());
+ tre.detail = e;
+ throw tre;
+ } else
+ {
+ // This exception will be transformed into a
RemoteException by the LogInterceptor
+ throw e;
+ }
+ } catch (RemoteException e)
+ {
+ // EJB 2.0 17.3, table 15
+ if (mi.getEnterpriseContext().getTransaction() != null)
+ {
+
mi.getEnterpriseContext().getTransaction().setRollbackOnly();
+ RemoteException tre = new
TransactionRolledbackException(e.getMessage());
+ tre.detail = e;
+ throw tre;
+ } else
+ {
+ // This exception will be transformed into a
RemoteException by the LogInterceptor
+ throw e;
+ }
+ } catch (Error e)
+ {
+ // EJB 2.0 17.3, table 15
+ if (mi.getEnterpriseContext().getTransaction() != null)
+ {
+
mi.getEnterpriseContext().getTransaction().setRollbackOnly();
+ RemoteException tre = new
TransactionRolledbackException(e.getMessage());
+ tre.detail = e;
+ throw tre;
+ } else
+ {
+ // This exception will be transformed into a
RemoteException by the LogInterceptor
+ throw e;
+ }
+ }
}
/*