From: Adrian B. <ej...@us...> - 2004-04-01 12:10:26
|
User: ejort Date: 04/04/01 03:58:31 Modified: src/main/org/jboss/test/jca/ejb Tag: Branch_3_2 LocalWrapperCleanupTestSessionBean.java Log: Add tests for closing prepared statements Revision Changes Path No revision No revision 1.2.2.5 +104 -0 jbosstest/src/main/org/jboss/test/jca/ejb/LocalWrapperCleanupTestSessionBean.java Index: LocalWrapperCleanupTestSessionBean.java =================================================================== RCS file: /cvsroot/jboss/jbosstest/src/main/org/jboss/test/jca/ejb/LocalWrapperCleanupTestSessionBean.java,v retrieving revision 1.2.2.4 retrieving revision 1.2.2.5 diff -u -r1.2.2.4 -r1.2.2.5 --- LocalWrapperCleanupTestSessionBean.java 25 Oct 2003 02:33:54 -0000 1.2.2.4 +++ LocalWrapperCleanupTestSessionBean.java 1 Apr 2004 11:58:30 -0000 1.2.2.5 @@ -13,6 +13,7 @@ import java.rmi.RemoteException; import java.sql.Connection; +import java.sql.PreparedStatement; import java.sql.Statement; import javax.ejb.EJBException; import javax.ejb.SessionBean; @@ -21,6 +22,8 @@ import javax.sql.DataSource; import org.apache.log4j.Category; import org.jboss.resource.adapter.jdbc.WrappedConnection; + + import java.sql.ResultSet; import javax.transaction.UserTransaction; @@ -429,6 +432,107 @@ /** + * Test duplicate reference to a prepare statement after it has been removed + * from the cache + * + * @exception EJBException if an error occurs + * @ejb:interface-method + * @ejb:transaction type="NotSupported" + */ + public void testDuplicatePreparedStatementCloseAfterCacheRemoval() + { + try + { + DataSource ds = (DataSource)new InitialContext().lookup("java:/SingleConnectionDS"); + Connection c1 = ds.getConnection(); + + Statement s1 = c1.createStatement(); + s1.execute("create table pscachetest (id integer)"); + try + { + // Prepare the statement + PreparedStatement ps1 = c1.prepareStatement("select * from pscachetest"); + // Get a second reference to the prepared statement + PreparedStatement ps2 = c1.prepareStatement("select * from pscachetest"); + // Now force the removal from the cache, it has size two so two new + // prepared statements will remove the first one + PreparedStatement ps3 = c1.prepareStatement("select id from pscachetest"); + PreparedStatement ps4 = c1.prepareStatement("select 1 from pscachetest"); + // Close all the statements except the last one which we will try to use + ps4.close(); + ps3.close(); + ps2.close(); + + ps1.executeQuery().close(); + + // Close the last statement + ps1.close(); + } + finally + { + s1.execute("drop table pscachetest"); + s1.close(); + c1.close(); + } + } + catch (EJBException e) + { + throw e; + } + catch (Exception e) + { + throw new EJBException("Untested problem in test: " + e); + } + + } + + /** + * Test duplicate reference to a prepare statement in the cache + * + * @exception EJBException if an error occurs + * @ejb:interface-method + * @ejb:transaction type="NotSupported" + */ + public void testDuplicatePreparedStatementClose() + { + try + { + DataSource ds = (DataSource)new InitialContext().lookup("java:/SingleConnectionDS"); + Connection c1 = ds.getConnection(); + + Statement s1 = c1.createStatement(); + s1.execute("create table pscachetest (id integer)"); + try + { + // Prepare the statement + PreparedStatement ps1 = c1.prepareStatement("select * from pscachetest"); + // Get a second reference to the prepared statement + PreparedStatement ps2 = c1.prepareStatement("select * from pscachetest"); + ps2.close(); + + // Try to use the statement + ps1.execute(); + ps1.close(); + } + finally + { + s1.execute("drop table pscachetest"); + s1.close(); + c1.close(); + } + } + catch (EJBException e) + { + throw e; + } + catch (Exception e) + { + throw new EJBException("Untested problem in test: " + e); + } + + } + + /** * Describe <code>testTxIsolationInReturnedConnection</code> method here. * * @exception EJBException if an error occurs |