Index: src/test/org/apache/commons/dbcp/TestManual.java =================================================================== --- src/test/org/apache/commons/dbcp/TestManual.java (revision 558883) +++ src/test/org/apache/commons/dbcp/TestManual.java (working copy) @@ -182,37 +182,37 @@ SQLException ex; DriverManager.setLogWriter(pw); - ex = new SQLNestedException("A", new Exception("a")); + ex = (SQLException) new SQLException("A").initCause(new Exception("a")); ex.printStackTrace(); ex.printStackTrace(ps); ex.printStackTrace(pw); - ex = new SQLNestedException("B", null); + ex = (SQLException) new SQLException("B").initCause(null); ex.printStackTrace(); ex.printStackTrace(ps); ex.printStackTrace(pw); - ex = new SQLNestedException(null, new Exception("c")); + ex = (SQLException) new SQLException(null).initCause(new Exception("c")); ex.printStackTrace(); ex.printStackTrace(ps); ex.printStackTrace(pw); - ex = new SQLNestedException(null, null); + ex = (SQLException) new SQLException(null).initCause(null); ex.printStackTrace(); ex.printStackTrace(ps); ex.printStackTrace(pw); DriverManager.setLogWriter(null); - ex = new SQLNestedException("A", new Exception("a")); + ex = (SQLException) new SQLException("A").initCause(new Exception("a")); ex.printStackTrace(); ex.printStackTrace(ps); ex.printStackTrace(pw); - ex = new SQLNestedException("B", null); + ex = (SQLException) new SQLException("B").initCause(null); ex.printStackTrace(); ex.printStackTrace(ps); ex.printStackTrace(pw); - ex = new SQLNestedException(null, new Exception("c")); + ex = (SQLException) new SQLException(null).initCause(new Exception("c")); ex.printStackTrace(); ex.printStackTrace(ps); ex.printStackTrace(pw); - ex = new SQLNestedException(null, null); + ex = (SQLException) new SQLException(null).initCause(null); ex.printStackTrace(); ex.printStackTrace(ps); ex.printStackTrace(pw); Index: src/test/org/apache/commons/dbcp/TesterConnection.java =================================================================== --- src/test/org/apache/commons/dbcp/TesterConnection.java (revision 558883) +++ src/test/org/apache/commons/dbcp/TesterConnection.java (working copy) @@ -202,7 +202,7 @@ protected void checkFailure() throws SQLException { if (failure != null) { - throw new SQLNestedException("TesterConnection failure", failure); + throw (SQLException) new SQLException("TesterConnection failure").initCause(failure); } } Index: src/java/org/apache/commons/dbcp/PoolablePreparedStatement.java =================================================================== --- src/java/org/apache/commons/dbcp/PoolablePreparedStatement.java (revision 558883) +++ src/java/org/apache/commons/dbcp/PoolablePreparedStatement.java (working copy) @@ -81,7 +81,7 @@ } catch(RuntimeException e) { throw e; } catch(Exception e) { - throw new SQLNestedException("Cannot close preparedstatement (return to pool failed)", e); + throw (SQLException) new SQLException("Cannot close preparedstatement (return to pool failed)").initCause(e); } } } Index: src/java/org/apache/commons/dbcp/cpdsadapter/PooledConnectionImpl.java =================================================================== --- src/java/org/apache/commons/dbcp/cpdsadapter/PooledConnectionImpl.java (revision 558883) +++ src/java/org/apache/commons/dbcp/cpdsadapter/PooledConnectionImpl.java (working copy) @@ -29,7 +29,6 @@ import org.apache.commons.dbcp.DelegatingConnection; import org.apache.commons.dbcp.DelegatingPreparedStatement; -import org.apache.commons.dbcp.SQLNestedException; import org.apache.commons.pool.KeyedObjectPool; import org.apache.commons.pool.KeyedPoolableObjectFactory; @@ -122,7 +121,7 @@ } catch (RuntimeException e) { throw e; } catch (Exception e) { - throw new SQLNestedException("Cannot close connection (return to pool failed)", e); + throw (SQLException) new SQLException("Cannot close connection (return to pool failed)").initCause(e); } finally { try { connection.close(); @@ -216,7 +215,7 @@ } catch (RuntimeException e) { throw e; } catch (Exception e) { - throw new SQLNestedException("Borrow prepareStatement from pool failed", e); + throw (SQLException) new SQLException("Borrow prepareStatement from pool failed").initCause(e); } } } @@ -237,7 +236,7 @@ } catch (RuntimeException e) { throw e; } catch (Exception e) { - throw new SQLNestedException("Borrow prepareStatement from pool failed", e); + throw (SQLException) new SQLException("Borrow prepareStatement from pool failed").initCause(e); } } } Index: src/java/org/apache/commons/dbcp/managed/BasicManagedDataSource.java =================================================================== --- src/java/org/apache/commons/dbcp/managed/BasicManagedDataSource.java (revision 558883) +++ src/java/org/apache/commons/dbcp/managed/BasicManagedDataSource.java (working copy) @@ -20,7 +20,6 @@ import org.apache.commons.dbcp.BasicDataSource; import org.apache.commons.dbcp.ConnectionFactory; import org.apache.commons.dbcp.PoolingDataSource; -import org.apache.commons.dbcp.SQLNestedException; import javax.sql.XADataSource; import javax.transaction.TransactionManager; @@ -110,7 +109,7 @@ String message = "Cannot load XA data source class '" + xaDataSource + "'"; logWriter.println(message); t.printStackTrace(logWriter); - throw new SQLNestedException(message, t); + throw (SQLException) new SQLException(message).initCause(t); } // Create the xa data source instance @@ -121,7 +120,7 @@ String message = "Cannot create XA data source of class '" + xaDataSource + "'"; logWriter.println(message); t.printStackTrace(logWriter); - throw new SQLNestedException(message, t); + throw (SQLException) new SQLException(message).initCause(t); } // finally, create the XAConectionFactory using the XA data source Index: src/java/org/apache/commons/dbcp/PoolableConnection.java =================================================================== --- src/java/org/apache/commons/dbcp/PoolableConnection.java (revision 558884) +++ src/java/org/apache/commons/dbcp/PoolableConnection.java (working copy) @@ -77,7 +77,7 @@ } catch (Exception ie) { // DO NOTHING the original exception will be rethrown } - throw new SQLNestedException("Cannot close connection (isClosed check failed)", e); + throw (SQLException) new SQLException("Cannot close connection (isClosed check failed)").initCause(e); } if (isClosed) { try { @@ -102,7 +102,7 @@ } catch(RuntimeException e) { throw e; } catch(Exception e) { - throw new SQLNestedException("Cannot close connection (return to pool failed)", e); + throw (SQLException) new SQLException("Cannot close connection (return to pool failed)").initCause(e); } } } Index: src/java/org/apache/commons/dbcp/SQLNestedException.java =================================================================== --- src/java/org/apache/commons/dbcp/SQLNestedException.java (revision 558883) +++ src/java/org/apache/commons/dbcp/SQLNestedException.java (working copy) @@ -1,92 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.commons.dbcp; - -import java.io.PrintStream; -import java.io.PrintWriter; -import java.lang.reflect.Method; -import java.sql.DriverManager; -import java.sql.SQLException; - -/** - * A SQLException subclass containing another Throwable - * - * @author Dirk Verbeeck - * @version $Revision$ $Date$ - */ -public class SQLNestedException extends SQLException { - - /* Throwable.getCause detection as found in commons-lang */ - private static final Method THROWABLE_CAUSE_METHOD; - static { - Method getCauseMethod; - try { - getCauseMethod = Throwable.class.getMethod("getCause", (Class[]) null); - } catch (Exception e) { - getCauseMethod = null; - } - THROWABLE_CAUSE_METHOD = getCauseMethod; - } - - private static boolean hasThrowableCauseMethod() { - return THROWABLE_CAUSE_METHOD != null; - } - - /** - * Holds the reference to the exception or error that caused - * this exception to be thrown. - */ - private Throwable cause = null; - - /** - * Constructs a new SQLNestedException with specified - * detail message and nested Throwable. - * - * @param msg the error message - * @param cause the exception or error that caused this exception to be - * thrown - */ - public SQLNestedException(String msg, Throwable cause) { - super(msg); - this.cause = cause; - if ((cause != null) && (DriverManager.getLogWriter() != null)) { - DriverManager.getLogWriter().print("Caused by: "); - cause.printStackTrace(DriverManager.getLogWriter()); - } - } - - public Throwable getCause() { - return this.cause; - } - - public void printStackTrace(PrintStream s) { - super.printStackTrace(s); - if ((cause != null) && !hasThrowableCauseMethod()) { - s.print("Caused by: "); - this.cause.printStackTrace(s); - } - } - - public void printStackTrace(PrintWriter s) { - super.printStackTrace(s); - if ((cause != null) && !hasThrowableCauseMethod()) { - s.print("Caused by: "); - this.cause.printStackTrace(s); - } - } -} Index: src/java/org/apache/commons/dbcp/PoolingDataSource.java =================================================================== --- src/java/org/apache/commons/dbcp/PoolingDataSource.java (revision 558883) +++ src/java/org/apache/commons/dbcp/PoolingDataSource.java (working copy) @@ -101,11 +101,11 @@ } catch(SQLException e) { throw e; } catch(NoSuchElementException e) { - throw new SQLNestedException("Cannot get a connection, pool error " + e.getMessage(), e); + throw (SQLException) new SQLException("Cannot get a connection, pool error " + e.getMessage()).initCause(e); } catch(RuntimeException e) { throw e; } catch(Exception e) { - throw new SQLNestedException("Cannot get a connection, general error", e); + throw (SQLException) new SQLException("Cannot get a connection, general error").initCause(e); } } Index: src/java/org/apache/commons/dbcp/PoolingDriver.java =================================================================== --- src/java/org/apache/commons/dbcp/PoolingDriver.java (revision 558883) +++ src/java/org/apache/commons/dbcp/PoolingDriver.java (working copy) @@ -112,10 +112,10 @@ jocl = JOCLContentHandler.parse(in); } catch (SAXException e) { - throw new SQLNestedException("Could not parse configuration file", e); + throw (SQLException) new SQLException("Could not parse configuration file").initCause(e); } catch (IOException e) { - throw new SQLNestedException("Could not load configuration file", e); + throw (SQLException) new SQLException("Could not load configuration file").initCause(e); } if(jocl.getType(0).equals(String.class)) { pool = getPool((String)(jocl.getValue(0))); @@ -148,7 +148,7 @@ pool.close(); } catch (Exception e) { - throw new SQLNestedException("Error closing pool " + name, e); + throw (SQLException) new SQLException("Error closing pool " + name).initCause(e); } } } @@ -181,11 +181,11 @@ } catch(SQLException e) { throw e; } catch(NoSuchElementException e) { - throw new SQLNestedException("Cannot get a connection, pool error: " + e.getMessage(), e); + throw (SQLException) new SQLException("Cannot get a connection, pool error: " + e.getMessage()).initCause(e); } catch(RuntimeException e) { throw e; } catch(Exception e) { - throw new SQLNestedException("Cannot get a connection, general error: " + e.getMessage(), e); + throw (SQLException) new SQLException("Cannot get a connection, general error: " + e.getMessage()).initCause(e); } } } else { Index: src/java/org/apache/commons/dbcp/PoolingConnection.java =================================================================== --- src/java/org/apache/commons/dbcp/PoolingConnection.java (revision 558883) +++ src/java/org/apache/commons/dbcp/PoolingConnection.java (working copy) @@ -77,7 +77,7 @@ } catch(SQLException e) { throw e; } catch(Exception e) { - throw new SQLNestedException("Cannot close connection", e); + throw (SQLException) new SQLException("Cannot close connection").initCause(e); } } getInnermostDelegate().close(); @@ -91,11 +91,11 @@ try { return(PreparedStatement)(_pstmtPool.borrowObject(createKey(sql))); } catch(NoSuchElementException e) { - throw new SQLNestedException("MaxOpenPreparedStatements limit reached", e); + throw (SQLException) new SQLException("MaxOpenPreparedStatements limit reached").initCause(e); } catch(RuntimeException e) { throw e; } catch(Exception e) { - throw new SQLNestedException("Borrow prepareStatement from pool failed", e); + throw (SQLException) new SQLException("Borrow prepareStatement from pool failed").initCause(e); } } @@ -107,11 +107,11 @@ try { return(PreparedStatement)(_pstmtPool.borrowObject(createKey(sql,resultSetType,resultSetConcurrency))); } catch(NoSuchElementException e) { - throw new SQLNestedException("MaxOpenPreparedStatements limit reached", e); + throw (SQLException) new SQLException("MaxOpenPreparedStatements limit reached").initCause(e); } catch(RuntimeException e) { throw e; } catch(Exception e) { - throw new SQLNestedException("Borrow prepareStatement from pool failed", e); + throw (SQLException) new SQLException("Borrow prepareStatement from pool failed").initCause(e); } } Index: src/java/org/apache/commons/dbcp/BasicDataSource.java =================================================================== --- src/java/org/apache/commons/dbcp/BasicDataSource.java (revision 558884) +++ src/java/org/apache/commons/dbcp/BasicDataSource.java (working copy) @@ -1150,7 +1150,7 @@ } catch(RuntimeException e) { throw e; } catch(Exception e) { - throw new SQLNestedException("Cannot close connection pool", e); + throw (SQLException) new SQLException("Cannot close connection pool").initCause(e); } } @@ -1225,7 +1225,7 @@ } catch (RuntimeException e) { throw e; } catch (Exception e) { - throw new SQLNestedException("Cannot create PoolableConnectionFactory (" + e.getMessage() + ")", e); + throw (SQLException) new SQLException("Cannot create PoolableConnectionFactory (" + e.getMessage() + ")").initCause(e); } // Create and return the pooling data source to manage the connections @@ -1236,7 +1236,7 @@ connectionPool.addObject(); } } catch (Exception e) { - throw new SQLNestedException("Error preloading the connection pool", e); + throw (SQLException) new SQLException("Error preloading the connection pool").initCause(e); } return dataSource; @@ -1256,7 +1256,7 @@ driverClassName + "'"; logWriter.println(message); t.printStackTrace(logWriter); - throw new SQLNestedException(message, t); + throw (SQLException) new SQLException(message).initCause(t); } } @@ -1270,7 +1270,7 @@ "' for connect URL '" + url + "'"; logWriter.println(message); t.printStackTrace(logWriter); - throw new SQLNestedException(message, t); + throw (SQLException) new SQLException(message).initCause(t); } // Can't test without a validationQuery Index: src/java/org/apache/commons/dbcp/datasources/CPDSConnectionFactory.java =================================================================== --- src/java/org/apache/commons/dbcp/datasources/CPDSConnectionFactory.java (revision 558883) +++ src/java/org/apache/commons/dbcp/datasources/CPDSConnectionFactory.java (working copy) @@ -30,7 +30,6 @@ import javax.sql.ConnectionPoolDataSource; import javax.sql.PooledConnection; -import org.apache.commons.dbcp.SQLNestedException; import org.apache.commons.pool.ObjectPool; import org.apache.commons.pool.PoolableObjectFactory; @@ -156,7 +155,7 @@ } catch (RuntimeException e) { throw e; } catch (Exception e) { - throw new SQLNestedException("Cannot set the pool on this factory", e); + throw (SQLException) new SQLException("Cannot set the pool on this factory").initCause(e); } } _pool = pool; Index: src/java/org/apache/commons/dbcp/datasources/KeyedCPDSConnectionFactory.java =================================================================== --- src/java/org/apache/commons/dbcp/datasources/KeyedCPDSConnectionFactory.java (revision 558883) +++ src/java/org/apache/commons/dbcp/datasources/KeyedCPDSConnectionFactory.java (working copy) @@ -30,7 +30,6 @@ import javax.sql.ConnectionPoolDataSource; import javax.sql.PooledConnection; -import org.apache.commons.dbcp.SQLNestedException; import org.apache.commons.pool.KeyedObjectPool; import org.apache.commons.pool.KeyedPoolableObjectFactory; @@ -132,7 +131,7 @@ } catch (RuntimeException e) { throw e; } catch (Exception e) { - throw new SQLNestedException("Cannot set the pool on this factory", e); + throw (SQLException) new SQLException("Cannot set the pool on this factory").initCause(e); } } _pool = pool; Index: src/java/org/apache/commons/dbcp/datasources/InstanceKeyDataSource.java =================================================================== --- src/java/org/apache/commons/dbcp/datasources/InstanceKeyDataSource.java (revision 558883) +++ src/java/org/apache/commons/dbcp/datasources/InstanceKeyDataSource.java (working copy) @@ -34,7 +34,6 @@ import javax.sql.DataSource; import javax.sql.PooledConnection; -import org.apache.commons.dbcp.SQLNestedException; import org.apache.commons.pool.impl.GenericObjectPool; /** @@ -669,7 +668,7 @@ info = getPooledConnectionAndInfo(username, password); } catch (NoSuchElementException e) { closeDueToException(info); - throw new SQLNestedException("Cannot borrow connection from pool", e); + throw (SQLException) new SQLException("Cannot borrow connection from pool").initCause(e); } catch (RuntimeException e) { closeDueToException(info); throw e; @@ -678,7 +677,7 @@ throw e; } catch (Exception e) { closeDueToException(info); - throw new SQLNestedException("Cannot borrow connection from pool", e); + throw (SQLException) new SQLException("Cannot borrow connection from pool").initCause(e); } if (!(null == password ? null == info.getPassword() Index: src/java/org/apache/commons/dbcp/datasources/PerUserPoolDataSource.java =================================================================== --- src/java/org/apache/commons/dbcp/datasources/PerUserPoolDataSource.java (revision 558883) +++ src/java/org/apache/commons/dbcp/datasources/PerUserPoolDataSource.java (working copy) @@ -32,7 +32,6 @@ import org.apache.commons.pool.ObjectPool; import org.apache.commons.pool.impl.GenericObjectPool; -import org.apache.commons.dbcp.SQLNestedException; /** *

