Author: dimuthul
Date: Sun Dec  9 18:33:37 2007
New Revision: 10737

Log:

Keeping a client count to enable reset without bugs.
This will preserve - loose coupling.



Modified:
   
trunk/commons/usermanager/modules/core/src/main/java/org/wso2/usermanager/pool/SimplePoolManager.java
   
trunk/commons/usermanager/modules/core/src/main/java/org/wso2/usermanager/readwrite/DefaultAccessControlAdmin.java
   
trunk/commons/usermanager/modules/core/src/main/java/org/wso2/usermanager/readwrite/DefaultAuthenticator.java
   
trunk/commons/usermanager/modules/core/src/main/java/org/wso2/usermanager/readwrite/DefaultAuthorizer.java
   
trunk/commons/usermanager/modules/core/src/main/java/org/wso2/usermanager/readwrite/DefaultCommons.java
   
trunk/commons/usermanager/modules/core/src/main/java/org/wso2/usermanager/readwrite/DefaultUserStoreAdmin.java
   
trunk/commons/usermanager/modules/core/src/main/java/org/wso2/usermanager/readwrite/DefaultUserStoreReader.java
   
trunk/commons/usermanager/modules/core/src/test/java/org/wso2/usermanager/readwrite/DefaultRealmTest.java

Modified: 
trunk/commons/usermanager/modules/core/src/main/java/org/wso2/usermanager/pool/SimplePoolManager.java
==============================================================================
--- 
trunk/commons/usermanager/modules/core/src/main/java/org/wso2/usermanager/pool/SimplePoolManager.java
       (original)
+++ 
trunk/commons/usermanager/modules/core/src/main/java/org/wso2/usermanager/pool/SimplePoolManager.java
       Sun Dec  9 18:33:37 2007
@@ -28,11 +28,17 @@
     }
     
     public static synchronized SimplePoolManager getInstance() {
+        clients++;
         return instance;
     }
+    
+    public static synchronized void freeInstance() {
+        clients--;
+        return;
+    }
        
     public static synchronized boolean resetPool() {
-        if(instance != null){
+        if(instance != null && clients == 0){
             instance.deletePool();
             instance = null;
         }

Modified: 
trunk/commons/usermanager/modules/core/src/main/java/org/wso2/usermanager/readwrite/DefaultAccessControlAdmin.java
==============================================================================
--- 
trunk/commons/usermanager/modules/core/src/main/java/org/wso2/usermanager/readwrite/DefaultAccessControlAdmin.java
  (original)
+++ 
trunk/commons/usermanager/modules/core/src/main/java/org/wso2/usermanager/readwrite/DefaultAccessControlAdmin.java
  Sun Dec  9 18:33:37 2007
@@ -25,8 +25,8 @@
 
     public void clearUserAuthorization(String userName, String resourceId,
             String action) throws UserManagerException {
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -57,7 +57,8 @@
             log.debug(e);
             throw new UserManagerException("errorModifyingUserStore", e);
         } finally {
-            pool.freeConnection(dbConnection);
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
     }
 
@@ -71,8 +72,8 @@
             throw new UserManagerException("nullUser");
         }
 
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -92,7 +93,8 @@
             log.debug(e);
             throw new UserManagerException("errorModifyingUserStore", e);
         } finally {
-            pool.freeConnection(dbConnection);
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
 
     }
@@ -106,8 +108,8 @@
         }
 
         String permissionId = this.getOrAddPermissionId(resourceId, action);
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -127,7 +129,8 @@
             log.debug(e);
             throw new UserManagerException("errorModifyingUserStore", e);
         } finally {
-            pool.freeConnection(dbConnection);
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
 
     }
