Author: markt Date: Thu Feb 19 13:40:35 2009 New Revision: 745857 URL: http://svn.apache.org/viewvc?rev=745857&view=rev Log: Add a DelegatingDatabaseMetaData to address DBCP-265. Still need to add the compile time switches. These will follwo shortly.
Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingConnection.java commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingResultSet.java Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingConnection.java URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingConnection.java?rev=745857&r1=745856&r2=745857&view=diff ============================================================================== --- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingConnection.java (original) +++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingConnection.java Thu Feb 19 13:40:35 2009 @@ -326,8 +326,15 @@ public String getCatalog() throws SQLException { checkOpen(); try { return _conn.getCatalog(); } catch (SQLException e) { handleException(e); return null; } } - public DatabaseMetaData getMetaData() throws SQLException - { checkOpen(); try { return _conn.getMetaData(); } catch (SQLException e) { handleException(e); return null; } } + public DatabaseMetaData getMetaData() throws SQLException { + checkOpen(); + try { + return new DelegatingDatabaseMetaData(this, _conn.getMetaData()); + } catch (SQLException e) { + handleException(e); + return null; + } + } public int getTransactionIsolation() throws SQLException { checkOpen(); try { return _conn.getTransactionIsolation(); } catch (SQLException e) { handleException(e); return -1; } } Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingResultSet.java URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingResultSet.java?rev=745857&r1=745856&r2=745857&view=diff ============================================================================== --- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingResultSet.java (original) +++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingResultSet.java Thu Feb 19 13:40:35 2009 @@ -29,6 +29,7 @@ import java.io.Reader; import java.sql.Statement; import java.util.Map; +import java.sql.Connection; import java.sql.Ref; import java.sql.Blob; import java.sql.Clob; @@ -65,6 +66,9 @@ /** The Statement that created me, if any. **/ private Statement _stmt; + /** The Connection that created me, if any. **/ + private Connection _conn; + /** * Create a wrapper for the ResultSet which traces this * ResultSet to the Statement which created it and the @@ -79,6 +83,20 @@ this._res = res; } + /** + * Create a wrapper for the ResultSet which traces this + * ResultSet to the Connection which created it (via, for + * example DatabaseMetadata, and the code which created it. + * + * @param conn Connection which created this ResultSet + * @param res ResultSet to wrap + */ + public DelegatingResultSet(Connection conn, ResultSet res) { + super((AbandonedTrace)conn); + this._conn = conn; + this._res = res; + } + public static ResultSet wrapResultSet(Statement stmt, ResultSet rset) { if(null == rset) { return null; @@ -87,6 +105,14 @@ } } + public static ResultSet wrapResultSet(Connection conn, ResultSet rset) { + if(null == rset) { + return null; + } else { + return new DelegatingResultSet(conn,rset); + } + } + public ResultSet getDelegate() { return _res; } @@ -154,6 +180,10 @@ ((AbandonedTrace)_stmt).removeTrace(this); _stmt = null; } + if(_conn != null) { + ((AbandonedTrace)_conn).removeTrace(this); + _conn = null; + } _res.close(); } catch (SQLException e) { @@ -165,6 +195,9 @@ if ((_stmt != null) && (_stmt instanceof DelegatingStatement)) { ((DelegatingStatement)_stmt).handleException(e); } + else if ((_conn != null) && (_conn instanceof DelegatingConnection)) { + ((DelegatingConnection)_conn).handleException(e); + } else { throw e; }