From: Adrian B. <ej...@us...> - 2003-08-30 15:04:33
|
User: ejort Date: 03/08/30 08:04:31 Modified: src/main/org/jboss/test/jca/ejb Tag: Branch_3_2 CachedConnectionSessionBean.java Added: src/main/org/jboss/test/jca/ejb Tag: Branch_3_2 ThreadLocalDB.java Log: Add a test for passing a connection around a unit of work using a thread local. The context that closes the connection is not the one that opened it Revision Changes Path No revision No revision 1.1.4.2 +42 -0 jbosstest/src/main/org/jboss/test/jca/ejb/CachedConnectionSessionBean.java Index: CachedConnectionSessionBean.java =================================================================== RCS file: /cvsroot/jboss/jbosstest/src/main/org/jboss/test/jca/ejb/CachedConnectionSessionBean.java,v retrieving revision 1.1.4.1 retrieving revision 1.1.4.2 diff -u -r1.1.4.1 -r1.1.4.2 --- CachedConnectionSessionBean.java 20 Feb 2003 15:47:24 -0000 1.1.4.1 +++ CachedConnectionSessionBean.java 30 Aug 2003 15:04:31 -0000 1.1.4.2 @@ -18,12 +18,14 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import javax.ejb.EJBException; import javax.ejb.SessionBean; import javax.ejb.SessionContext; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.sql.DataSource; import org.apache.log4j.Category; +import org.jboss.test.jca.interfaces.CachedConnectionSessionLocal; /** * CachedConnectionSessionBean.java @@ -47,6 +49,7 @@ private Connection conn; private Category log = Category.getInstance(getClass().getName()); + private SessionContext ctx; /** * Describe <code>createTable</code> method here. @@ -187,6 +190,44 @@ return conn; } + /** + * Invoke another bean that opens a thread local connection, + * we close it. + * + * @ejb:interface-method + */ + public void firstTLTest() + { + try + { + CachedConnectionSessionLocal other = (CachedConnectionSessionLocal) ctx.getEJBLocalObject(); + other.secondTLTest(); + ThreadLocalDB.close(); + } + catch (Exception e) + { + log.info("Error", e); + throw new EJBException(e.toString()); + } + } + + /** + * @ejb:interface-method + */ + public void secondTLTest() + { + try + { + Connection c = ThreadLocalDB.open(); + c.createStatement().close(); + } + catch (Exception e) + { + log.info("Error", e); + throw new EJBException(e.toString()); + } + } + public void ejbCreate() { } @@ -231,6 +272,7 @@ public void setSessionContext(SessionContext ctx) throws RemoteException { + this.ctx = ctx; } public void unsetSessionContext() throws RemoteException No revision No revision 1.1.2.1 +62 -0 jbosstest/src/main/org/jboss/test/jca/ejb/Attic/ThreadLocalDB.java |