You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2018/07/13 00:25:47 UTC
[07/50] [abbrv] commons-dbcp git commit: Refactor duplicate code.
Refactor duplicate code.
Project: http://git-wip-us.apache.org/repos/asf/commons-dbcp/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-dbcp/commit/8e4a5652
Tree: http://git-wip-us.apache.org/repos/asf/commons-dbcp/tree/8e4a5652
Diff: http://git-wip-us.apache.org/repos/asf/commons-dbcp/diff/8e4a5652
Branch: refs/heads/release
Commit: 8e4a56526f342b5ebaf36ea2003a614ddb7e4059
Parents: a78ebb0
Author: Gary Gregory <ga...@gmail.com>
Authored: Wed Jun 20 08:54:18 2018 -0600
Committer: Gary Gregory <ga...@gmail.com>
Committed: Wed Jun 20 08:54:18 2018 -0600
----------------------------------------------------------------------
.../apache/commons/dbcp2/PoolingConnection.java | 91 ++++++--------------
1 file changed, 24 insertions(+), 67 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/8e4a5652/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java b/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java
index 8b2ffa0..e97b034 100644
--- a/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java
+++ b/src/main/java/org/apache/commons/dbcp2/PoolingConnection.java
@@ -125,23 +125,7 @@ public class PoolingConnection extends DelegatingConnection<Connection>
* @return the PStmtKey created for the given arguments.
*/
protected PStmtKey createKey(final String sql) {
- String catalog = null;
- try {
- catalog = getCatalog();
- } catch (final SQLException e) {
- // Ignored
- }
- return new PStmtKey(normalizeSQL(sql), catalog);
- }
-
- protected PStmtKey createKey(final String sql, final int autoGeneratedKeys) {
- String catalog = null;
- try {
- catalog = getCatalog();
- } catch (final SQLException e) {
- // Ignored
- }
- return new PStmtKey(normalizeSQL(sql), catalog, autoGeneratedKeys);
+ return new PStmtKey(normalizeSQL(sql), getCatalogOrNull());
}
/**
@@ -155,13 +139,7 @@ public class PoolingConnection extends DelegatingConnection<Connection>
* @return the PStmtKey created for the given arguments.
*/
protected PStmtKey createKey(final String sql, final int columnIndexes[]) {
- String catalog = null;
- try {
- catalog = getCatalog();
- } catch (final SQLException e) {
- // Ignored
- }
- return new PStmtKey(normalizeSQL(sql), catalog, columnIndexes);
+ return new PStmtKey(normalizeSQL(sql), getCatalogOrNull(), columnIndexes);
}
/**
@@ -177,13 +155,7 @@ public class PoolingConnection extends DelegatingConnection<Connection>
* @return the PStmtKey created for the given arguments.
*/
protected PStmtKey createKey(final String sql, final int resultSetType, final int resultSetConcurrency) {
- String catalog = null;
- try {
- catalog = getCatalog();
- } catch (final SQLException e) {
- // Ignored
- }
- return new PStmtKey(normalizeSQL(sql), catalog, resultSetType, resultSetConcurrency);
+ return new PStmtKey(normalizeSQL(sql), getCatalogOrNull(), resultSetType, resultSetConcurrency);
}
/**
@@ -202,13 +174,8 @@ public class PoolingConnection extends DelegatingConnection<Connection>
*/
protected PStmtKey createKey(final String sql, final int resultSetType, final int resultSetConcurrency,
final int resultSetHoldability) {
- String catalog = null;
- try {
- catalog = getCatalog();
- } catch (final SQLException e) {
- // Ignored
- }
- return new PStmtKey(normalizeSQL(sql), catalog, resultSetType, resultSetConcurrency, resultSetHoldability);
+ return new PStmtKey(normalizeSQL(sql), getCatalogOrNull(), resultSetType, resultSetConcurrency,
+ resultSetHoldability);
}
/**
@@ -229,14 +196,8 @@ public class PoolingConnection extends DelegatingConnection<Connection>
*/
protected PStmtKey createKey(final String sql, final int resultSetType, final int resultSetConcurrency,
final int resultSetHoldability, final StatementType stmtType) {
- String catalog = null;
- try {
- catalog = getCatalog();
- } catch (final SQLException e) {
- // Ignored
- }
- return new PStmtKey(normalizeSQL(sql), catalog, resultSetType, resultSetConcurrency, resultSetHoldability,
- stmtType);
+ return new PStmtKey(normalizeSQL(sql), getCatalogOrNull(), resultSetType, resultSetConcurrency,
+ resultSetHoldability, stmtType);
}
/**
@@ -255,13 +216,7 @@ public class PoolingConnection extends DelegatingConnection<Connection>
*/
protected PStmtKey createKey(final String sql, final int resultSetType, final int resultSetConcurrency,
final StatementType stmtType) {
- String catalog = null;
- try {
- catalog = getCatalog();
- } catch (final SQLException e) {
- // Ignored
- }
- return new PStmtKey(normalizeSQL(sql), catalog, resultSetType, resultSetConcurrency, stmtType);
+ return new PStmtKey(normalizeSQL(sql), getCatalogOrNull(), resultSetType, resultSetConcurrency, stmtType);
}
/**
@@ -275,13 +230,7 @@ public class PoolingConnection extends DelegatingConnection<Connection>
* @return the PStmtKey created for the given arguments.
*/
protected PStmtKey createKey(final String sql, final StatementType stmtType) {
- String catalog = null;
- try {
- catalog = getCatalog();
- } catch (final SQLException e) {
- // Ignored
- }
- return new PStmtKey(normalizeSQL(sql), catalog, stmtType, null);
+ return new PStmtKey(normalizeSQL(sql), getCatalogOrNull(), stmtType, null);
}
/**
@@ -295,13 +244,7 @@ public class PoolingConnection extends DelegatingConnection<Connection>
* @return the PStmtKey created for the given arguments.
*/
protected PStmtKey createKey(final String sql, final String columnNames[]) {
- String catalog = null;
- try {
- catalog = getCatalog();
- } catch (final SQLException e) {
- // Ignored
- }
- return new PStmtKey(normalizeSQL(sql), catalog, columnNames);
+ return new PStmtKey(normalizeSQL(sql), getCatalogOrNull(), columnNames);
}
/**
@@ -319,6 +262,20 @@ public class PoolingConnection extends DelegatingConnection<Connection>
pooledObject.getObject().getInnermostDelegate().close();
}
+ private String getCatalogOrNull() {
+ String catalog = null;
+ try {
+ catalog = getCatalog();
+ } catch (final SQLException e) {
+ // Ignored
+ }
+ return catalog;
+ }
+
+ protected PStmtKey createKey(final String sql, final int autoGeneratedKeys) {
+ return new PStmtKey(normalizeSQL(sql), getCatalogOrNull(), autoGeneratedKeys);
+ }
+
/**
* {@link KeyedPooledObjectFactory} method for creating {@link PoolablePreparedStatement}s or
* {@link PoolableCallableStatement}s. The <code>stmtType</code> field in the key determines whether a