This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git


The following commit(s) were added to refs/heads/master by this push:
     new c352855  Allow pooling of Prepared Statements in JDBC
c352855 is described below

commit c3528555f445cea46919e414731d96ebe6d1111c
Author: Felix Schumacher <[email protected]>
AuthorDate: Sat Aug 21 13:56:40 2021 +0200

    Allow pooling of Prepared Statements in JDBC
    
    Bugzilla Id: 65515
---
 .../protocol/jdbc/config/DataSourceElement.java    |  46 +++++++++++++++------
 .../jdbc/config/DataSourceElementBeanInfo.java     |   6 ++-
 .../config/DataSourceElementResources.properties   |   2 +
 xdocs/changes.xml                                  |   1 +
 .../screenshots/jdbc-config/jdbc-conn-config.png   | Bin 37115 -> 19902 bytes
 xdocs/usermanual/component_reference.xml           |   1 +
 6 files changed, 42 insertions(+), 14 deletions(-)

diff --git 
a/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java
 
b/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java
index 1abd0ee..35a0e66 100644
--- 
a/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java
+++ 
b/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java
@@ -45,7 +45,7 @@ public class DataSourceElement extends AbstractTestElement
     implements ConfigElement, TestStateListener, TestBean {
     private static final Logger log = 
LoggerFactory.getLogger(DataSourceElement.class);
 
-    private static final long serialVersionUID = 234L;
+    private static final long serialVersionUID = 235L;
 
     private transient String dataSource;
     private transient String driver;
@@ -60,6 +60,7 @@ public class DataSourceElement extends AbstractTestElement
     private transient String timeout;
     private transient String trimInterval;
     private transient String transactionIsolation;
+    private transient String poolPreparedStatements;
 
     private transient boolean keepAlive;
     private transient boolean autocommit;
@@ -214,18 +215,8 @@ public class DataSourceElement extends AbstractTestElement
         BasicDataSource dataSource = new BasicDataSource();
 
         if (log.isDebugEnabled()) {
-            StringBuilder sb = new StringBuilder(40);
-            sb.append("MaxPool: ");
-            sb.append(maxPool);
-            sb.append(" Timeout: ");
-            sb.append(getTimeout());
-            sb.append(" TrimInt: ");
-            sb.append(getTrimInterval());
-            sb.append(" Auto-Commit: ");
-            sb.append(isAutocommit());
-            sb.append(" Preinit: ");
-            sb.append(isPreinit());
-            log.debug(sb.toString());
+            log.debug("MaxPool: {} Timeout: {} TrimInt: {} Auto-Commit: {} 
Preinit: {} poolPreparedStatements: {}",
+                    maxPool, getTimeout(), getTrimInterval(), isAutocommit(), 
isPreinit(), poolPreparedStatements);
         }
         int poolSize = Integer.parseInt(maxPool);
         dataSource.setMinIdle(0);
@@ -240,6 +231,15 @@ public class DataSourceElement extends AbstractTestElement
         if(StringUtils.isNotEmpty(connectionProperties)) {
             dataSource.setConnectionProperties(connectionProperties);
         }
+        if (StringUtils.isNotEmpty(poolPreparedStatements)) {
+            int maxPreparedStatements = 
Integer.parseInt(poolPreparedStatements);
+            if (maxPreparedStatements < 0) {
+                dataSource.setPoolPreparedStatements(false);
+            } else {
+                dataSource.setPoolPreparedStatements(true);
+                dataSource.setMaxOpenPreparedStatements(10);
+            }
+        }
         dataSource.setRollbackOnReturn(false);
         dataSource.setMaxIdle(poolSize);
         dataSource.setMaxTotal(poolSize);
@@ -643,4 +643,24 @@ public class DataSourceElement extends AbstractTestElement
     public void setConnectionProperties(String connectionProperties) {
         this.connectionProperties = connectionProperties;
     }
+
+    /**
+     * Return the max number of pooled prepared statements. "0" means no limit
+     * on prepared statements to pool and "-1" disables pooling.
+     *
+     * @return the max number of pooled prepared statements
+     */
+    public String getPoolPreparedStatements() {
+        return poolPreparedStatements;
+    }
+
+    /**
+     * Set the max number of pooled prepared statements. "0" means no limit
+     * on prepared statements to pool and "-1" disables pooling.
+     *
+     * @param poolPreparedStatements max number of prepared statements
+     */
+    public void setPoolPreparedStatements(String poolPreparedStatements) {
+        this.poolPreparedStatements = poolPreparedStatements;
+    }
 }
diff --git 
a/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/config/DataSourceElementBeanInfo.java
 
b/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/config/DataSourceElementBeanInfo.java
index 6c0edeb..7dd9046 100644
--- 
a/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/config/DataSourceElementBeanInfo.java
+++ 
b/src/protocol/jdbc/src/main/java/org/apache/jmeter/protocol/jdbc/config/DataSourceElementBeanInfo.java
@@ -50,7 +50,7 @@ public class DataSourceElementBeanInfo extends 
BeanInfoSupport {
         createPropertyGroup("varName", new String[] { "dataSource" });
 
         createPropertyGroup("pool", new String[] { "poolMax", "timeout",
-                "trimInterval", "autocommit", "transactionIsolation", 
"preinit", "initQuery" });
+                "trimInterval", "autocommit", "transactionIsolation", 
"poolPreparedStatements", "preinit", "initQuery" });
 
         createPropertyGroup("keep-alive", new String[] { "keepAlive", 
"connectionAge", "checkQuery" });
 
