User: oberg
Date: 00/10/09 13:15:39
Modified: src/main/org/jboss/ejb/plugins AbstractInstancePool.java
BMPPersistenceManager.java
CMPFilePersistenceManager.java
CMPPersistenceManager.java
EntityInstanceInterceptor.java
EntityInstancePool.java
NoPassivationEntityInstanceCache.java
NoPassivationStatefulSessionInstanceCache.java
SingletonStatelessSessionInstancePool.java
StatefulSessionFilePersistenceManager.java
StatefulSessionInstancePool.java
StatelessSessionInstancePool.java
Log:
Updated exception handling. Thanks to Paul Austin for insights on this!
Revision Changes Path
1.6 +7 -5 jboss/src/main/org/jboss/ejb/plugins/AbstractInstancePool.java
Index: AbstractInstancePool.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/AbstractInstancePool.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AbstractInstancePool.java 2000/09/30 00:59:40 1.5
+++ AbstractInstancePool.java 2000/10/09 20:15:36 1.6
@@ -31,7 +31,7 @@
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
public abstract class AbstractInstancePool
implements InstancePool, XmlLoadable
@@ -92,7 +92,7 @@
* @exception RemoteException
*/
public synchronized EnterpriseContext get()
- throws RemoteException
+ throws Exception
{
//DEBUG Logger.debug("Get instance "+this);
@@ -103,7 +103,7 @@
{
try
{
- return create(container.getBeanClass().newInstance(), container);
+ return create(container.getBeanClass().newInstance());
} catch (InstantiationException e)
{
throw new ServerException("Could not instantiate bean", e);
@@ -128,6 +128,8 @@
// Pool it
//DEBUG Logger.debug("Free instance:"+ctx.getId()+"#"+ctx.getTransaction());
+ ctx.clear();
+
if (pool.size() < maxSize)
{
pool.push(ctx);
@@ -164,8 +166,8 @@
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
- protected abstract EnterpriseContext create(Object instance, Container con)
- throws RemoteException;
+ protected abstract EnterpriseContext create(Object instance)
+ throws Exception;
// Private -------------------------------------------------------
1.15 +4 -4 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.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- BMPPersistenceManager.java 2000/09/30 00:59:40 1.14
+++ BMPPersistenceManager.java 2000/10/09 20:15:36 1.15
@@ -36,7 +36,7 @@
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
-* @version $Revision: 1.14 $
+* @version $Revision: 1.15 $
*/
public class BMPPersistenceManager
implements EntityPersistenceManager
@@ -109,7 +109,7 @@
}
public void createEntity(Method m, Object[] args, EntityEnterpriseContext ctx)
- throws RemoteException, CreateException
+ throws Exception
{
Method createMethod = (Method)createMethods.get(m);
Method postCreateMethod = (Method)postCreateMethods.get(m);
@@ -189,7 +189,7 @@
}
public Object findEntity(Method finderMethod, Object[] args,
EntityEnterpriseContext ctx)
- throws RemoteException, FinderException
+ throws Exception
{
// call the finder method
Object objectId = callFinderMethod(finderMethod, args, ctx);
@@ -199,7 +199,7 @@
}
public Collection findEntities(Method finderMethod, Object[] args,
EntityEnterpriseContext ctx)
- throws RemoteException, FinderException
+ throws Exception
{
// call the finder method
Object result = callFinderMethod(finderMethod, args, ctx);
1.7 +2 -2
jboss/src/main/org/jboss/ejb/plugins/CMPFilePersistenceManager.java
Index: CMPFilePersistenceManager.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/CMPFilePersistenceManager.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- CMPFilePersistenceManager.java 2000/09/30 00:59:40 1.6
+++ CMPFilePersistenceManager.java 2000/10/09 20:15:37 1.7
@@ -42,7 +42,7 @@
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
- * @version $Revision: 1.6 $
+ * @version $Revision: 1.7 $
*/
public class CMPFilePersistenceManager
implements EntityPersistenceStore
@@ -102,7 +102,7 @@
}
public Object createEntity(Method m, Object[] args, EntityEnterpriseContext ctx)
- throws RemoteException, CreateException
+ throws Exception
{
try {
1.11 +22 -24 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.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- CMPPersistenceManager.java 2000/09/29 21:25:17 1.10
+++ CMPPersistenceManager.java 2000/10/09 20:15:37 1.11
@@ -37,7 +37,7 @@
*
* @see <related>
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
-* @version $Revision: 1.10 $
+* @version $Revision: 1.11 $
*/
public class CMPPersistenceManager
implements EntityPersistenceManager {
@@ -116,7 +116,7 @@
}
public void createEntity(Method m, Object[] args, EntityEnterpriseContext ctx)
- throws RemoteException, CreateException {
+ throws Exception {
// Get methods
Method createMethod = (Method)createMethods.get(m);
Method postCreateMethod = (Method)postCreateMethods.get(m);
@@ -132,15 +132,7 @@
} 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)
+ if (e instanceof EJBException)
{
// Rethrow exception
throw (EJBException)e;
@@ -148,8 +140,15 @@
{
// Wrap runtime exceptions
throw new EJBException((Exception)e);
+ } else if (e instanceof Exception)
+ {
+ // Remote, Create, or custom app. exception
+ throw (Exception)e;
+ } else
+ {
+ throw (Error)e;
}
- }
+ }
// Have the store persist the new instance, the return is the key
Object id = store.createEntity(m, args, ctx);
@@ -179,28 +178,27 @@
} catch (InvocationTargetException ite)
{
Throwable e = ite.getTargetException();
- if (e instanceof CreateException)
+ if (e instanceof EJBException)
{
// 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);
+ } else if (e instanceof Exception)
+ {
+ // Remote, Create, or custom app. exception
+ throw (Exception)e;
+ } else
+ {
+ throw (Error)e;
}
- }
+ }
}
public Object findEntity(Method finderMethod, Object[] args,
EntityEnterpriseContext ctx)
- throws RemoteException, FinderException {
+ throws Exception {
// The store will find the entity and return the primaryKey
Object id = store.findEntity(finderMethod, args, ctx);
@@ -210,7 +208,7 @@
}
public Collection findEntities(Method finderMethod, Object[] args,
EntityEnterpriseContext ctx)
- throws RemoteException, FinderException {
+ throws Exception {
// The store will find the id and return a collection of PrimaryKeys
Collection ids = store.findEntities(finderMethod, args, ctx);
1.16 +1 -2
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.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- EntityInstanceInterceptor.java 2000/10/08 08:32:53 1.15
+++ EntityInstanceInterceptor.java 2000/10/09 20:15:37 1.16
@@ -43,7 +43,7 @@
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="[EMAIL PROTECTED]">Marc Fleury</a>
-* @version $Revision: 1.15 $
+* @version $Revision: 1.16 $
*/
public class EntityInstanceInterceptor
extends AbstractInterceptor
@@ -134,7 +134,6 @@
{
// Possible deadlock
Transaction tx = ctx.getTransaction();
-
Logger.log("LOCKING-WAITING for id "+ctx.getId()+" ctx.hash
"+ctx.hashCode()+" tx:"+((tx == null) ? "null" : tx.toString()));
try{ctx.wait(5000);}
1.7 +5 -4 jboss/src/main/org/jboss/ejb/plugins/EntityInstancePool.java
Index: EntityInstancePool.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/EntityInstancePool.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- EntityInstancePool.java 2000/09/26 20:18:50 1.6
+++ EntityInstancePool.java 2000/10/09 20:15:37 1.7
@@ -8,6 +8,8 @@
import java.rmi.RemoteException;
+import javax.ejb.EJBException;
+
import org.jboss.ejb.Container;
import org.jboss.ejb.EnterpriseContext;
import org.jboss.ejb.EntityEnterpriseContext;
@@ -18,7 +20,7 @@
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
- * @version $Revision: 1.6 $
+ * @version $Revision: 1.7 $
*/
public class EntityInstancePool
extends AbstractInstancePool
@@ -63,10 +65,9 @@
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
- protected EnterpriseContext create(Object instance, Container con)
- throws RemoteException
+ protected EnterpriseContext create(Object instance)
+ throws Exception
{
- // MF FIXME why pass con and then use getContainer()
return new EntityEnterpriseContext(instance, getContainer());
}
1.15 +2 -2
jboss/src/main/org/jboss/ejb/plugins/NoPassivationEntityInstanceCache.java
Index: NoPassivationEntityInstanceCache.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/NoPassivationEntityInstanceCache.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- NoPassivationEntityInstanceCache.java 2000/09/30 00:59:40 1.14
+++ NoPassivationEntityInstanceCache.java 2000/10/09 20:15:37 1.15
@@ -38,7 +38,7 @@
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Andy Schaefer</a>
-* @version $Revision: 1.14 $
+* @version $Revision: 1.15 $
*/
public class NoPassivationEntityInstanceCache
implements EntityInstanceCache
@@ -97,7 +97,7 @@
*/
public synchronized EnterpriseContext get(Object id)
- throws RemoteException
+ throws Exception
{
// Use the CacheKey for the rest of the method
1.13 +2 -2
jboss/src/main/org/jboss/ejb/plugins/NoPassivationStatefulSessionInstanceCache.java
Index: NoPassivationStatefulSessionInstanceCache.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/NoPassivationStatefulSessionInstanceCache.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- NoPassivationStatefulSessionInstanceCache.java 2000/09/30 00:59:41 1.12
+++ NoPassivationStatefulSessionInstanceCache.java 2000/10/09 20:15:37 1.13
@@ -32,7 +32,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 NoPassivationStatefulSessionInstanceCache
implements InstanceCache
@@ -80,7 +80,7 @@
}
public synchronized EnterpriseContext get(Object id)
- throws RemoteException
+ throws Exception
{
//DEBUG Logger.debug("Stateful cache looking for ID "+id);
1.5 +3 -3
jboss/src/main/org/jboss/ejb/plugins/SingletonStatelessSessionInstancePool.java
Index: SingletonStatelessSessionInstancePool.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/SingletonStatelessSessionInstancePool.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SingletonStatelessSessionInstancePool.java 2000/08/18 03:20:57 1.4
+++ SingletonStatelessSessionInstancePool.java 2000/10/09 20:15:37 1.5
@@ -29,7 +29,7 @@
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*/
public class SingletonStatelessSessionInstancePool
implements InstancePool, XmlLoadable
@@ -85,7 +85,7 @@
* @exception RemoteException
*/
public synchronized EnterpriseContext get()
- throws RemoteException
+ throws Exception
{
// Wait while someone else is using it
while(inUse && isSynchronized)
@@ -156,7 +156,7 @@
// Protected -----------------------------------------------------
protected EnterpriseContext create(Object instance, Container con)
- throws RemoteException
+ throws Exception
{
return new StatelessSessionEnterpriseContext(instance, con);
}
1.11 +120 -31
jboss/src/main/org/jboss/ejb/plugins/StatefulSessionFilePersistenceManager.java
Index: StatefulSessionFilePersistenceManager.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/StatefulSessionFilePersistenceManager.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- StatefulSessionFilePersistenceManager.java 2000/09/28 01:17:01 1.10
+++ StatefulSessionFilePersistenceManager.java 2000/10/09 20:15:37 1.11
@@ -41,6 +41,7 @@
import javax.ejb.DuplicateKeyException;
import javax.ejb.FinderException;
import javax.ejb.RemoveException;
+import javax.ejb.EJBException;
import javax.naming.Context;
import javax.naming.InitialContext;
@@ -60,7 +61,7 @@
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="[EMAIL PROTECTED]">Marc Fleury</a>
- * @version $Revision: 1.10 $
+ * @version $Revision: 1.11 $
*/
public class StatefulSessionFilePersistenceManager
implements StatefulSessionPersistenceManager
@@ -100,8 +101,11 @@
// Initialize the dataStore
String ejbName = con.getBeanMetaData().getEjbName();
- File database = new File("database");
+ // Base dir
+ File databaseDir = new
File(getClass().getResource("/db.properties").getFile()).getParentFile();
+ File database = new File(databaseDir, "sessions");
+
dir = new File(database, ejbName);
dir.mkdirs();
@@ -131,7 +135,7 @@
}
public void createSession(Method m, Object[] args,
StatefulSessionEnterpriseContext ctx)
- throws RemoteException, CreateException
+ throws Exception
{
// Get methods
try
@@ -141,25 +145,39 @@
// Call ejbCreate
createMethod.invoke(ctx.getInstance(), args);
- // Set id
- ctx.setId(nextId());
-
- // Insert in cache
- ((StatefulSessionContainer)con).getInstanceCache().insert(ctx);
-
- // Create EJBObject
-
ctx.setEJBObject(con.getContainerInvoker().getStatefulSessionEJBObject(ctx.getId()));
-
- } 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);
- }
+ {
+ // Throw this as a bean exception...(?)
+ throw new EJBException(e);
+ } catch (InvocationTargetException ite)
+ {
+ Throwable e = ite.getTargetException();
+ if (e instanceof EJBException)
+ {
+ // Rethrow exception
+ throw (EJBException)e;
+ } else if (e instanceof RuntimeException)
+ {
+ // Wrap runtime exceptions
+ throw new EJBException((Exception)e);
+ } else if (e instanceof Exception)
+ {
+ // Remote, Create, or custom app. exception
+ throw (Exception)e;
+ } else
+ {
+ throw (Error)e;
+ }
+ }
+
+ // Set id
+ ctx.setId(nextId());
+
+ // Insert in cache
+ ((StatefulSessionContainer)con).getInstanceCache().insert(ctx);
+
+ // Create EJBObject
+
ctx.setEJBObject(con.getContainerInvoker().getStatefulSessionEJBObject(ctx.getId()));
}
public void activateSession(StatefulSessionEnterpriseContext ctx)
@@ -181,10 +199,36 @@
// Call bean
ejbActivate.invoke(ctx.getInstance(), new Object[0]);
- } catch (Exception e)
+ } catch (ClassNotFoundException e)
+ {
+ throw new ServerException("Could not activate", e);
+ } catch (IOException e)
{
- throw new ServerException("Activation failed", e);
- }
+ throw new ServerException("Could not activate", e);
+ } catch (IllegalAccessException e)
+ {
+ // Throw this as a bean exception...(?)
+ throw new EJBException(e);
+ } catch (InvocationTargetException ite)
+ {
+ Throwable e = ite.getTargetException();
+ if (e instanceof EJBException)
+ {
+ // Rethrow exception
+ throw (EJBException)e;
+ } else if (e instanceof RuntimeException)
+ {
+ // Wrap runtime exceptions
+ throw new EJBException((Exception)e);
+ } else if (e instanceof RemoteException)
+ {
+ // Remote, Create, or custom app. exception
+ throw (RemoteException)e;
+ } else
+ {
+ throw (Error)e;
+ }
+ }
}
public void passivateSession(StatefulSessionEnterpriseContext ctx)
@@ -205,10 +249,33 @@
out.writeObject(fields[i].get(ctx.getInstance()));
out.close();
- } catch (Exception e)
+ } catch (IOException e)
{
- throw new ServerException("Passivation failed", e);
- }
+ throw new ServerException("Could not passivate", e);
+ }catch (IllegalAccessException e)
+ {
+ // Throw this as a bean exception...(?)
+ throw new EJBException(e);
+ } catch (InvocationTargetException ite)
+ {
+ Throwable e = ite.getTargetException();
+ if (e instanceof EJBException)
+ {
+ // Rethrow exception
+ throw (EJBException)e;
+ } else if (e instanceof RuntimeException)
+ {
+ // Wrap runtime exceptions
+ throw new EJBException((Exception)e);
+ } else if (e instanceof RemoteException)
+ {
+ // Remote, Create, or custom app. exception
+ throw (RemoteException)e;
+ } else
+ {
+ throw (Error)e;
+ }
+ }
}
public void removeSession(StatefulSessionEnterpriseContext ctx)
@@ -218,10 +285,32 @@
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 EJBException)
+ {
+ // Rethrow exception
+ throw (EJBException)e;
+ } else if (e instanceof RuntimeException)
+ {
+ // Wrap runtime exceptions
+ throw new EJBException((Exception)e);
+ } else if (e instanceof RemoveException)
+ {
+ throw (RemoveException)e;
+ } else if (e instanceof RemoteException)
+ {
+ throw (RemoteException)e;
+ } else
+ {
+ throw (Error)e;
+ }
+ }
}
// Z implementation ----------------------------------------------
1.3 +3 -3
jboss/src/main/org/jboss/ejb/plugins/StatefulSessionInstancePool.java
Index: StatefulSessionInstancePool.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/StatefulSessionInstancePool.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- StatefulSessionInstancePool.java 2000/08/08 21:14:42 1.2
+++ StatefulSessionInstancePool.java 2000/10/09 20:15:38 1.3
@@ -17,7 +17,7 @@
*
* @see <related>
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
-* @version $Revision: 1.2 $
+* @version $Revision: 1.3 $
*/
public class StatefulSessionInstancePool
extends AbstractInstancePool
@@ -38,8 +38,8 @@
}
// Protected -----------------------------------------------------
- protected EnterpriseContext create(Object instance, Container con)
- throws RemoteException
+ protected EnterpriseContext create(Object instance)
+ throws Exception
{
// The instance is created by the caller and is a newInstance();
return new StatefulSessionEnterpriseContext(instance, getContainer());
1.3 +4 -4
jboss/src/main/org/jboss/ejb/plugins/StatelessSessionInstancePool.java
Index: StatelessSessionInstancePool.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/StatelessSessionInstancePool.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- StatelessSessionInstancePool.java 2000/08/12 00:40:46 1.2
+++ StatelessSessionInstancePool.java 2000/10/09 20:15:38 1.3
@@ -17,7 +17,7 @@
*
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class StatelessSessionInstancePool
extends AbstractInstancePool
@@ -41,10 +41,10 @@
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
- protected EnterpriseContext create(Object instance, Container con)
- throws RemoteException
+ protected EnterpriseContext create(Object instance)
+ throws Exception
{
- return new StatelessSessionEnterpriseContext(instance, con);
+ return new StatelessSessionEnterpriseContext(instance, getContainer());
}
// Private -------------------------------------------------------