@@ -141,8 +144,8 @@
         }
 
         String permissionId = this.getOrAddPermissionId(resourceId, action);
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -162,14 +165,15 @@
             log.debug(e);
             throw new UserManagerException("errorModifyingUserStore", e);
         } finally {
-            pool.freeConnection(dbConnection);
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
     }
 
     public void clearRoleAuthorization(String roleName, String resourceId,
             String action) throws UserManagerException {
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -202,15 +206,16 @@
             log.debug(e);
             throw new UserManagerException("errorModifyingUserStore", e);
         } finally {
-            pool.freeConnection(dbConnection);
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
 
     }
 
     public void clearResourceAuthorizations(String resourceId)
             throws UserManagerException {
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -225,14 +230,15 @@
             log.debug(e);
             throw new UserManagerException("errorModifyingUserStore", e);
         } finally {
-            pool.freeConnection(dbConnection);
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
     }
 
     public void copyAuthorizations(String fromResourceId, String toResourceId)
             throws UserManagerException {
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -322,7 +328,8 @@
             log.debug(e);
             throw new UserManagerException("errorCopyingAuthorizations", e);
         } finally {
-            pool.freeConnection(dbConnection);
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
 
     }
@@ -338,8 +345,8 @@
 
         String permissionId = this.getOrAddPermissionId(resourceId, action);
         
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -360,7 +367,8 @@
             log.debug(e);
             throw new UserManagerException("errorModifyingUserStore", e);
         } finally {
-            pool.freeConnection(dbConnection);
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
 
     }
@@ -374,8 +382,8 @@
     protected String getOrAddPermissionId(String resourceId, String action)
             throws UserManagerException {
         String permissionId = null;
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -410,7 +418,8 @@
             log.debug(e);
             throw new UserManagerException("errorModifyingUserStore", e);
         } finally {
-            pool.freeConnection(dbConnection);
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
 
         return permissionId;

Modified: 
trunk/commons/usermanager/modules/core/src/main/java/org/wso2/usermanager/readwrite/DefaultAuthenticator.java
==============================================================================
--- 
trunk/commons/usermanager/modules/core/src/main/java/org/wso2/usermanager/readwrite/DefaultAuthenticator.java
       (original)
+++ 
trunk/commons/usermanager/modules/core/src/main/java/org/wso2/usermanager/readwrite/DefaultAuthenticator.java
       Sun Dec  9 18:33:37 2007
@@ -30,8 +30,8 @@
     public boolean authenticate(String userName, Object credentials)
             throws UserManagerException {
         boolean isAuth = false;
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -57,7 +57,8 @@
             log.debug(e);
             throw new UserManagerException("errorCreatingPasswordDigest", e);
         } finally {
-           pool.freeConnection(dbConnection);
+           poolMan.freeConnection(dbConnection);
+           SimplePoolManager.freeInstance();
         }
         return isAuth;
     }

Modified: 
trunk/commons/usermanager/modules/core/src/main/java/org/wso2/usermanager/readwrite/DefaultAuthorizer.java
==============================================================================
--- 
trunk/commons/usermanager/modules/core/src/main/java/org/wso2/usermanager/readwrite/DefaultAuthorizer.java
  (original)
+++ 
trunk/commons/usermanager/modules/core/src/main/java/org/wso2/usermanager/readwrite/DefaultAuthorizer.java
  Sun Dec  9 18:33:37 2007
@@ -56,8 +56,8 @@
     public String[] getAllowedUsersForResource(String resourceId, String 
action)
             throws UserManagerException {
         String[] names = new String[0];
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -79,7 +79,8 @@
             log.debug(e);
             throw new UserManagerException("errorReadingFromUserStore", e);
         } finally {
-            pool.freeConnection(dbConnection);
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
         return names;
     }
@@ -87,8 +88,8 @@
     public String[] getDeniedUsersForResource(String resourceId, String action)
             throws UserManagerException {
         String[] names = new String[0];
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -110,7 +111,8 @@
             log.debug(e);
             throw new UserManagerException("errorReadingFromUserStore", e);
         } finally {
-            pool.freeConnection(dbConnection);
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
         return names;
     }
@@ -118,8 +120,8 @@
     public String[] getAllowedRolesForResource(String resourceId, String 
action)
             throws UserManagerException {
         String[] names = new String[0];
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -141,7 +143,8 @@
             log.debug(e);
             throw new UserManagerException("errorReadingFromUserStore", e);
         } finally {
-            pool.freeConnection(dbConnection);
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
         return names;
     }