@@ -78,6 +78,10 @@ public class DataSourceElementBeanInfo extends 
BeanInfoSupport {
         Set<String> modesSet = TRANSACTION_ISOLATION_MAP.keySet();
         String[] modes = modesSet.toArray(new String[modesSet.size()]);
         p.setValue(TAGS, modes);
+        p = property("poolPreparedStatements");
+        p.setValue(NOT_UNDEFINED, Boolean.TRUE);
+        p.setValue(DEFAULT_NOT_SAVED, Boolean.TRUE);
+        p.setValue(DEFAULT, "-1");
         p = property("preinit");
         p.setValue(NOT_UNDEFINED, Boolean.TRUE);
         p.setValue(DEFAULT, Boolean.FALSE);
diff --git 
a/src/protocol/jdbc/src/main/resources/org/apache/jmeter/protocol/jdbc/config/DataSourceElementResources.properties
 
b/src/protocol/jdbc/src/main/resources/org/apache/jmeter/protocol/jdbc/config/DataSourceElementResources.properties
index 00f00d7..022bfb0 100644
--- 
a/src/protocol/jdbc/src/main/resources/org/apache/jmeter/protocol/jdbc/config/DataSourceElementResources.properties
+++ 
b/src/protocol/jdbc/src/main/resources/org/apache/jmeter/protocol/jdbc/config/DataSourceElementResources.properties
@@ -52,3 +52,5 @@ transactionIsolation.displayName=Transaction Isolation
 transactionIsolation.shortDescription=Transaction Isolation Level
 preinit.displayName=Preinit Pool
 preinit.shortDescription=Preinitialize the whole connection pool by requesting 
one connection from it.
+poolPreparedStatements.displayName=Pool Prepared Statements
+poolPreparedStatements.shortDescription=Max Prepared Statements to cache per 
connection. "-1" disables the caching and "0" sets no limit on caching.
diff --git a/xdocs/changes.xml b/xdocs/changes.xml
index aec3819..975ef7b 100644
--- a/xdocs/changes.xml
+++ b/xdocs/changes.xml
@@ -109,6 +109,7 @@ Summary
 <ul>
     <li><pr>638</pr>Bolt Connection Configuration: added 
<code>ConnectionPoolMaxSize</code> parameter. Contributed by
         David Pecollet (david.pecollet at gmail.com)</li>
+    <li><bug>65515</bug>Allow pooling of Prepared Statements in JDBC</li>
 </ul>
 
 <h3>Functions</h3>
diff --git a/xdocs/images/screenshots/jdbc-config/jdbc-conn-config.png 
b/xdocs/images/screenshots/jdbc-config/jdbc-conn-config.png
index 1324b9d..003b249 100644
Binary files a/xdocs/images/screenshots/jdbc-config/jdbc-conn-config.png and 
b/xdocs/images/screenshots/jdbc-config/jdbc-conn-config.png differ
diff --git a/xdocs/usermanual/component_reference.xml 
b/xdocs/usermanual/component_reference.xml
index c3e08b7..ef8f840 100644
--- a/xdocs/usermanual/component_reference.xml
+++ b/xdocs/usermanual/component_reference.xml
@@ -4065,6 +4065,7 @@ instead. (see figures 12 and 13).</p>
         See <a 
href="https://commons.apache.org/proper/commons-dbcp/api-2.1.1/org/apache/commons/dbcp2/BasicDataSource.html#getTimeBetweenEvictionRunsMillis--";
 >BasicDataSource.html#getTimeBetweenEvictionRunsMillis</a></property>
         <property name="Auto Commit" required="Yes">Turn auto commit on or off 
for the connections.</property>
         <property name="Transaction isolation" required="Yes">Transaction 
isolation level</property>
+        <property name="Pool Prepared Statements" required="Yes">Max number of 
Prepared Statements to pool per connection. <code>"-1</code>" disables the 
pooling and "<code>0</code>" means unlimited number of Prepared Statements to 
pool. (Defaults to "<code>-1</code>")</property>
         <property name="Preinit Pool" required="No">The connection pool can be 
initialized instantly. If set to <code>False</code> (default), the JDBC request 
samplers using this pool might measure higher response times for the first 
queries – as the connection establishment time for the whole pool is 
included.</property>
         <property name="Init SQL statements separated by new line" 
required="No">A Collection of SQL statements that will be used to initialize 
physical connections when they are first created. These statements are executed 
only once - when the configured connection factory creates the connection. 
</property>
         <property name="Test While Idle" required="Yes">Test idle connections 
of the pool, see <a 
href="https://commons.apache.org/proper/commons-dbcp/api-2.1.1/org/apache/commons/dbcp2/BasicDataSource.html#getTestWhileIdle--";>BasicDataSource.html#getTestWhileIdle</a>.

Reply via email to