@@ -373,7 +372,7 @@ registerPool(username, password); pool = pools.get(key); } catch (NamingException e) { - throw new SQLNestedException("RegisterPool failed", e); + throw (SQLException) new SQLException("RegisterPool failed").initCause(e); } } @@ -382,8 +381,7 @@ info = (PooledConnectionAndInfo)((ObjectPool) pool).borrowObject(); } catch (Exception e) { - throw new SQLNestedException( - "Could not retrieve connection info from pool", e); + throw (SQLException) new SQLException("Could not retrieve connection info from pool").initCause(e); } return info; Index: src/java/org/apache/commons/dbcp/datasources/SharedPoolDataSource.java =================================================================== --- src/java/org/apache/commons/dbcp/datasources/SharedPoolDataSource.java (revision 558883) +++ src/java/org/apache/commons/dbcp/datasources/SharedPoolDataSource.java (working copy) @@ -31,7 +31,6 @@ import org.apache.commons.pool.KeyedObjectPool; import org.apache.commons.pool.impl.GenericKeyedObjectPool; import org.apache.commons.pool.impl.GenericObjectPool; -import org.apache.commons.dbcp.SQLNestedException; /** * A pooling DataSource appropriate for deployment within @@ -158,7 +157,7 @@ try { registerPool(username, password); } catch (NamingException e) { - throw new SQLNestedException("RegisterPool failed", e); + throw (SQLException) new SQLException("RegisterPool failed").initCause(e); } } @@ -168,8 +167,7 @@ .borrowObject(getUserPassKey(username, password)); } catch (Exception e) { - throw new SQLNestedException( - "Could not retrieve connection info from pool", e); + throw (SQLException) new SQLException("Could not retrieve connection info from pool").initCause(e); } return info; }