@@ -150,8 +153,8 @@
             throws UserManagerException {
 
         String[] names = new String[0];
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -173,7 +176,8 @@
             log.debug(e);
             throw new UserManagerException("errorReadingFromUserStore", e);
         } finally {
-            pool.freeConnection(dbConnection);
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
         return names;
 
@@ -212,8 +216,8 @@
     private Boolean getRoleAuthorized(String roleName, String resourceId,
             String action) throws UserManagerException {
         Boolean isAuthorized = null;
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -233,7 +237,8 @@
             log.debug(e);
             throw new UserManagerException("errorReadingFromUserStore", e);
         } finally {
-            pool.freeConnection(dbConnection);
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
         return isAuthorized;
     }
@@ -241,8 +246,8 @@
     private Boolean getUserAuthorized(String userName, String resourceId,
             String action) throws UserManagerException {
         Boolean result = null;
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -262,7 +267,8 @@
             log.debug(e);
             throw new UserManagerException("errorReadingFromUserStore", e);
         } finally {
-            pool.freeConnection(dbConnection);
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
         return result;
     }

Modified: 
trunk/commons/usermanager/modules/core/src/main/java/org/wso2/usermanager/readwrite/DefaultCommons.java
==============================================================================
--- 
trunk/commons/usermanager/modules/core/src/main/java/org/wso2/usermanager/readwrite/DefaultCommons.java
     (original)
+++ 
trunk/commons/usermanager/modules/core/src/main/java/org/wso2/usermanager/readwrite/DefaultCommons.java
     Sun Dec  9 18:33:37 2007
@@ -23,8 +23,8 @@
     public static String getUserId(String userName) throws 
UserManagerException {
         String id = null;
         
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -42,7 +42,8 @@
             log.debug(e);
             throw new UserManagerException("errorReadingFromUserStore", e);
         } finally {
-            pool.freeConnection(dbConnection);
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
         return id;
     }
@@ -50,8 +51,8 @@
     public static String getRoleId(String roleName) throws 
UserManagerException {
         String id = null;
         
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -68,7 +69,8 @@
             log.debug(e);
             throw new UserManagerException("errorReadingFromUserStore", e);
         } finally {
-            pool.freeConnection(dbConnection);
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
         return id;
     }
@@ -76,8 +78,8 @@
     
     public static String[] getUserRoles(String userName) throws 
UserManagerException {
         String[] names = new String[0];
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -97,7 +99,8 @@
             log.debug(e);
             throw new UserManagerException("errorReadingFromUserStore", e);
         } finally {
-            pool.freeConnection(dbConnection);
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
         return names;
     } 

Modified: 
trunk/commons/usermanager/modules/core/src/main/java/org/wso2/usermanager/readwrite/DefaultUserStoreAdmin.java
==============================================================================
--- 
trunk/commons/usermanager/modules/core/src/main/java/org/wso2/usermanager/readwrite/DefaultUserStoreAdmin.java
      (original)
+++ 
trunk/commons/usermanager/modules/core/src/main/java/org/wso2/usermanager/readwrite/DefaultUserStoreAdmin.java
      Sun Dec  9 18:33:37 2007
@@ -31,8 +31,8 @@
         if (!(credential instanceof String)) {
             throw new UserManagerException("Credential type not support");
         }
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -59,15 +59,16 @@
             log.debug(e);
             throw new UserManagerException("errorCreatingPasswordDigest", e);
         } finally {
-            pool.freeConnection(dbConnection);
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
 
     }
 
     public void updateUser(String userName, Object credential)
             throws UserManagerException {
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -88,13 +89,14 @@
             log.debug(e);
             throw new UserManagerException("errorCreatingPasswordDigest", e);
         } finally {
-            pool.freeConnection(dbConnection);
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
     }
 
     public void deleteUser(String userName) throws UserManagerException {
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -109,7 +111,7 @@
             log.debug(e);
             throw new UserManagerException("errorModifyingUserStore", e);
         } finally {
-            pool.freeConnection(dbConnection);
+            poolMan.freeConnection(dbConnection);
         }
 
     }
