commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r829653 - in /commons/proper/dbcp/trunk/src: java/org/apache/commons/dbcp/datasources/PerUserPoolDataSource.java java/org/apache/commons/dbcp/datasources/PoolKey.java test/org/apache/commons/dbcp/datasources/TestPerUserPoolDataSource.java
Date Sun, 25 Oct 2009 21:16:19 GMT
Author: markt
Date: Sun Oct 25 21:16:18 2009
New Revision: 829653

URL: http://svn.apache.org/viewvc?rev=829653&view=rev
Log:
Extend fix for DBCP-8 to PerUserPoolDataSource
The fix is a little ugly to maintain binary compatibility in PoolKey - I really wanted to
add password as a separate field
Unit tests all pass with fix applied

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/PoolKey.java
    commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/datasources/TestPerUserPoolDataSource.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=829653&r1=829652&r2=829653&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
Sun Oct 25 21:16:18 2009
@@ -333,7 +333,7 @@
      * Get the number of active connections in the pool for a given user.
      */
     public int getNumActive(String username, String password) {
-        ObjectPool pool = (ObjectPool)pools.get(getPoolKey(username));
+        ObjectPool pool = (ObjectPool)pools.get(getPoolKey(username,password));
         return (pool == null) ? 0 : pool.getNumActive();
     }
 
@@ -348,7 +348,7 @@
      * Get the number of idle connections in the pool for a given user.
      */
     public int getNumIdle(String username, String password) {
-        ObjectPool pool = (ObjectPool)pools.get(getPoolKey(username));
+        ObjectPool pool = (ObjectPool)pools.get(getPoolKey(username,password));
         return (pool == null) ? 0 : pool.getNumIdle();
     }
 
@@ -360,7 +360,7 @@
         getPooledConnectionAndInfo(String username, String password)
         throws SQLException {
 
-        PoolKey key = getPoolKey(username);
+        PoolKey key = getPoolKey(username,password);
         Object pool = pools.get(key);
         synchronized(this) {
             if (pool == null) {
@@ -436,21 +436,22 @@
         return ref;
     }
 
-    private PoolKey getPoolKey(String username) {
+    private PoolKey getPoolKey(String username, String password) {
         PoolKey key = null;
+        String name = username + password;
         String dsName = getDataSourceName();
         Map dsMap = (Map) poolKeys.get(dsName);
         if (dsMap != null) {
-            key = (PoolKey) dsMap.get(username);
+            key = (PoolKey) dsMap.get(name);
         }
         
         if (key == null) {
-            key = new PoolKey(dsName, username);
+            key = new PoolKey(dsName, name);
             if (dsMap == null) {
                 dsMap = new HashMap();
                 poolKeys.put(dsName, dsMap);
             }
-            dsMap.put(username, key);
+            dsMap.put(name, key);
         }
         return key;
     }
@@ -492,7 +493,7 @@
                                   isRollbackAfterValidation(), 
                                   username, password);
            
-        pools.put(getPoolKey(username), pool);
+        pools.put(getPoolKey(username,password), pool);
     }
 
     /**

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/PoolKey.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/PoolKey.java?rev=829653&r1=829652&r2=829653&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/PoolKey.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/PoolKey.java Sun
Oct 25 21:16:18 2009
@@ -24,18 +24,18 @@
  */
 class PoolKey implements Serializable {
     private String datasourceName;
-    private String username;
+    private String userPwd;
     
-    PoolKey(String datasourceName, String username) {
+    PoolKey(String datasourceName, String userPwd) {
         this.datasourceName = datasourceName;
-        this.username = username;
+        this.userPwd = userPwd;
     }
     
     public boolean equals(Object obj) {
         if (obj instanceof PoolKey) {
             PoolKey pk = (PoolKey)obj;
             return (null == datasourceName ? null == pk.datasourceName : datasourceName.equals(pk.datasourceName))
&&
-                (null == username ? null == pk.username : username.equals(pk.username));
+                (null == userPwd ? null == pk.userPwd : userPwd.equals(pk.userPwd));
         } else {
             return false;   
         }
@@ -46,8 +46,8 @@
         if (datasourceName != null) {
             h += datasourceName.hashCode();
         }
-        if (username != null) {
-            h = 29 * h + username.hashCode();
+        if (userPwd != null) {
+            h = 29 * h + userPwd.hashCode();
         }
         return h;
     }
@@ -55,7 +55,7 @@
     public String toString() {
         StringBuffer sb = new StringBuffer(50);
         sb.append("PoolKey(");
-        sb.append(username).append(", ").append(datasourceName);
+        sb.append(userPwd).append(", ").append(datasourceName);
         sb.append(')');
         return sb.toString();
     }

Modified: commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/datasources/TestPerUserPoolDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/datasources/TestPerUserPoolDataSource.java?rev=829653&r1=829652&r2=829653&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/datasources/TestPerUserPoolDataSource.java
(original)
+++ commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/datasources/TestPerUserPoolDataSource.java
Sun Oct 25 21:16:18 2009
@@ -104,7 +104,7 @@
         }
         catch (SQLException e)
         {
-            if (!e.getMessage().startsWith("Given password did not match")) 
+            if (!e.getMessage().startsWith("x is not the correct password")) 
             {
                 throw e;
             }



Mime
View raw message