You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2014/02/05 11:31:03 UTC

svn commit: r1564704 - in /commons/proper/dbcp/trunk/src: main/java/org/apache/commons/dbcp2/ main/java/org/apache/commons/dbcp2/datasources/ main/java/org/apache/commons/dbcp2/managed/ test/java/org/apache/commons/dbcp2/

Author: markt
Date: Wed Feb  5 10:31:03 2014
New Revision: 1564704

URL: http://svn.apache.org/r1564704
Log:
Simplify SQLException creation

Modified:
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolingDriver.java
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/KeyedCPDSConnectionFactory.java
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/BasicManagedDataSource.java
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/ManagedConnection.java
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/TransactionContext.java
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/TransactionRegistry.java
    commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TesterConnection.java

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java?rev=1564704&r1=1564703&r2=1564704&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java (original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java Wed Feb  5 10:31:03 2014
@@ -97,7 +97,7 @@ public class PoolableConnection extends 
             } catch (Exception ie) {
                 // DO NOTHING the original exception will be rethrown
             }
-            throw (SQLException) new SQLException("Cannot close connection (isClosed check failed)").initCause(e);
+            throw new SQLException("Cannot close connection (isClosed check failed)", e);
         }
 
         if (!isUnderlyingConectionClosed) {
@@ -114,7 +114,7 @@ public class PoolableConnection extends 
             } catch(RuntimeException e) {
                 throw e;
             } catch(Exception e) {
-                throw (SQLException) new SQLException("Cannot close connection (return to pool failed)").initCause(e);
+                throw new SQLException("Cannot close connection (return to pool failed)", e);
             }
         } else {
             // Abnormal close: underlying connection closed unexpectedly, so we
@@ -126,7 +126,7 @@ public class PoolableConnection extends 
                 passivate();
                 getInnermostDelegate().close();
             } catch (Exception e) {
-                throw (SQLException) new SQLException("Cannot close connection (invalidating pooled object failed)").initCause(e);
+                throw new SQLException("Cannot close connection (invalidating pooled object failed)", e);
             }
         }
         setClosedInternal(true);

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java?rev=1564704&r1=1564703&r2=1564704&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java (original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java Wed Feb  5 10:31:03 2014
@@ -88,7 +88,7 @@ public class PoolingConnection extends D
                 } catch(RuntimeException e) {
                     throw e;
                 } catch(Exception e) {
-                    throw (SQLException) new SQLException("Cannot close connection").initCause(e);
+                    throw new SQLException("Cannot close connection", e);
                 }
             }
         } finally {
@@ -114,7 +114,7 @@ public class PoolingConnection extends D
         try {
             return _pstmtPool.borrowObject(createKey(sql));
         } catch(NoSuchElementException e) {
-            throw (SQLException) new SQLException("MaxOpenPreparedStatements limit reached").initCause(e);
+            throw new SQLException("MaxOpenPreparedStatements limit reached", e);
         } catch(RuntimeException e) {
             throw e;
         } catch(Exception e) {
@@ -132,13 +132,13 @@ public class PoolingConnection extends D
             return _pstmtPool.borrowObject(createKey(sql, autoGeneratedKeys));
         }
         catch (NoSuchElementException e) {
-            throw (SQLException)new SQLException("MaxOpenPreparedStatements limit reached", e).initCause(e);
+            throw new SQLException("MaxOpenPreparedStatements limit reached", e);
         }
         catch (RuntimeException e) {
             throw e;
         }
         catch (Exception e) {
-            throw (SQLException)new SQLException("Borrow prepareStatement from pool failed").initCause(e);
+            throw new SQLException("Borrow prepareStatement from pool failed", e);
         }
     }
 
@@ -158,11 +158,11 @@ public class PoolingConnection extends D
         try {
             return _pstmtPool.borrowObject(createKey(sql,resultSetType,resultSetConcurrency));
         } catch(NoSuchElementException e) {
-            throw (SQLException) new SQLException("MaxOpenPreparedStatements limit reached").initCause(e);
+            throw new SQLException("MaxOpenPreparedStatements limit reached", e);
         } catch(RuntimeException e) {
             throw e;
         } catch(Exception e) {
-            throw (SQLException) new SQLException("Borrow prepareStatement from pool failed").initCause(e);
+            throw new SQLException("Borrow prepareStatement from pool failed", e);
         }
     }
 

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolingDriver.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolingDriver.java?rev=1564704&r1=1564703&r2=1564704&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolingDriver.java (original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolingDriver.java Wed Feb  5 10:31:03 2014
@@ -99,7 +99,7 @@ public class PoolingDriver implements Dr
                 pool.close();
             }
             catch (Exception e) {
-                throw (SQLException) new SQLException("Error closing pool " + name).initCause(e);
+                throw new SQLException("Error closing pool " + name, e);
             }
         }
     }