@@ -125,8 +127,8 @@
         if (properties == null || properties.isEmpty()) {
             return;
         }
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -159,7 +161,7 @@
             log.debug(e);
             throw new UserManagerException("errorModifyingUserStore", e);
         } finally {
-            pool.freeConnection(dbConnection);
+            poolMan.freeConnection(dbConnection);
         }
 
     }
@@ -171,8 +173,8 @@
         if (roleid == null) {
             throw new UserManagerException("nullRole");
         }
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -208,13 +210,14 @@
             log.debug(e);
             throw new UserManagerException("errorModifyingUserStore", e);
         } finally {
-            pool.freeConnection(dbConnection);
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
     }
 
     public void addRole(String roleName) throws UserManagerException {
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -231,13 +234,13 @@
             log.debug(e);
             throw new UserManagerException("errorModifyingUserStore", e);
         } finally {
-            pool.freeConnection(dbConnection);
+            poolMan.freeConnection(dbConnection);
         }
     }
 
     public void deleteRole(String roleName) throws UserManagerException {
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -252,7 +255,8 @@
             log.debug(e);
             throw new UserManagerException("errorModifyingUserStore", e);
         } finally {
-            pool.freeConnection(dbConnection);
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
     }
 
@@ -265,8 +269,8 @@
         if (roleid == null || userid == null) {
             throw new UserManagerException("nullData");
         }
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -285,14 +289,15 @@
             throw new UserManagerException("errorModifyingUserStore", e);
         } finally {
             log.debug("free_connection");
-            pool.freeConnection(dbConnection);
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
     }
 
     public void removeUserFromRole(String userName, String roleName)
             throws UserManagerException {
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -308,7 +313,8 @@
             log.debug(e);
             throw new UserManagerException("errorModifyingUserStore", e);
         } finally {
-            pool.freeConnection(dbConnection);
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
     }
 

Modified: 
trunk/commons/usermanager/modules/core/src/main/java/org/wso2/usermanager/readwrite/DefaultUserStoreReader.java
==============================================================================
--- 
trunk/commons/usermanager/modules/core/src/main/java/org/wso2/usermanager/readwrite/DefaultUserStoreReader.java
     (original)
+++ 
trunk/commons/usermanager/modules/core/src/main/java/org/wso2/usermanager/readwrite/DefaultUserStoreReader.java
     Sun Dec  9 18:33:37 2007
