Author: markt
Date: Thu Aug  1 14:29:21 2013
New Revision: 1509249

URL: http://svn.apache.org/r1509249
Log:
Use the new SwallowedExceptionListener interface for all instances of GOP used 
by DBCP

Added:
    
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/SwallowedExceptionLogger.java
   (with props)
Modified:
    
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/BasicDataSource.java
    
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/LocalStrings.properties
    
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java

Modified: 
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/BasicDataSource.java
URL: 
http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/BasicDataSource.java?rev=1509249&r1=1509248&r2=1509249&view=diff
==============================================================================
--- 
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/BasicDataSource.java
 (original)
+++ 
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/BasicDataSource.java
 Thu Aug  1 14:29:21 2013
@@ -33,6 +33,8 @@ import java.sql.SQLFeatureNotSupportedEx
 
 import javax.sql.DataSource;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.commons.pool2.PooledObject;
 import org.apache.commons.pool2.impl.AbandonedConfig;
 import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig;
@@ -56,6 +58,9 @@ import org.apache.commons.pool2.impl.Gen
  */
 public class BasicDataSource implements DataSource {
 
+    private static final Log log =
+            LogFactory.getLog(BasicDataSource.class);
+
     static {
         // Attempt to prevent deadlocks - see DBCP - 272
         DriverManager.getDrivers();
@@ -1790,6 +1795,7 @@ public class BasicDataSource implements 
         gop.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
         gop.setTestWhileIdle(testWhileIdle);
         gop.setLifo(lifo);
+        gop.setSwallowedExceptionListener(new SwallowedExceptionLogger(log));
         factory.setPool(gop);
         connectionPool = gop;
     }

Modified: 
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=1509249&r1=1509248&r2=1509249&view=diff
==============================================================================
--- 
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/LocalStrings.properties
 (original)
+++ 
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/LocalStrings.properties
 Thu Aug  1 14:29:21 2013
@@ -15,4 +15,6 @@
 
 connectionFactory.lifetimeExceeded=The lifetime of the connection [{0}] 
milliseconds exceeds the maximum permitted value of [{1}] milliseconds
 
-poolableConnectionFactory.validateObject.fail=Failed to validate a poolable 
connection
\ No newline at end of file
+poolableConnectionFactory.validateObject.fail=Failed to validate a poolable 
connection
+
+swallowedExceptionLogger.onSwallowedException=An internal object pool 
swallowed an Exception
\ No newline at end of file

Added: 
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/SwallowedExceptionLogger.java
URL: 
http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/SwallowedExceptionLogger.java?rev=1509249&view=auto
==============================================================================
--- 
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/SwallowedExceptionLogger.java
 (added)
+++ 
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/SwallowedExceptionLogger.java
 Thu Aug  1 14:29:21 2013
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+package org.apache.commons.dbcp2;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.pool2.SwallowedExceptionListener;
+
+public class SwallowedExceptionLogger implements SwallowedExceptionListener{
+
+    private final Log log;
+
+    public SwallowedExceptionLogger(Log log) {
+        this.log = log;
+    }
+
+    @Override
+    public void onSwallowException(Exception e) {
+        log.warn(Utils.getMessage(
+                "swallowedExceptionLogger.onSwallowedException"), e);
+    }
+}

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

Modified: 
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java
URL: 
http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java?rev=1509249&r1=1509248&r2=1509249&view=diff
==============================================================================
--- 
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java
 (original)
+++ 
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java
 Thu Aug  1 14:29:21 2013
@@ -30,6 +30,9 @@ import javax.naming.Reference;
 import javax.naming.StringRefAddr;
 import javax.sql.ConnectionPoolDataSource;
 
+import org.apache.commons.dbcp2.SwallowedExceptionLogger;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.commons.pool2.ObjectPool;
 import org.apache.commons.pool2.impl.GenericObjectPool;
 import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
@@ -59,6 +62,9 @@ public class PerUserPoolDataSource exten
 
     private static final long serialVersionUID = -3104731034410444060L;
 
+    private static final Log log =
+            LogFactory.getLog(PerUserPoolDataSource.class);
+
     private int defaultMaxTotal = GenericObjectPoolConfig.DEFAULT_MAX_TOTAL;
     private int defaultMaxIdle = GenericObjectPoolConfig.DEFAULT_MAX_IDLE;
     private int defaultMaxWaitMillis = (int)Math.min(Integer.MAX_VALUE,
@@ -543,6 +549,7 @@ public class PerUserPoolDataSource exten
         pool.setNumTestsPerEvictionRun(getNumTestsPerEvictionRun());
         pool.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
         pool.setTestWhileIdle(getTestWhileIdle());
+        pool.setSwallowedExceptionListener(new SwallowedExceptionLogger(log));
 
         Object old = managers.put(getPoolKey(username,password), factory);
         if (old != null) {


Reply via email to