You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2013/07/24 11:04:17 UTC

svn commit: r1506447 - in /commons/proper/dbcp/trunk/src: changes/changes.xml java/org/apache/commons/dbcp2/LocalStrings.properties java/org/apache/commons/dbcp2/PoolableConnectionFactory.java java/org/apache/commons/dbcp2/Utils.java

Author: markt
Date: Wed Jul 24 09:04:17 2013
New Revision: 1506447

URL: http://svn.apache.org/r1506447
Log:
JIRA-154
Log (at debug level) when a connection fails validation.
This commit also adds i18n support.

Added:
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/LocalStrings.properties   (with props)
Modified:
    commons/proper/dbcp/trunk/src/changes/changes.xml
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/Utils.java

Modified: commons/proper/dbcp/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/changes/changes.xml?rev=1506447&r1=1506446&r2=1506447&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/changes/changes.xml (original)
+++ commons/proper/dbcp/trunk/src/changes/changes.xml Wed Jul 24 09:04:17 2013
@@ -43,6 +43,9 @@ The <action> type attribute can be add,u
      4.1, so requires Java 7.  Java 6 users should use DBCP 1.4.x which supports
      JDBC 4. Java 1.4 and Java 5 users should use DBCP 1.3.x which supports JDBC
      3. Applications running under Java 7 should use DBCP 2.0.x.">
+      <action issue="DBCP-154" dev="markt" type="fix">
+        Log validation failures of poolable connections.
+      </action>
       <action issue="DBCP-322" dev="sebb" type="fix">
         CPDSConnectionFactory.validateObject(Object) ignores Throwable.
       </action>

Added: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/LocalStrings.properties
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/LocalStrings.properties?rev=1506447&view=auto
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/LocalStrings.properties (added)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/LocalStrings.properties Wed Jul 24 09:04:17 2013
@@ -0,0 +1,16 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+poolableConnectionFactory.validateObject.fail=Failed to validate a poolable connection
\ No newline at end of file

Propchange: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/LocalStrings.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java?rev=1506447&r1=1506446&r2=1506447&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java Wed Jul 24 09:04:17 2013
@@ -22,6 +22,9 @@ import java.sql.Statement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.Collection;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.commons.pool2.KeyedObjectPool;
 import org.apache.commons.pool2.PoolableObjectFactory;
 import org.apache.commons.pool2.ObjectPool;
@@ -41,6 +44,9 @@ import org.apache.commons.pool2.impl.Gen
 public class PoolableConnectionFactory
         implements PoolableObjectFactory<PoolableConnection> {
 
+    private static final Log log =
+            LogFactory.getLog(PoolableConnectionFactory.class);
+
     /**
      * Create a new <tt>PoolableConnectionFactory</tt>.
      * @param connFactory the {@link ConnectionFactory} from which to obtain
@@ -222,6 +228,10 @@ public class PoolableConnectionFactory
             validateConnection(conn);
             return true;
         } catch(Exception e) {
+            if (log.isDebugEnabled()) {
+                log.debug(Utils.getMessage(
+                        "poolableConnectionFactory.validateObject.fail"), e);
+            }
             return false;
         }
     }

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/Utils.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/Utils.java?rev=1506447&r1=1506446&r2=1506447&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/Utils.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/Utils.java Wed Jul 24 09:04:17 2013
@@ -13,7 +13,7 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- * 
+ *
  */
 
 package org.apache.commons.dbcp2;
@@ -21,19 +21,24 @@ package org.apache.commons.dbcp2;
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.Statement;
+import java.text.MessageFormat;
+import java.util.ResourceBundle;
 
 /**
  * Utility methods
  */
 public class Utils {
 
+    private static final ResourceBundle messages = ResourceBundle.getBundle(
+            Utils.class.getPackage().getName() + ".LocalStrings");
+
     private Utils() {
         // not instantiable
     }
 
     /**
      * Closes the ResultSet (which may be null).
-     * 
+     *
      * @param rset a ResultSet, may be {@code null}
      */
     public static void closeQuietly(ResultSet rset) {
@@ -48,7 +53,7 @@ public class Utils {
 
     /**
      * Closes the Connection (which may be null).
-     * 
+     *
      * @param conn a Connection, may be {@code null}
      */
     public static void closeQuietly(Connection conn) {
@@ -63,7 +68,7 @@ public class Utils {
 
     /**
      * Closes the Statement (which may be null).
-     * 
+     *
      * @param stmt a Statement, may be {@code null}
      */
     public static void closeQuietly(Statement stmt) {
@@ -75,4 +80,27 @@ public class Utils {
             }
         }
     }
+
+
+    /**
+     * Obtain the correct i18n message for the given key.
+     */
+    public static String getMessage(String key) {
+        return getMessage(key, (Object[]) null);
+    }
+
+
+    /**
+     * Obtain the correct i18n message for the given key with placeholders
+     * replaced by the supplied arguments.
+     */
+    public static String getMessage(String key, Object... args) {
+        String msg =  messages.getString(key);
+        if (args == null || args.length == 0) {
+            return msg;
+        } else {
+            MessageFormat mf = new MessageFormat(msg);
+            return mf.format(args, new StringBuffer(), null).toString();
+        }
+    }
 }