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 1d1d4e9 [DBCP-579] Performance of
DelegatingConnection.prepareStatement(String) regressed enormously in 2.8.0
compared to 1.4.
1d1d4e9 is described below
commit 1d1d4e988afca3499224f785a2740f35d7cb6e1c
Author: Gary Gregory <[email protected]>
AuthorDate: Wed Jul 7 10:35:50 2021 -0400
[DBCP-579] Performance of DelegatingConnection.prepareStatement(String)
regressed enormously in 2.8.0 compared to 1.4.
- DelegatingConnection should also cache connection schema string to avoid
calling the Connection#getSchema() for - each key creation.
- DelegatingConnection should also cache connection catalog string to avoid
calling the Connection#getCatalog() for each key creation.
---
src/changes/changes.xml | 5 +++++
.../apache/commons/dbcp2/DelegatingConnection.java | 24 ++++++++++++++++++++--
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 1fcec52..04594d8 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -150,6 +150,11 @@ The <action> type attribute can be add,update,fix,remove.
<action dev="ggregory" type="fix" due-to="Gary Gregory">
Internal package private UserPassKey class stores its user name as a
char[] as it already does the password.
</action>
+ <action issue="DBCP-579" dev="ggregory" type="fix" due-to="Shaktisinh
Jhala, Gary Gregory">
+ Performance of DelegatingConnection.prepareStatement(String)
regressed enormously in 2.8.0 compared to 1.4.
+ DelegatingConnection should also cache connection schema string to
avoid calling the Connection#getSchema() for each key creation.
+ DelegatingConnection should also cache connection catalog string to
avoid calling the Connection#getCatalog() for each key creation.
+ </action>
<!-- UPDATES -->
<action dev="ggregory" type="update" due-to="Dependabot">
Bump mockito-core from 3.5.11 to 3.11.2 #66, #72, #77, #85, #91, #105,
#110, #116.
diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java
b/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java
index 1b41d44..404ab2b 100644
--- a/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java
+++ b/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java
@@ -71,6 +71,8 @@ public class DelegatingConnection<C extends Connection>
extends AbandonedTrace i
private boolean cacheState = true;
private Boolean cachedAutoCommit;
private Boolean cachedReadOnly;
+ private String cachedCatalog;
+ private String cachedSchema;
private Integer defaultQueryTimeoutSeconds;
/**
@@ -406,8 +408,12 @@ public class DelegatingConnection<C extends Connection>
extends AbandonedTrace i
@Override
public String getCatalog() throws SQLException {
checkOpen();
+ if (cacheState && cachedCatalog != null) {
+ return cachedCatalog;
+ }
try {
- return connection.getCatalog();
+ cachedCatalog = connection.getCatalog();
+ return cachedCatalog;
} catch (final SQLException e) {
handleException(e);
return null;
@@ -532,6 +538,8 @@ public class DelegatingConnection<C extends Connection>
extends AbandonedTrace i
public void clearCachedState() {
cachedAutoCommit = null;
cachedReadOnly = null;
+ cachedSchema = null;
+ cachedCatalog = null;
if (connection instanceof DelegatingConnection) {
((DelegatingConnection<?>) connection).clearCachedState();
}
@@ -556,7 +564,11 @@ public class DelegatingConnection<C extends Connection>
extends AbandonedTrace i
checkOpen();
try {
connection.setCatalog(catalog);
+ if (cacheState) {
+ cachedCatalog = connection.getCatalog();
+ }
} catch (final SQLException e) {
+ cachedCatalog = null;
handleException(e);
}
}
@@ -948,7 +960,11 @@ public class DelegatingConnection<C extends Connection>
extends AbandonedTrace i
checkOpen();
try {
Jdbc41Bridge.setSchema(connection, schema);
+ if (cacheState) {
+ cachedSchema = connection.getSchema();
+ }
} catch (final SQLException e) {
+ cachedSchema = null;
handleException(e);
}
}
@@ -956,8 +972,12 @@ public class DelegatingConnection<C extends Connection>
extends AbandonedTrace i
@Override
public String getSchema() throws SQLException {
checkOpen();
+ if (cacheState && cachedSchema != null) {
+ return cachedSchema;
+ }
try {
- return Jdbc41Bridge.getSchema(connection);
+ cachedSchema = Jdbc41Bridge.getSchema(connection);
+ return cachedSchema;
} catch (final SQLException e) {
handleException(e);
return null;