@@ -133,11 +133,11 @@ public class PoolingDriver implements Dr
             } catch(SQLException e) {
                 throw e;
             } catch(NoSuchElementException e) {
-                throw (SQLException) new SQLException("Cannot get a connection, pool error: " + e.getMessage()).initCause(e);
+                throw new SQLException("Cannot get a connection, pool error: " + e.getMessage(), e);
             } catch(RuntimeException e) {
                 throw e;
             } catch(Exception e) {
-                throw (SQLException) new SQLException("Cannot get a connection, general error: " + e.getMessage()).initCause(e);
+                throw new SQLException("Cannot get a connection, general error: " + e.getMessage(), e);
             }
         } else {
             return null;

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java?rev=1564704&r1=1564703&r2=1564704&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java (original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java Wed Feb  5 10:31:03 2014
@@ -298,7 +298,7 @@ class CPDSConnectionFactory
             _pool.invalidateObject(pci);  // Destroy instance and update pool counters
             _pool.close();  // Clear any other instances in this pool and kill others as they come back
         } catch (Exception ex) {
-            throw (SQLException) new SQLException("Error invalidating connection").initCause(ex);
+            throw new SQLException("Error invalidating connection", ex);
         }
     }
 
@@ -336,7 +336,7 @@ class CPDSConnectionFactory
         try {
             _pool.close();
         } catch (Exception ex) {
-            throw (SQLException) new SQLException("Error closing connection pool").initCause(ex);
+            throw new SQLException("Error closing connection pool", ex);
         }
     }
 

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java?rev=1564704&r1=1564703&r2=1564704&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java (original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java Wed Feb  5 10:31:03 2014
@@ -812,8 +812,8 @@ public abstract class InstanceKeyDataSou
                 throw new SQLException("Given password did not match password used"
                                        + " to create the PooledConnection.");
             } catch (javax.naming.NamingException ne) {
-                throw (SQLException) new SQLException(
-                        "NamingException encountered connecting to database").initCause(ne);
+                throw new SQLException(
+                        "NamingException encountered connecting to database", ne);
             }
             /*
              * Password must have changed -> destroy connection and keep retrying until we get a new, good one,

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/KeyedCPDSConnectionFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/KeyedCPDSConnectionFactory.java?rev=1564704&r1=1564703&r2=1564704&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/KeyedCPDSConnectionFactory.java (original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/KeyedCPDSConnectionFactory.java Wed Feb  5 10:31:03 2014
@@ -310,7 +310,7 @@ class KeyedCPDSConnectionFactory
             _pool.invalidateObject(key, info);  // Destroy and update pool counters
             _pool.clear(key); // Remove any idle instances with this key
         } catch (Exception ex) {
-            throw (SQLException) new SQLException("Error invalidating connection").initCause(ex);
+            throw new SQLException("Error invalidating connection", ex);
         }
     }
 
@@ -341,7 +341,7 @@ class KeyedCPDSConnectionFactory
         try {
             _pool.clear(new UserPassKey(username, null));
         } catch (Exception ex) {
-            throw (SQLException) new SQLException("Error closing connection pool").initCause(ex);
+            throw new SQLException("Error closing connection pool", ex);
         }
     }
 

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java?rev=1564704&r1=1564703&r2=1564704&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java (original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java Wed Feb  5 10:31:03 2014
@@ -469,8 +469,8 @@ public class PerUserPoolDataSource exten
             try {
                 testCPDS(username, password);
             } catch (Exception ex) {
-                throw (SQLException) new SQLException(
-                        "Could not retrieve connection info from pool").initCause(ex);
+                throw new SQLException(
+                        "Could not retrieve connection info from pool", ex);
             }
             // New password works, so kill the old pool, create a new one, and borrow
             manager.closePool(username);
@@ -486,8 +486,8 @@ public class PerUserPoolDataSource exten
             try {
                 info = pool.borrowObject();
             } catch (Exception ex) {
-                throw (SQLException) new SQLException(
-                "Could not retrieve connection info from pool").initCause(ex);
+                throw new SQLException(
+                        "Could not retrieve connection info from pool", ex);
             }
         }
         return info;

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/BasicManagedDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/BasicManagedDataSource.java?rev=1564704&r1=1564703&r2=1564704&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/BasicManagedDataSource.java (original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/BasicManagedDataSource.java Wed Feb  5 10:31:03 2014
@@ -147,14 +147,14 @@ public class BasicManagedDataSource exte
                 xaDataSourceClass = Class.forName(xaDataSource);
             } catch (Exception t) {
                 String message = "Cannot load XA data source class '" + xaDataSource + "'";
-                throw (SQLException)new SQLException(message).initCause(t);
+                throw new SQLException(message, t);
             }
 
             try {
                 xaDataSourceInstance = (XADataSource) xaDataSourceClass.newInstance();
             } catch (Exception t) {
                 String message = "Cannot create XA data source of class '" + xaDataSource + "'";
-                throw (SQLException)new SQLException(message).initCause(t);
+                throw new SQLException(message, t);
             }
         }
 
@@ -202,7 +202,7 @@ public class BasicManagedDataSource exte
         } catch (RuntimeException e) {
             throw e;
         } catch (Exception e) {
-            throw (SQLException)new SQLException("Cannot create PoolableConnectionFactory (" + e.getMessage() + ")").initCause(e);
+            throw new SQLException("Cannot create PoolableConnectionFactory (" + e.getMessage() + ")", e);
         }
         return connectionFactory;
     }

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/ManagedConnection.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/ManagedConnection.java?rev=1564704&r1=1564703&r2=1564704&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/ManagedConnection.java (original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/ManagedConnection.java Wed Feb  5 10:31:03 2014
@@ -124,7 +124,7 @@ public class ManagedConnection<C extends
                     C connection = pool.borrowObject();
                     setDelegate(connection);
                 } catch (Exception e) {
-                    throw (SQLException) new SQLException("Unable to acquire a new connection from the pool").initCause(e);
+                    throw new SQLException("Unable to acquire a new connection from the pool", e);
                 }
             }
 

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/TransactionContext.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/TransactionContext.java?rev=1564704&r1=1564703&r2=1564704&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/TransactionContext.java (original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/TransactionContext.java Wed Feb  5 10:31:03 2014
@@ -90,7 +90,7 @@ public class TransactionContext {
         } catch (RollbackException e) {
             // transaction was rolled back... proceed as if there never was a transaction
         } catch (SystemException e) {
-            throw (SQLException) new SQLException("Unable to enlist connection the transaction").initCause(e);
+            throw new SQLException("Unable to enlist connection the transaction", e);
         }
 
         this.sharedConnection = sharedConnection;
@@ -118,7 +118,7 @@ public class TransactionContext {
             // JTA spec doesn't let us register with a transaction marked rollback only
             // just ignore this and the tx state will be cleared another way.
         } catch (Exception e) {
-            throw (SQLException) new SQLException("Unable to register transaction context listener").initCause(e);
+            throw new SQLException("Unable to register transaction context listener", e);
         }
     }
 
@@ -136,7 +136,7 @@ public class TransactionContext {
             int status = transaction.getStatus();
             return status == Status.STATUS_ACTIVE || status == Status.STATUS_MARKED_ROLLBACK;
         } catch (SystemException e) {
-            throw (SQLException) new SQLException("Unable to get transaction status").initCause(e);
+            throw new SQLException("Unable to get transaction status", e);
         }
     }
 

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/TransactionRegistry.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/TransactionRegistry.java?rev=1564704&r1=1564703&r2=1564704&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/TransactionRegistry.java (original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/TransactionRegistry.java Wed Feb  5 10:31:03 2014
@@ -105,7 +105,7 @@ public class TransactionRegistry {
                 return null;
             }
         } catch (SystemException e) {
-            throw (SQLException) new SQLException("Unable to determine current transaction ").initCause(e);
+            throw new SQLException("Unable to determine current transaction ", e);
         }
 
         // register the the context (or create a new one)

Modified: commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TesterConnection.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TesterConnection.java?rev=1564704&r1=1564703&r2=1564704&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TesterConnection.java (original)
+++ commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TesterConnection.java Wed Feb  5 10:31:03 2014
@@ -5,9 +5,9 @@
  * 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.
@@ -39,7 +39,7 @@ import java.util.concurrent.Executor;
 
 /**
  * A dummy {@link Connection}, for testing purposes.
- * 
+ *
  * @author Rodney Waldhoff
  * @author Dirk Verbeeck
  * @version $Revision$ $Date$
@@ -61,7 +61,7 @@ public class TesterConnection implements
         this.username = username;
         this.password = password;
     }
-    
+
     public String getUsername() {
         return this.username;
     }
@@ -234,17 +234,17 @@ public class TesterConnection implements
         }
         checkFailure();
     }
-    
+
     protected void checkFailure() throws SQLException {
         if (failure != null) {
-            throw (SQLException) new SQLException("TesterConnection failure").initCause(failure);
+            throw new SQLException("TesterConnection failure", failure);
         }
     }
-    
+
     public void setFailure(Exception failure) {
         this.failure = failure;
     }
-    
+
     @Override
     public int getHoldability() throws SQLException {
         throw new SQLException("Not implemented.");