This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-dbcp.git
The following commit(s) were added to refs/heads/master by this push:
new 1841d6a7 Move normalization for package private class
PooledConnectionImpl into PStmtKey.
1841d6a7 is described below
commit 1841d6a7c37dc0c65ebb0d6a0bd028ffc1a140ea
Author: Gary Gregory <[email protected]>
AuthorDate: Sun Jul 10 14:06:39 2022 -0400
Move normalization for package private class PooledConnectionImpl into
PStmtKey.
---
.../java/org/apache/commons/dbcp2/PStmtKey.java | 2 +-
.../dbcp2/cpdsadapter/PooledConnectionImpl.java | 42 +++++++---------------
2 files changed, 14 insertions(+), 30 deletions(-)
diff --git a/src/main/java/org/apache/commons/dbcp2/PStmtKey.java
b/src/main/java/org/apache/commons/dbcp2/PStmtKey.java
index e8422986..c1a17d36 100644
--- a/src/main/java/org/apache/commons/dbcp2/PStmtKey.java
+++ b/src/main/java/org/apache/commons/dbcp2/PStmtKey.java
@@ -405,7 +405,7 @@ public class PStmtKey {
private PStmtKey(final String sql, final String catalog, final String
schema, final Integer resultSetType, final Integer resultSetConcurrency,
final Integer resultSetHoldability, final Integer autoGeneratedKeys,
final int[] columnIndexes, final String[] columnNames,
final StatementType statementType, final Function<PStmtKey,
StatementBuilder> statementBuilder) {
- this.sql = sql;
+ this.sql = Objects.requireNonNull(sql, "sql").trim();
this.catalog = catalog;
this.schema = schema;
this.resultSetType = resultSetType;
diff --git
a/src/main/java/org/apache/commons/dbcp2/cpdsadapter/PooledConnectionImpl.java
b/src/main/java/org/apache/commons/dbcp2/cpdsadapter/PooledConnectionImpl.java
index 57bcecd4..c82910be 100644
---
a/src/main/java/org/apache/commons/dbcp2/cpdsadapter/PooledConnectionImpl.java
+++
b/src/main/java/org/apache/commons/dbcp2/cpdsadapter/PooledConnectionImpl.java
@@ -184,7 +184,7 @@ final class PooledConnectionImpl
* @return a {@link PStmtKey} for the given arguments.
*/
protected PStmtKey createKey(final String sql) {
- return new PStmtKey(normalizeSQL(sql), getCatalogOrNull(),
getSchemaOrNull());
+ return new PStmtKey(sql, getCatalogOrNull(), getSchemaOrNull());
}
/**
@@ -198,7 +198,7 @@ final class PooledConnectionImpl
* @return a key to uniquely identify a prepared statement.
*/
protected PStmtKey createKey(final String sql, final int
autoGeneratedKeys) {
- return new PStmtKey(normalizeSQL(sql), getCatalogOrNull(),
getSchemaOrNull(), autoGeneratedKeys);
+ return new PStmtKey(sql, getCatalogOrNull(), getSchemaOrNull(),
autoGeneratedKeys);
}
/**
@@ -215,8 +215,7 @@ final class PooledConnectionImpl
* @return a key to uniquely identify a prepared statement.
*/
protected PStmtKey createKey(final String sql, final int resultSetType,
final int resultSetConcurrency) {
- return new PStmtKey(normalizeSQL(sql), getCatalogOrNull(),
getSchemaOrNull(), resultSetType,
- resultSetConcurrency);
+ return new PStmtKey(sql, getCatalogOrNull(), getSchemaOrNull(),
resultSetType, resultSetConcurrency);
}
/**
@@ -235,10 +234,8 @@ final class PooledConnectionImpl
* or {@code ResultSet.CLOSE_CURSORS_AT_COMMIT}.
* @return a key to uniquely identify a prepared statement.
*/
- protected PStmtKey createKey(final String sql, final int resultSetType,
final int resultSetConcurrency,
- final int resultSetHoldability) {
- return new PStmtKey(normalizeSQL(sql), getCatalogOrNull(),
getSchemaOrNull(), resultSetType,
- resultSetConcurrency, resultSetHoldability);
+ protected PStmtKey createKey(final String sql, final int resultSetType,
final int resultSetConcurrency, final int resultSetHoldability) {
+ return new PStmtKey(sql, getCatalogOrNull(), getSchemaOrNull(),
resultSetType, resultSetConcurrency, resultSetHoldability);
}
/**
@@ -260,10 +257,9 @@ final class PooledConnectionImpl
* @return a key to uniquely identify a prepared statement.
* @since 2.4.0
*/
- protected PStmtKey createKey(final String sql, final int resultSetType,
final int resultSetConcurrency,
- final int resultSetHoldability, final StatementType statementType)
{
- return new PStmtKey(normalizeSQL(sql), getCatalogOrNull(),
getSchemaOrNull(), resultSetType,
- resultSetConcurrency, resultSetHoldability, statementType);
+ protected PStmtKey createKey(final String sql, final int resultSetType,
final int resultSetConcurrency, final int resultSetHoldability,
+ final StatementType statementType) {
+ return new PStmtKey(sql, getCatalogOrNull(), getSchemaOrNull(),
resultSetType, resultSetConcurrency, resultSetHoldability, statementType);
}
/**
@@ -282,10 +278,8 @@ final class PooledConnectionImpl
* @return a key to uniquely identify a prepared statement.
* @since 2.4.0
*/
- protected PStmtKey createKey(final String sql, final int resultSetType,
final int resultSetConcurrency,
- final StatementType statementType) {
- return new PStmtKey(normalizeSQL(sql), getCatalogOrNull(),
getSchemaOrNull(), resultSetType,
- resultSetConcurrency, statementType);
+ protected PStmtKey createKey(final String sql, final int resultSetType,
final int resultSetConcurrency, final StatementType statementType) {
+ return new PStmtKey(sql, getCatalogOrNull(), getSchemaOrNull(),
resultSetType, resultSetConcurrency, statementType);
}
/**
@@ -299,7 +293,7 @@ final class PooledConnectionImpl
* @return a key to uniquely identify a prepared statement.
*/
protected PStmtKey createKey(final String sql, final int[] columnIndexes) {
- return new PStmtKey(normalizeSQL(sql), getCatalogOrNull(),
getSchemaOrNull(), columnIndexes);
+ return new PStmtKey(sql, getCatalogOrNull(), getSchemaOrNull(),
columnIndexes);
}
/**
@@ -312,7 +306,7 @@ final class PooledConnectionImpl
* @return a key to uniquely identify a prepared statement.
*/
protected PStmtKey createKey(final String sql, final StatementType
statementType) {
- return new PStmtKey(normalizeSQL(sql), getCatalogOrNull(),
getSchemaOrNull(), statementType);
+ return new PStmtKey(sql, getCatalogOrNull(), getSchemaOrNull(),
statementType);
}
/**
@@ -325,7 +319,7 @@ final class PooledConnectionImpl
* @return a key to uniquely identify a prepared statement.
*/
protected PStmtKey createKey(final String sql, final String[] columnNames)
{
- return new PStmtKey(normalizeSQL(sql), getCatalogOrNull(),
getSchemaOrNull(), columnNames);
+ return new PStmtKey(sql, getCatalogOrNull(), getSchemaOrNull(),
columnNames);
}
/**
@@ -434,16 +428,6 @@ final class PooledConnectionImpl
return new DefaultPooledObject<>(pcs);
}
- /**
- * Normalizes the given SQL statement, producing a canonical form that is
semantically equivalent to the original.
- * @param sql
- * The SQL statement.
- * @return the normalized SQL statement.
- */
- protected String normalizeSQL(final String sql) {
- return sql.trim();
- }
-
/**
* Sends a connectionClosed event.
*/