If the user changes the validation query from non-empty to empty, I
think the code could leave the original query untouched.
I think it would be safer to do the following:
String validationQuery = getCheckQuery();
if (!StringUtils.isBlank(validationQuery)) {
dataSource.setValidationQuery(validationQuery);
} else {
dataSource.setValidationQuery(null);
}
On 5 July 2016 at 20:45, <[email protected]> wrote:
> Author: fschumacher
> Date: Tue Jul 5 19:45:30 2016
> New Revision: 1751545
>
> URL: http://svn.apache.org/viewvc?rev=1751545&view=rev
> Log:
> Use isValid() method from jdbc driver, if no validationQuery
> is given in JDBC Connection Configuration.
>
> Bugzilla Id: 59803
>
> Modified:
>
> jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java
> jmeter/trunk/xdocs/changes.xml
> jmeter/trunk/xdocs/usermanual/component_reference.xml
>
> Modified:
> jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java
> URL:
> http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java?rev=1751545&r1=1751544&r2=1751545&view=diff
> ==============================================================================
> ---
> jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java
> (original)
> +++
> jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java
> Tue Jul 5 19:45:30 2016
> @@ -25,6 +25,7 @@ import java.util.Map;
> import java.util.Set;
>
> import org.apache.commons.dbcp2.BasicDataSource;
> +import org.apache.commons.lang3.StringUtils;
> import org.apache.jmeter.config.ConfigElement;
> import org.apache.jmeter.testbeans.TestBean;
> import org.apache.jmeter.testbeans.TestBeanHelper;
> @@ -209,7 +210,10 @@ public class DataSourceElement extends A
>
> if(isKeepAlive()) {
> dataSource.setTestWhileIdle(true);
> - dataSource.setValidationQuery(getCheckQuery());
> + String validationQuery = getCheckQuery();
> + if (!StringUtils.isBlank(validationQuery)) {
> + dataSource.setValidationQuery(validationQuery);
> + }
>
> dataSource.setSoftMinEvictableIdleTimeMillis(Long.parseLong(getConnectionAge()));
>
> dataSource.setTimeBetweenEvictionRunsMillis(Integer.parseInt(getTrimInterval()));
> }
>
> Modified: jmeter/trunk/xdocs/changes.xml
> URL:
> http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1751545&r1=1751544&r2=1751545&view=diff
> ==============================================================================
> --- jmeter/trunk/xdocs/changes.xml (original)
> +++ jmeter/trunk/xdocs/changes.xml Tue Jul 5 19:45:30 2016
> @@ -110,6 +110,8 @@ Summary
>
> <h3>General</h3>
> <ul>
> + <li><bug>59803</bug>Use <code>isValid()</code> method from jdbc driver,
> if no validationQuery
> + is given in JDBC Connection Configuration.</li>
> </ul>
>
> <ch_section>Non-functional changes</ch_section>
>
> Modified: jmeter/trunk/xdocs/usermanual/component_reference.xml
> URL:
> http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=1751545&r1=1751544&r2=1751545&view=diff
> ==============================================================================
> --- jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
> +++ jmeter/trunk/xdocs/usermanual/component_reference.xml Tue Jul 5 19:45:30
> 2016
> @@ -4061,10 +4061,10 @@ 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#getSoftMinEvictableIdleTimeMillis--">BasicDataSource.html#getSoftMinEvictableIdleTimeMillis</a>.
> Defaults to 5000 (5 seconds)
> </property>
> - <property name="Validation Query" required="Yes">A simple query used
> to determine if the database is still responding.
> - This defaults to 'SELECT 1' which is suitable for many databases.
> - However some may require a different query; for example Oracle
> requires something like 'SELECT 1 FROM DUAL'.
> - Note this validation query is used on pool creation to validate it
> even if "Test While Idle" suggests query would only be used on idle
> connections.
> + <property name="Validation Query" required="No">A simple query used
> to determine if the database is still responding.
> + This defaults to the '<code>isValid()</code>' method of the jdbc
> driver, which is suitable for many databases.
> + However some may require a different query; for example Oracle
> something like '<code>SELECT 1 FROM DUAL</code>' could be used.
> + Note this validation query is used on pool creation to validate it
> even if "<code>Test While Idle</code>" suggests query would only be used on
> idle connections.
> This is DBCP behaviour.
> </property>
> <property name="Database URL" required="Yes">JDBC Connection string
> for the database.</property>
>
>