commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r893809 - in /commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources: PerUserPoolDataSource.java SharedPoolDataSource.java
Date Thu, 24 Dec 2009 20:12:14 GMT
Author: psteitz
Date: Thu Dec 24 20:12:11 2009
New Revision: 893809

URL: http://svn.apache.org/viewvc?rev=893809&view=rev
Log:
Protect user keys. JIRA:DBCP-291.

Modified:
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/PerUserPoolDataSource.java
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/SharedPoolDataSource.java

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/PerUserPoolDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/PerUserPoolDataSource.java?rev=893809&r1=893808&r2=893809&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/PerUserPoolDataSource.java
(original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/PerUserPoolDataSource.java
Thu Dec 24 20:12:11 2009
@@ -443,18 +443,20 @@
         PoolKey key = null;
         String name = username + password;
         String dsName = getDataSourceName();
-        Map dsMap = (Map) poolKeys.get(dsName);
-        if (dsMap != null) {
-            key = (PoolKey) dsMap.get(name);
-        }
-        
-        if (key == null) {
-            key = new PoolKey(dsName, name);
-            if (dsMap == null) {
-                dsMap = new HashMap();
-                poolKeys.put(dsName, dsMap);
+        synchronized (poolKeys) {
+            Map dsMap = (Map) poolKeys.get(dsName);
+            if (dsMap != null) {
+                key = (PoolKey) dsMap.get(name);
+            }
+
+            if (key == null) {
+                key = new PoolKey(dsName, name);
+                if (dsMap == null) {
+                    dsMap = new HashMap();
+                    poolKeys.put(dsName, dsMap);
+                }
+                dsMap.put(name, key);
             }
-            dsMap.put(name, key);
         }
         return key;
     }

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/SharedPoolDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/SharedPoolDataSource.java?rev=893809&r1=893808&r2=893809&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/SharedPoolDataSource.java
(original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/SharedPoolDataSource.java
Thu Dec 24 20:12:11 2009
@@ -168,20 +168,29 @@
         }
 
         PooledConnectionAndInfo info = null;
+        
+        UserPassKey key = null;
+        synchronized (userKeys) {
+            key = getUserPassKey(username, password);
+        }
+        
         try {
-            info = (PooledConnectionAndInfo) pool
-                .borrowObject(getUserPassKey(username, password));
+            info = (PooledConnectionAndInfo) pool.borrowObject(key);
         }
         catch (SQLException ex) {  // Remove bad UserPassKey
-            if ((userKeys != null) && (userKeys.containsKey(username))) {
-                userKeys.remove(username);
+            if (userKeys != null) {
+                synchronized (userKeys) {
+                    if (userKeys.containsKey(username)) {
+                        userKeys.remove(username);
+                    }
+                }
             }
             throw new SQLNestedException(
-                "Could not retrieve connection info from pool", ex);
+                    "Could not retrieve connection info from pool", ex);
         }
         catch (Exception e) {
             throw new SQLNestedException(
-                "Could not retrieve connection info from pool", e);
+                    "Could not retrieve connection info from pool", e);
         }
         return info;
     }



Mime
View raw message