@@ -28,8 +28,8 @@
 
     public String[] getAllRoleNames() throws UserManagerException {
         String[] names = new String[0];
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -48,16 +48,17 @@
         } catch (SQLException e) {
             log.debug(e);
             throw new UserManagerException("errorReadingFromUserStore", e);
-        }  finally {
-           pool.freeConnection(dbConnection);
+        } finally {
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
         return names;
     }
 
     public String[] getAllUserNames() throws UserManagerException {
         String[] names = new String[0];
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -67,7 +68,8 @@
             ResultSet rs = getAllUserNamesStmt.executeQuery();
             List lst = new LinkedList();
             while (rs.next()) {
-                String name = 
rs.getString(DefaultRealmConstants.COLUMN_USER_NAME);
+                String name = rs
+                        .getString(DefaultRealmConstants.COLUMN_USER_NAME);
                 lst.add(name);
             }
             if (lst.size() > 0) {
@@ -77,8 +79,9 @@
         } catch (SQLException e) {
             log.debug(e);
             throw new UserManagerException("errorReadingFromUserStore", e);
-        }  finally {
-           pool.freeConnection(dbConnection);
+        } finally {
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
         return names;
     }
@@ -86,8 +89,8 @@
     public Map getRoleProperties(String roleName) throws UserManagerException {
 
         Map props = new HashMap();
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -108,8 +111,9 @@
         } catch (SQLException e) {
             log.debug(e);
             throw new UserManagerException("errorReadingFromUserStore", e);
-        }  finally {
-           pool.freeConnection(dbConnection);
+        } finally {
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
 
         return props;
@@ -118,8 +122,8 @@
 
     public Map getUserProperties(String userName) throws UserManagerException {
         Map props = new HashMap();
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -140,8 +144,9 @@
         } catch (SQLException e) {
             log.debug(e);
             throw new UserManagerException("errorReadingFromUserStore", e);
-        }  finally {
-           pool.freeConnection(dbConnection);
+        } finally {
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
 
         return props;
@@ -150,8 +155,8 @@
 
     public String[] getUserPropertyNames() throws UserManagerException {
         String[] propNames = new String[0];
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -168,8 +173,9 @@
         } catch (SQLException e) {
             log.debug(e);
             throw new UserManagerException("errorReadingFromUserStore", e);
-        }  finally {
-           pool.freeConnection(dbConnection);
+        } finally {
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
         return propNames;
     }
@@ -180,7 +186,7 @@
 
     public boolean isExistingUser(String userName) throws UserManagerException 
{
         boolean isExisting = false;
-        if(DefaultCommons.getUserId(userName)!= null){
+        if (DefaultCommons.getUserId(userName) != null) {
             isExisting = true;
         }
         return isExisting;
@@ -189,25 +195,25 @@
     public String[] getUserNamesWithPropertyValue(String propertyName,
             String propetyValue) throws UserManagerException {
         String[] names = new String[0];
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
         try {
             PreparedStatement getPropValue = null;
-            
-            if(propertyName != null && propertyName.length() != 0){
-                getPropValue= dbConnection
-                    
.prepareStatement(DefaultRealmConstants.GET_USERS_WITH_PROPERTY);
+
+            if (propertyName != null && propertyName.length() != 0) {
+                getPropValue = dbConnection
+                        
.prepareStatement(DefaultRealmConstants.GET_USERS_WITH_PROPERTY);
                 getPropValue.setString(1, propertyName);
                 getPropValue.setString(2, propetyValue);
-            }else{
-                getPropValue= dbConnection
-                
.prepareStatement(DefaultRealmConstants.GET_USERS_WITH_PROPERTY_VALUE);
+            } else {
+                getPropValue = dbConnection
+                        
.prepareStatement(DefaultRealmConstants.GET_USERS_WITH_PROPERTY_VALUE);
                 getPropValue.setString(1, propetyValue);
             }
-           
+
             ResultSet rs = getPropValue.executeQuery();
             List lst = new ArrayList();
             while (rs.next()) {
@@ -218,18 +224,19 @@
         } catch (SQLException e) {
             log.debug(e);
             throw new UserManagerException("errorReadingFromUserStore", e);
-        }  finally {
-           pool.freeConnection(dbConnection);
+        } finally {
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
-        
+
         return names;
-        
+
     }
 
     public String[] getUsersInRole(String roleName) throws 
UserManagerException {
         String[] names = new String[0];
-        SimplePoolManager pool = SimplePoolManager.getInstance();
-        Connection dbConnection = pool.getConnection();
+        SimplePoolManager poolMan = SimplePoolManager.getInstance();
+        Connection dbConnection = poolMan.getConnection();
         if (dbConnection == null) {
             throw new UserManagerException("null_connection");
         }
@@ -247,10 +254,11 @@
         } catch (SQLException e) {
             log.debug(e);
             throw new UserManagerException("errorReadingFromUserStore", e);
-        }  finally {
-           pool.freeConnection(dbConnection);
+        } finally {
+            poolMan.freeConnection(dbConnection);
+            SimplePoolManager.freeInstance();
         }
-        
+
         return names;
     }
 

Modified: 
trunk/commons/usermanager/modules/core/src/test/java/org/wso2/usermanager/readwrite/DefaultRealmTest.java
==============================================================================
--- 
trunk/commons/usermanager/modules/core/src/test/java/org/wso2/usermanager/readwrite/DefaultRealmTest.java
   (original)
+++ 
trunk/commons/usermanager/modules/core/src/test/java/org/wso2/usermanager/readwrite/DefaultRealmTest.java
   Sun Dec  9 18:33:37 2007
@@ -60,6 +60,12 @@
         config.setConnectionURL(connURL);
         config.setResetPoolManager(true);
         realm.init(config);
+        
+        //now let's test resetting the realm
+        
+        config.setResetPoolManager(true);
+        realm.init(config);
+        
 
     }
 

_______________________________________________
Commons-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/commons-dev

Reply via email to