Author: kfujino
Date: Tue Nov 15 05:28:17 2016
New Revision: 1769728

URL: http://svn.apache.org/viewvc?rev=1769728&view=rev
Log:
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=60194
If validationQuery is not specified, connection validation is done by calling 
the isValid() method.

Modified:
    tomcat/tc8.5.x/trunk/modules/jdbc-pool/doc/jdbc-pool.xml
    
tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
    tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml

Modified: tomcat/tc8.5.x/trunk/modules/jdbc-pool/doc/jdbc-pool.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/modules/jdbc-pool/doc/jdbc-pool.xml?rev=1769728&r1=1769727&r2=1769728&view=diff
==============================================================================
--- tomcat/tc8.5.x/trunk/modules/jdbc-pool/doc/jdbc-pool.xml (original)
+++ tomcat/tc8.5.x/trunk/modules/jdbc-pool/doc/jdbc-pool.xml Tue Nov 15 
05:28:17 2016
@@ -277,8 +277,6 @@
     <attribute name="testOnBorrow" required="false">
       <p>(boolean) The indication of whether objects will be validated before 
being borrowed from the pool.
          If the object fails to validate, it will be dropped from the pool, 
and we will attempt to borrow another.
-         NOTE - for a true value to have any effect, the 
<code>validationQuery</code>
-         or <code>validatorClassName</code> parameter must be set to a 
non-null string.
          In order to have a more efficient validation, see 
<code>validationInterval</code>.
          Default value is <code>false</code>
       </p>
@@ -287,16 +285,12 @@
     <attribute name="testOnConnect" required="false">
       <p>(boolean) The indication of whether objects will be validated when a 
connection is first created.
          If an object fails to validate, it will be throw 
<code>SQLException</code>.
-         NOTE - for a true value to have any effect, the 
<code>validationQuery</code>, <code>initSQL</code>
-         or <code>validatorClassName</code> parameter must be set to a 
non-null string.
          Default value is <code>false</code>
       </p>
     </attribute>
 
     <attribute name="testOnReturn" required="false">
       <p>(boolean) The indication of whether objects will be validated before 
being returned to the pool.
-         NOTE - for a true value to have any effect, the 
<code>validationQuery</code>
-         or <code>validatorClassName</code> parameter must be set to a 
non-null string.
          The default value is <code>false</code>.
       </p>
     </attribute>
@@ -304,8 +298,6 @@
     <attribute name="testWhileIdle" required="false">
       <p>(boolean) The indication of whether objects will be validated by the 
idle object evictor (if any).
          If an object fails to validate, it will be dropped from the pool.
-         NOTE - for a true value to have any effect, the 
<code>validationQuery</code>
-         or <code>validatorClassName</code> parameter must be set to a 
non-null string.
          The default value is <code>false</code> and this property has to be 
set in order for the
          pool cleaner/test thread is to run (also see 
<code>timeBetweenEvictionRunsMillis</code>)
       </p>
@@ -315,6 +307,7 @@
       <p>(String) The SQL query that will be used to validate connections from 
this pool before returning them to the caller.
          If specified, this query does not have to return any data, it just 
can't throw a <code>SQLException</code>.
          The default value is <code>null</code>.
+         If not specified, connections will be validation by the isValid() 
method.
          Example values are <code>SELECT 1</code>(mysql), <code>select 1 from 
dual</code>(oracle), <code>SELECT 1</code>(MS Sql Server)
       </p>
     </attribute>

Modified: 
tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PooledConnection.java?rev=1769728&r1=1769727&r2=1769728&view=diff
==============================================================================
--- 
tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
 (original)
+++ 
tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
 Tue Nov 15 05:28:17 2016
@@ -497,6 +497,29 @@ public class PooledConnection {
             query = poolProperties.getValidationQuery();
         }
 
+        if (query == null) {
+            int validationQueryTimeout = 
poolProperties.getValidationQueryTimeout();
+            if (validationQueryTimeout < 0) validationQueryTimeout = 0;
+            try {
+                if (connection.isValid(validationQueryTimeout)) {
+                    this.lastValidated = now;
+                    return true;
+                } else {
+                    if (getPoolProperties().getLogValidationErrors()) {
+                        log.error("isValid() returned false.");
+                    }
+                    return false;
+                }
+            } catch (SQLException e) {
+                if (getPoolProperties().getLogValidationErrors()) {
+                    log.error("isValid() failed.", e);
+                } else if (log.isDebugEnabled()) {
+                    log.debug("isValid() failed.", e);
+                }
+                return false;
+            }
+        }
+
         Statement stmt = null;
         try {
             stmt = connection.createStatement();

Modified: tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml?rev=1769728&r1=1769727&r2=1769728&view=diff
==============================================================================
--- tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml Tue Nov 15 05:28:17 2016
@@ -79,6 +79,15 @@
       </fix>
     </changelog>
   </subsection>
+  <subsection name="jdbc-pool">
+    <changelog>
+      <fix>
+        <bug>60194</bug>: If <code>validationQuery</code> is not specified,
+        connection validation is done by calling the <code>isValid()</code>
+        method. (kfujino)
+      </fix>
+    </changelog>
+  </subsection>
   <subsection name="Other">
     <changelog>
       <fix>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to