dirkv 2003/12/26 07:43:55 Modified: dbcp/src/java/org/apache/commons/dbcp DelegatingCallableStatement.java DelegatingPreparedStatement.java DelegatingStatement.java PoolablePreparedStatement.java PoolingConnection.java Log: Bugzilla Bug 24966: NullPointer with Oracle 9 driver - refactor close() & passivate() methods Revision Changes Path 1.14 +3 -30 jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/DelegatingCallableStatement.java Index: DelegatingCallableStatement.java =================================================================== RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/DelegatingCallableStatement.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- DelegatingCallableStatement.java 26 Dec 2003 15:16:28 -0000 1.13 +++ DelegatingCallableStatement.java 26 Dec 2003 15:43:55 -0000 1.14 @@ -80,8 +80,6 @@ import java.sql.SQLWarning; import java.sql.SQLException; -import java.util.List; - /** * A base delegating implementation of [EMAIL PROTECTED] CallableStatement}. * <p> @@ -136,31 +134,6 @@ public void setDelegate(CallableStatement s) { super.setDelegate(s); _stmt = s; - } - - /** - * Close this DelegatingCallableStatement, and close - * any ResultSets that were not explicitly closed. - */ - public void close() throws SQLException { - if(_conn != null) { - _conn.removeTrace(this); - _conn = null; - } - - // The JDBC spec requires that a statement close any open - // ResultSet's when it is closed. - List resultSets = getTrace(); - if( resultSets != null) { - ResultSet[] set = new ResultSet[resultSets.size()]; - resultSets.toArray(set); - for (int i = 0; i < set.length; i++) { - set[i].close(); - } - clearTrace(); - } - - _stmt.close(); } public ResultSet executeQuery() throws SQLException { 1.17 +3 -45 jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/DelegatingPreparedStatement.java Index: DelegatingPreparedStatement.java =================================================================== RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/DelegatingPreparedStatement.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- DelegatingPreparedStatement.java 26 Dec 2003 15:16:28 -0000 1.16 +++ DelegatingPreparedStatement.java 26 Dec 2003 15:43:55 -0000 1.17 @@ -72,7 +72,6 @@ import java.sql.SQLException; import java.sql.SQLWarning; import java.util.Calendar; -import java.util.List; /** * A base delegating implementation of [EMAIL PROTECTED] PreparedStatement}. @@ -133,15 +132,6 @@ _stmt = s; } - /** - * Close this DelegatingPreparedStatement, and close - * any ResultSets that were not explicitly closed. - */ - public void close() throws SQLException { - _stmt.close(); - passivate(); - } - public ResultSet executeQuery(String sql) throws SQLException { checkOpen(); return DelegatingResultSet.wrapResultSet(this,_stmt.executeQuery(sql)); @@ -217,38 +207,6 @@ public void setTime(int parameterIndex, java.sql.Time x, Calendar cal) throws SQLException { checkOpen(); _stmt.setTime(parameterIndex,x,cal);} public void setTimestamp(int parameterIndex, java.sql.Timestamp x, Calendar cal) throws SQLException { checkOpen(); _stmt.setTimestamp(parameterIndex,x,cal);} public void setNull (int paramIndex, int sqlType, String typeName) throws SQLException { checkOpen(); _stmt.setNull(paramIndex,sqlType,typeName);} - - protected void activate() { - _closed = false; - if(_stmt instanceof DelegatingPreparedStatement) { - ((DelegatingPreparedStatement)_stmt).activate(); - } - } - - protected void passivate() throws SQLException { - _closed = true; - if(_conn != null) { - _conn.removeTrace(this); - _conn = null; - } - - // The JDBC spec requires that a statment close any open - // ResultSet's when it is closed. - // FIXME The PreparedStatement we're wrapping should handle this for us. - // See bug 17301 for what could happen when ResultSets are closed twice. - List resultSets = getTrace(); - if( resultSets != null) { - ResultSet[] set = new ResultSet[resultSets.size()]; - resultSets.toArray(set); - for (int i = 0; i < set.length; i++) { - set[i].close(); - } - clearTrace(); - } - if(_stmt instanceof DelegatingPreparedStatement) { - ((DelegatingPreparedStatement)_stmt).passivate(); - } - } // ------------------- JDBC 3.0 ----------------------------------------- // Will be commented by the build process on a JDBC 2.0 system 1.14 +34 -34 jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/DelegatingStatement.java Index: DelegatingStatement.java =================================================================== RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/DelegatingStatement.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- DelegatingStatement.java 26 Dec 2003 15:16:28 -0000 1.13 +++ DelegatingStatement.java 26 Dec 2003 15:43:55 -0000 1.14 @@ -175,10 +175,40 @@ * any ResultSets that were not explicitly closed. */ public void close() throws SQLException { - passivate(); + _closed = true; + if (_conn != null) { + _conn.removeTrace(this); + _conn = null; + } + + // The JDBC spec requires that a statment close any open + // ResultSet's when it is closed. + // FIXME The PreparedStatement we're wrapping should handle this for us. + // See bug 17301 for what could happen when ResultSets are closed twice. + List resultSets = getTrace(); + if( resultSets != null) { + ResultSet[] set = (ResultSet[]) resultSets.toArray(new ResultSet[resultSets.size()]); + for (int i = 0; i < set.length; i++) { + set[i].close(); + } + clearTrace(); + } + _stmt.close(); } + protected void activate() throws SQLException { + if(_stmt instanceof DelegatingStatement) { + ((DelegatingStatement)_stmt).activate(); + } + } + + protected void passivate() throws SQLException { + if(_stmt instanceof DelegatingStatement) { + ((DelegatingStatement)_stmt).passivate(); + } + } + public Connection getConnection() throws SQLException { checkOpen(); return _conn; // return the delegating connection that created this @@ -222,36 +252,6 @@ protected void checkOpen() throws SQLException { if(isClosed()) { throw new SQLException(this.getClass().getName() + " is closed."); - } - } - - protected void activate() { - _closed = false; - if(_stmt instanceof DelegatingPreparedStatement) { - ((DelegatingPreparedStatement)_stmt).activate(); - } - } - - protected void passivate() throws SQLException { - _closed = true; - if (_conn != null) { - _conn.removeTrace(this); - _conn = null; - } - - // The JDBC spec requires that a statment close any open - // ResultSet's when it is closed. - List resultSets = getTrace(); - if( resultSets != null) { - ResultSet[] set = new ResultSet[resultSets.size()]; - resultSets.toArray(set); - for (int i = 0; i < set.length; i++) { - set[i].close(); - } - clearTrace(); - } - if(_stmt instanceof DelegatingPreparedStatement) { - ((DelegatingPreparedStatement)_stmt).passivate(); } } 1.8 +38 -16 jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/PoolablePreparedStatement.java Index: PoolablePreparedStatement.java =================================================================== RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/PoolablePreparedStatement.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- PoolablePreparedStatement.java 9 Oct 2003 21:04:44 -0000 1.7 +++ PoolablePreparedStatement.java 26 Dec 2003 15:43:55 -0000 1.8 @@ -61,9 +61,12 @@ package org.apache.commons.dbcp; -import java.sql.PreparedStatement; import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; import java.sql.SQLException; +import java.util.List; + import org.apache.commons.pool.KeyedObjectPool; /** @@ -76,15 +79,11 @@ * @author Rodney Waldhoff * @author Glenn L. Nielsen * @author James House (<a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a>) - * @version $Id$ + * @author Dirk Verbeeck + * @version $Revision$ $Date$ */ public class PoolablePreparedStatement extends DelegatingPreparedStatement implements PreparedStatement { /** - * The [EMAIL PROTECTED] Connection} from which I was created. - */ - protected Connection _conn = null; - - /** * The [EMAIL PROTECTED] KeyedObjectPool} from which I was obtained. */ protected KeyedObjectPool _pool = null; @@ -105,7 +104,6 @@ super((DelegatingConnection) conn, stmt); _pool = pool; _key = key; - _conn = conn; } /** @@ -126,11 +124,35 @@ } } } - - /** - * Return the [EMAIL PROTECTED] Connection} from which I was created. - */ - public Connection getConnection() throws SQLException { - return(null == _conn) ? _stmt.getConnection() : _conn; + + protected void activate() throws SQLException{ + _closed = false; + if(_conn != null) { + _conn.addTrace(this); + } + super.passivate(); } + + protected void passivate() throws SQLException { + _closed = true; + if(_conn != null) { + _conn.removeTrace(this); + } + + // The JDBC spec requires that a statment close any open + // ResultSet's when it is closed. + // FIXME The PreparedStatement we're wrapping should handle this for us. + // See bug 17301 for what could happen when ResultSets are closed twice. + List resultSets = getTrace(); + if( resultSets != null) { + ResultSet[] set = (ResultSet[]) resultSets.toArray(new ResultSet[resultSets.size()]); + for (int i = 0; i < set.length; i++) { + set[i].close(); + } + clearTrace(); + } + + super.passivate(); + } + } 1.11 +5 -3 jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/PoolingConnection.java Index: PoolingConnection.java =================================================================== RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/PoolingConnection.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- PoolingConnection.java 9 Oct 2003 21:04:44 -0000 1.10 +++ PoolingConnection.java 26 Dec 2003 15:43:55 -0000 1.11 @@ -76,6 +76,8 @@ * * @see PoolablePreparedStatement * @author Rodney Waldhoff (<a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a>) + * @author Dirk Verbeeck + * @version $Revision$ $Date$ */ public class PoolingConnection extends DelegatingConnection implements Connection, KeyedPoolableObjectFactory { /** My pool of [EMAIL PROTECTED] PreparedStatement}s. */ @@ -259,7 +261,7 @@ * @param key ignored * @param obj ignored */ - public void activateObject(Object key, Object obj) { + public void activateObject(Object key, Object obj) throws Exception { ((DelegatingPreparedStatement)obj).activate(); }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]