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 2013/12/03 21:04:46 UTC
svn commit: r1547560 -
/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolingDataSource.java
Author: markt
Date: Tue Dec 3 20:04:46 2013
New Revision: 1547560
URL: http://svn.apache.org/r1547560
Log:
Simplify.
DelegatingConnection already calls its own checkOpen that performs the same test.
No need to keep a second reference to the inner connection.
Modified:
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolingDataSource.java
Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolingDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolingDataSource.java?rev=1547560&r1=1547559&r2=1547560&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolingDataSource.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolingDataSource.java Tue Dec 3 20:04:46 2013
@@ -14,19 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.commons.dbcp2;
import java.io.PrintWriter;
-import java.sql.CallableStatement;
+
import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
-import java.sql.SQLWarning;
-import java.sql.Statement;
-import java.util.Map;
import java.util.NoSuchElementException;
import java.util.logging.Logger;
@@ -189,287 +183,8 @@ public class PoolingDataSource implement
*/
private class PoolGuardConnectionWrapper extends DelegatingConnection {
- private Connection delegate;
-
PoolGuardConnectionWrapper(Connection delegate) {
super(delegate);
- this.delegate = delegate;
- }
-
- @Override
- protected void checkOpen() throws SQLException {
- if(delegate == null) {
- throw new SQLException("Connection is closed.");
- }
- }
-
- @Override
- public void close() throws SQLException {
- if (delegate != null) {
- this.delegate.close();
- this.delegate = null;
- super.setDelegate(null);
- }
- }
-
- @Override
- public boolean isClosed() throws SQLException {
- if (delegate == null) {
- return true;
- }
- return delegate.isClosed();
- }
-
- @Override
- public void clearWarnings() throws SQLException {
- checkOpen();
- delegate.clearWarnings();
- }
-
- @Override
- public void commit() throws SQLException {
- checkOpen();
- delegate.commit();
- }
-
- @Override
- public Statement createStatement() throws SQLException {
- checkOpen();
- return new DelegatingStatement(this, delegate.createStatement());
- }
-
- @Override
- public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
- checkOpen();
- return new DelegatingStatement(this, delegate.createStatement(resultSetType, resultSetConcurrency));
- }
-
- @Override
- public boolean innermostDelegateEquals(Connection c) {
- Connection innerCon = super.getInnermostDelegate();
- if (innerCon == null) {
- return c == null;
- } else {
- return innerCon.equals(c);
- }
- }
-
- @Override
- public boolean getAutoCommit() throws SQLException {
- checkOpen();
- return delegate.getAutoCommit();
- }
-
- @Override
- public String getCatalog() throws SQLException {
- checkOpen();
- return delegate.getCatalog();
- }
-
- @Override
- public DatabaseMetaData getMetaData() throws SQLException {
- checkOpen();
- return delegate.getMetaData();
- }
-
- @Override
- public int getTransactionIsolation() throws SQLException {
- checkOpen();
- return delegate.getTransactionIsolation();
- }
-
- @Override
- public Map<String,Class<?>> getTypeMap() throws SQLException {
- checkOpen();
- return delegate.getTypeMap();
- }
-
- @Override
- public SQLWarning getWarnings() throws SQLException {
- checkOpen();
- return delegate.getWarnings();
- }
-
- @Override
- public int hashCode() {
- if (delegate == null){
- return 0;
- }
- return delegate.hashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == null) {
- return false;
- }
- if (obj == this) {
- return true;
- }
- // Use superclass accessor to skip access test
- Connection conn = super.getInnermostDelegate();
- if (conn == null) {
- return false;
- }
- if (obj instanceof DelegatingConnection) {
- DelegatingConnection c = (DelegatingConnection) obj;
- return c.innermostDelegateEquals(conn);
- }
- else {
- return conn.equals(obj);
- }
- }
-
- @Override
- public boolean isReadOnly() throws SQLException {
- checkOpen();
- return delegate.isReadOnly();
- }
-
- @Override
- public String nativeSQL(String sql) throws SQLException {
- checkOpen();
- return delegate.nativeSQL(sql);
- }
-
- @Override
- public CallableStatement prepareCall(String sql) throws SQLException {
- checkOpen();
- return new DelegatingCallableStatement(this, delegate.prepareCall(sql));
- }
-
- @Override
- public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
- checkOpen();
- return new DelegatingCallableStatement(this, delegate.prepareCall(sql, resultSetType, resultSetConcurrency));
- }
-
- @Override
- public PreparedStatement prepareStatement(String sql) throws SQLException {
- checkOpen();
- return new DelegatingPreparedStatement(this, delegate.prepareStatement(sql));
- }
-
- @Override
- public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
- checkOpen();
- return new DelegatingPreparedStatement(this, delegate.prepareStatement(sql, resultSetType, resultSetConcurrency));
- }
-
- @Override
- public void rollback() throws SQLException {
- checkOpen();
- delegate.rollback();
- }
-
- @Override
- public void setAutoCommit(boolean autoCommit) throws SQLException {
- checkOpen();
- delegate.setAutoCommit(autoCommit);
- }
-
- @Override
- public void setCatalog(String catalog) throws SQLException {
- checkOpen();
- delegate.setCatalog(catalog);
- }
-
- @Override
- public void setReadOnly(boolean readOnly) throws SQLException {
- checkOpen();
- delegate.setReadOnly(readOnly);
- }
-
- @Override
- public void setTransactionIsolation(int level) throws SQLException {
- checkOpen();
- delegate.setTransactionIsolation(level);
- }
-
- @Override
- public void setTypeMap(Map<String,Class<?>> map) throws SQLException {
- checkOpen();
- delegate.setTypeMap(map);
- }
-
- @Override
- public String toString() {
- if (delegate == null){
- return "NULL";
- }
- return delegate.toString();
- }
-
- @Override
- public int getHoldability() throws SQLException {
- checkOpen();
- return delegate.getHoldability();
- }
-
- @Override
- public void setHoldability(int holdability) throws SQLException {
- checkOpen();
- delegate.setHoldability(holdability);
- }
-
- @Override
- public java.sql.Savepoint setSavepoint() throws SQLException {
- checkOpen();
- return delegate.setSavepoint();
- }
-
- @Override
- public java.sql.Savepoint setSavepoint(String name) throws SQLException {
- checkOpen();
- return delegate.setSavepoint(name);
- }
-
- @Override
- public void releaseSavepoint(java.sql.Savepoint savepoint) throws SQLException {
- checkOpen();
- delegate.releaseSavepoint(savepoint);
- }
-
- @Override
- public void rollback(java.sql.Savepoint savepoint) throws SQLException {
- checkOpen();
- delegate.rollback(savepoint);
- }
-
- @Override
- public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
- checkOpen();
- return new DelegatingStatement(this, delegate.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability));
- }
-
- @Override
- public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
- checkOpen();
- return new DelegatingCallableStatement(this, delegate.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability));
- }
-
- @Override
- public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
- checkOpen();
- return new DelegatingPreparedStatement(this, delegate.prepareStatement(sql, autoGeneratedKeys));
- }
-
- @Override
- public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
- checkOpen();
- return new DelegatingPreparedStatement(this,delegate.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability));
- }
-
- @Override
- public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
- checkOpen();
- return new DelegatingPreparedStatement(this, delegate.prepareStatement(sql, columnIndexes));
- }
-
- @Override
- public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
- checkOpen();
- return new DelegatingPreparedStatement(this, delegate.prepareStatement(sql, columnNames));
}
/**