User: mulder
Date: 00/08/30 09:17:07
Modified: src/main/org/jboss/minerva/xa XAClientConnection.java
XAConnectionImpl.java
Log:
Cache PreparedStatements for each Connection. The JDBC 1/2 wrappers
automatically clean this up for each Connection as it is closed. We need
to think about how to handle clearing the cache when a Connection is closed
for a native JDBC 2 Standard Extension implementation.
Revision Changes Path
1.2 +37 -7 jboss/src/main/org/jboss/minerva/xa/XAClientConnection.java
Index: XAClientConnection.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/minerva/xa/XAClientConnection.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XAClientConnection.java 2000/06/02 13:48:47 1.1
+++ XAClientConnection.java 2000/08/30 16:17:06 1.2
@@ -6,10 +6,22 @@
*/
package org.jboss.minerva.xa;
-import java.sql.*;
-import java.util.*;
-import org.jboss.minerva.jdbc.*;
-import org.jboss.minerva.pools.*;
+import java.sql.Connection;
+import java.sql.CallableStatement;
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.SQLWarning;
+import java.sql.Statement;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Vector;
+import org.jboss.minerva.jdbc.ConnectionWrapper;
+import org.jboss.minerva.jdbc.PreparedStatementInPool;
+import org.jboss.minerva.jdbc.PSCacheKey;
+import org.jboss.minerva.jdbc.StatementInPool;
/**
* Wrapper for database connections used by an XAConnection. When close is
@@ -18,7 +30,7 @@
* returned to the pool) until the transactional details are taken care of.
* This instance only lives as long as one client is using it - though we
* probably want to consider reusing it to save object allocations.
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
* @author Aaron Mulder ([EMAIL PROTECTED])
*/
public class XAClientConnection implements ConnectionWrapper {
@@ -101,7 +113,16 @@
public PreparedStatement prepareStatement(String sql) throws SQLException {
if(con == null) throw new SQLException(CLOSED);
try {
- return con.prepareStatement(sql);
+ PreparedStatement ps =
(PreparedStatement)PreparedStatementInPool.preparedStatementCache.get(
+ new PSCacheKey(con, sql));
+ if(ps == null) {
+ ps = con.prepareStatement(sql);
+ PreparedStatementInPool.preparedStatementCache.put(
+ new PSCacheKey(con, sql), ps);
+ }
+ PreparedStatementInPool wrapper = new PreparedStatementInPool(ps, this);
+ statements.add(wrapper);
+ return wrapper;
} catch(SQLException e) {
setError(e);
throw e;
@@ -296,7 +317,16 @@
public PreparedStatement prepareStatement(String sql, int resultSetType, int
resultSetConcurrency) throws SQLException {
if(con == null) throw new SQLException(CLOSED);
try {
- return con.prepareStatement(sql, resultSetType, resultSetConcurrency);
+ PreparedStatement ps =
(PreparedStatement)PreparedStatementInPool.preparedStatementCache.get(
+ new PSCacheKey(con, sql));
+ if(ps == null) {
+ ps = con.prepareStatement(sql, resultSetType, resultSetConcurrency);
+ PreparedStatementInPool.preparedStatementCache.put(
+ new PSCacheKey(con, sql), ps);
+ }
+ PreparedStatementInPool wrapper = new PreparedStatementInPool(ps, this);
+ statements.add(wrapper);
+ return wrapper;
} catch(SQLException e) {
setError(e);
throw e;
1.3 +13 -1 jboss/src/main/org/jboss/minerva/xa/XAConnectionImpl.java
Index: XAConnectionImpl.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/minerva/xa/XAConnectionImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XAConnectionImpl.java 2000/06/09 15:11:14 1.2
+++ XAConnectionImpl.java 2000/08/30 16:17:07 1.3
@@ -7,9 +7,13 @@
package org.jboss.minerva.xa;
import java.sql.*;
+import java.util.Iterator;
+import java.util.Map;
import java.util.Vector;
import javax.sql.*;
import javax.transaction.xa.XAResource;
+import org.jboss.minerva.jdbc.PreparedStatementInPool;
+import org.jboss.minerva.jdbc.PSCacheKey;
/**
* A transaction wrapper around a java.sql.Connection. This provides access to
@@ -36,7 +40,7 @@
* also register a TransactionListener that will be notified when the
* Transaction is finished, and release the XAConnection at that time.</P>
* @see org.jboss.minerva.xa.TransactionListener
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
* @author Aaron Mulder ([EMAIL PROTECTED])
*/
public class XAConnectionImpl implements XAConnection {
@@ -76,6 +80,14 @@
* Shuts down this wrapper (and the underlying Connection) permanently.
*/
public void close() {
+ Map map = (Map)PreparedStatementInPool.preparedStatementCache.clone();
+ Iterator it = map.keySet().iterator();
+ while(it.hasNext()) {
+ PSCacheKey key = (PSCacheKey)it.next();
+ if(key.con.equals(con))
+ PreparedStatementInPool.preparedStatementCache.remove(key);
+ }
+
try {
con.close();
} catch(SQLException e) {}