[Jboss-cvs] JBossAS SVN: r55350 - in branches/JBoss_4_0_3_SP1_CP: connector connector/src/main/org/jboss/resource/adapter/jdbc testsuite/src/main/org/jboss/test/jca/ejb testsuite/src/main/org/jboss/test/jca/interfaces testsuite/src/main/org/jboss/test/jca/test testsuite/src/resources/jca/pscache
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sat Aug 5 14:45:30 EDT 2006
Author: ryan.campbell at jboss.com
Date: 2006-08-05 14:45:29 -0400 (Sat, 05 Aug 2006)
New Revision: 55350
Added:
branches/JBoss_4_0_3_SP1_CP/connector/src/main/org/jboss/resource/adapter/jdbc/CachedCallableStatement.java
Modified:
branches/JBoss_4_0_3_SP1_CP/connector/build.xml
branches/JBoss_4_0_3_SP1_CP/connector/src/main/org/jboss/resource/adapter/jdbc/BaseWrapperManagedConnection.java
branches/JBoss_4_0_3_SP1_CP/connector/src/main/org/jboss/resource/adapter/jdbc/PreparedStatementCache.java
branches/JBoss_4_0_3_SP1_CP/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedConnection.java
branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/jca/ejb/PreparedStatementBean.java
branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/jca/interfaces/PreparedStatementRemote.java
branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/jca/test/PSCacheUnitTestCase.java
branches/JBoss_4_0_3_SP1_CP/testsuite/src/resources/jca/pscache/ejb-jar.xml
Log:
JBAS-2671: Patch for JBAS-2584 CallableStatement Caching to JBoss 4.0.3 SP1
Modified: branches/JBoss_4_0_3_SP1_CP/connector/build.xml
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/connector/build.xml 2006-08-05 18:27:45 UTC (rev 55349)
+++ branches/JBoss_4_0_3_SP1_CP/connector/build.xml 2006-08-05 18:45:29 UTC (rev 55350)
@@ -262,8 +262,9 @@
<include name="org/jboss/resource/adapter/jdbc/Null*.class"/>
<include name="org/jboss/resource/adapter/jdbc/Wrap*.class"/>
<include name="org/jboss/resource/adapter/jdbc/BaseWrap*.class"/>
+ <include name="org/jboss/resource/adapter/jdbc/CachedCallableStatement.class"/>
<include name="org/jboss/resource/adapter/jdbc/CachedPreparedStatement.class"/>
- <include name="org/jboss/resource/adapter/jdbc/PreparedStatementCache.class"/>
+ <include name="org/jboss/resource/adapter/jdbc/PreparedStatementCache*.class"/>
<include name="org/jboss/resource/adapter/jdbc/StatementAccess.class"/>
<include name="org/jboss/resource/adapter/jdbc/remote/*"/>
<!-- JBAS-2250 hack -->
Modified: branches/JBoss_4_0_3_SP1_CP/connector/src/main/org/jboss/resource/adapter/jdbc/BaseWrapperManagedConnection.java
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/connector/src/main/org/jboss/resource/adapter/jdbc/BaseWrapperManagedConnection.java 2006-08-05 18:27:45 UTC (rev 55349)
+++ branches/JBoss_4_0_3_SP1_CP/connector/src/main/org/jboss/resource/adapter/jdbc/BaseWrapperManagedConnection.java 2006-08-05 18:45:29 UTC (rev 55350)
@@ -13,6 +13,7 @@
import java.sql.SQLException;
import java.sql.Savepoint;
import java.sql.Statement;
+import java.sql.CallableStatement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
@@ -52,7 +53,7 @@
private final Set handles = new HashSet();
private PreparedStatementCache psCache = null;
- protected Object stateLock = new Object();
+ protected final Object stateLock = new Object();
protected boolean inManagedTransaction = false;
protected boolean jdbcAutoCommit = true;
@@ -292,7 +293,8 @@
{
if (psCache != null)
{
- CachedPreparedStatement cachedps = (CachedPreparedStatement)psCache.get(sql);
+ final PreparedStatementCache.Key key = new PreparedStatementCache.Key(sql, PreparedStatementCache.Key.PREPARED_STATEMENT);
+ CachedPreparedStatement cachedps = (CachedPreparedStatement)psCache.get(key);
if (cachedps != null)
{
if (canUse(cachedps))
@@ -304,7 +306,7 @@
{
PreparedStatement ps = con.prepareStatement(sql);
cachedps = new CachedPreparedStatement(ps);
- psCache.insert(sql, cachedps);
+ psCache.insert(key, cachedps);
}
return cachedps;
}
@@ -480,4 +482,28 @@
connectionError(e);
throw new JBossResourceException("SQLException", e);
}
-}
+
+ public CallableStatement prepareCall(String sql) throws SQLException {
+ if (psCache != null)
+ {
+ final PreparedStatementCache.Key key = new PreparedStatementCache.Key(sql, PreparedStatementCache.Key.CALLABLE_STATEMENT);
+ CachedCallableStatement cachedps = (CachedCallableStatement)psCache.get(key);
+ if (cachedps != null)
+ {
+ if (canUse(cachedps))
+ cachedps.inUse();
+ else
+ return con.prepareCall(sql);
+ }
+ else
+ {
+ CallableStatement cs = con.prepareCall(sql);
+ cachedps = new CachedCallableStatement(cs);
+ psCache.insert(key, cachedps);
+ }
+ return cachedps;
+ }
+ else
+ return con.prepareCall(sql);
+ }
+}
\ No newline at end of file
Copied: branches/JBoss_4_0_3_SP1_CP/connector/src/main/org/jboss/resource/adapter/jdbc/CachedCallableStatement.java (from rev 55349, branches/JBoss_4_0_3_SP1_JBAS-2671/connector/src/main/org/jboss/resource/adapter/jdbc/CachedCallableStatement.java)
Modified: branches/JBoss_4_0_3_SP1_CP/connector/src/main/org/jboss/resource/adapter/jdbc/PreparedStatementCache.java
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/connector/src/main/org/jboss/resource/adapter/jdbc/PreparedStatementCache.java 2006-08-05 18:27:45 UTC (rev 55349)
+++ branches/JBoss_4_0_3_SP1_CP/connector/src/main/org/jboss/resource/adapter/jdbc/PreparedStatementCache.java 2006-08-05 18:45:29 UTC (rev 55350)
@@ -17,11 +17,57 @@
* its not in use.
*
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @author <a href="mailto:adrian at jboss.com">Adrian Brock</a>
+ * @author Scott.Stark at jboss.org
* @version $Revision$
*/
public class PreparedStatementCache extends LRUCachePolicy
{
+ public static class Key
+ {
+ public static final int PREPARED_STATEMENT = 1;
+ public static final int CALLABLE_STATEMENT = 2;
+ private final String sql;
+ private final int type;
+ public Key(String sql, int type)
+ {
+ this.sql = sql;
+ this.type = type;
+ }
+
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ final Key key = (Key) o;
+
+ if (type != key.type) return false;
+ return !(sql != null ? !sql.equals(key.sql) : key.sql != null);
+
+ }
+
+ public int hashCode()
+ {
+ int result;
+ result = (sql != null ? sql.hashCode() : 0);
+ result = 29 * result + type;
+ return result;
+ }
+ public String toString()
+ {
+ StringBuffer tmp = new StringBuffer(super.toString());
+ tmp.append('[');
+ tmp.append("sql=");
+ tmp.append(sql);
+ tmp.append("type=");
+ tmp.append(type==PREPARED_STATEMENT ? "PS" : "CS");
+ tmp.append(']');
+ return tmp.toString();
+ }
+ }
+
private final Logger log = Logger.getLogger(getClass());
public PreparedStatementCache(int max)
Modified: branches/JBoss_4_0_3_SP1_CP/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedConnection.java
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedConnection.java 2006-08-05 18:27:45 UTC (rev 55349)
+++ branches/JBoss_4_0_3_SP1_CP/connector/src/main/org/jboss/resource/adapter/jdbc/WrappedConnection.java 2006-08-05 18:45:29 UTC (rev 55350)
@@ -258,7 +258,7 @@
checkTransaction();
try
{
- return new WrappedCallableStatement(this, mc.getConnection().prepareCall(sql));
+ return new WrappedCallableStatement(this, mc.prepareCall(sql));
}
catch (SQLException e)
{
Modified: branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/jca/ejb/PreparedStatementBean.java
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/jca/ejb/PreparedStatementBean.java 2006-08-05 18:27:45 UTC (rev 55349)
+++ branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/jca/ejb/PreparedStatementBean.java 2006-08-05 18:45:29 UTC (rev 55350)
@@ -13,6 +13,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
+import java.sql.CallableStatement;
import javax.ejb.CreateException;
import javax.ejb.DuplicateKeyException;
import javax.ejb.EJBException;
@@ -297,6 +298,50 @@
return hash;
}
+ public String executeStoredProc(String name)
+ throws RemoteException
+ {
+ String value = null;
+ try
+ {
+ InitialContext ctx = new InitialContext();
+ String query = (String) ctx.lookup("java:comp/env/"+name);
+
+ Connection con = ds.getConnection();
+ try
+ {
+ CallableStatement ps = con.prepareCall(query);
+ try
+ {
+ ResultSet rs = ps.executeQuery();
+ while( rs.next() )
+ {
+ value = rs.getString(1);
+ }
+ rs.close();
+ }
+ finally
+ {
+ ps.close();
+ }
+ }
+ finally
+ {
+ con.close();
+ }
+ }
+ catch (SQLException e)
+ {
+ throw new RemoteException("Failed to execuate CallableStatement", e);
+ }
+ catch (NamingException e)
+ {
+ throw new RemoteException("Failed to lookup query", e);
+ }
+ return value;
+
+ }
+
private void ensureTableExists()
{
boolean exists = true;
Modified: branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/jca/interfaces/PreparedStatementRemote.java
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/jca/interfaces/PreparedStatementRemote.java 2006-08-05 18:27:45 UTC (rev 55349)
+++ branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/jca/interfaces/PreparedStatementRemote.java 2006-08-05 18:45:29 UTC (rev 55350)
@@ -19,4 +19,6 @@
{
public long hashEntityTable()
throws RemoteException;
+ public String executeStoredProc(String name)
+ throws RemoteException;
}
Modified: branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/jca/test/PSCacheUnitTestCase.java
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/jca/test/PSCacheUnitTestCase.java 2006-08-05 18:27:45 UTC (rev 55349)
+++ branches/JBoss_4_0_3_SP1_CP/testsuite/src/main/org/jboss/test/jca/test/PSCacheUnitTestCase.java 2006-08-05 18:45:29 UTC (rev 55350)
@@ -27,8 +27,9 @@
super(name);
}
- public void testBasic() throws Exception
+ public void testBasicPreparedStatement() throws Exception
{
+ log.info("+++ testBasicPreparedStatement");
InitialContext ctx = new InitialContext();
PreparedStatementHome home = (PreparedStatementHome) ctx.lookup("PreparedStatementBean");
PreparedStatementRemote bean = home.create("key1", "name1");
@@ -36,6 +37,17 @@
bean.remove();
}
+ public void testBasicCallableStatement() throws Exception
+ {
+ log.info("+++ testBasicCallableStatement");
+ InitialContext ctx = new InitialContext();
+ PreparedStatementHome home = (PreparedStatementHome) ctx.lookup("PreparedStatementBean");
+ PreparedStatementRemote bean = home.create("key2", "name2");
+ String result = bean.executeStoredProc("callIdentitySQL");
+ log.info("callIdentitySQL result="+result);
+ bean.remove();
+ }
+
public static Test suite() throws Exception
{
return getDeploySetup(PSCacheUnitTestCase.class, "pscache.jar");
Modified: branches/JBoss_4_0_3_SP1_CP/testsuite/src/resources/jca/pscache/ejb-jar.xml
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/testsuite/src/resources/jca/pscache/ejb-jar.xml 2006-08-05 18:27:45 UTC (rev 55349)
+++ branches/JBoss_4_0_3_SP1_CP/testsuite/src/resources/jca/pscache/ejb-jar.xml 2006-08-05 18:45:29 UTC (rev 55350)
@@ -13,6 +13,11 @@
<persistence-type>Bean</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
<reentrant>True</reentrant>
+ <env-entry>
+ <env-entry-name>callIdentitySQL</env-entry-name>
+ <env-entry-type>java.lang.String</env-entry-type>
+ <env-entry-value>call identity()</env-entry-value>
+ </env-entry>
<resource-ref>
<res-ref-name>jdbc/DataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
More information about the jboss-cvs-commits
mailing list