commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From di...@apache.org
Subject cvs commit: jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/jdbc2pool Jdbc2PoolDataSource.java
Date Mon, 11 Aug 2003 14:08:39 GMT
dirkv       2003/08/11 07:08:39

  Modified:    dbcp/src/java/org/apache/commons/dbcp/jdbc2pool
                        Jdbc2PoolDataSource.java
  Log:
  Bugzilla Bug 18905
    Couldn't get connection (Jdbc2PoolDataSource)
  
  Jdbc2PoolDataSource.registerPool didn't check if the supplied username/password was correct.
  A broken pool was registered and the next call to getConnection always used this pool.
  Now registerPool tries to connect and returns the SQLException if it fails.
  (this fix solved the 3 testcases that were failing for me)
  
  Revision  Changes    Path
  1.14      +27 -3     jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/jdbc2pool/Jdbc2PoolDataSource.java
  
  Index: Jdbc2PoolDataSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/jdbc2pool/Jdbc2PoolDataSource.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Jdbc2PoolDataSource.java	26 Jul 2003 01:23:21 -0000	1.13
  +++ Jdbc2PoolDataSource.java	11 Aug 2003 14:08:39 -0000	1.14
  @@ -958,7 +958,7 @@
               try {
                   registerPool(username, password);
                   pool = pools.get(key);
  -            } catch (Exception e) {
  +            } catch (NamingException e) {
                   e.printStackTrace();
                   throw new SQLException(e.getMessage());
               }
  @@ -1097,7 +1097,7 @@
       }
   
       private synchronized void registerPool(String username, String password) 
  -            throws javax.naming.NamingException {
  +            throws javax.naming.NamingException, SQLException {
           Map pools = (Map) dsInstanceMap.get(instanceKey);
           PoolKey key = getPoolKey(username);
           if (!pools.containsKey(key)) {
  @@ -1115,6 +1115,30 @@
                       ctx = new InitialContext(jndiEnvironment);
                   }
                   cpds = (ConnectionPoolDataSource) ctx.lookup(dataSourceName);
  +            }
  +            
  +            // try to get a connection with the supplied username/password
  +            PooledConnection conn = null;
  +            try {
  +                if (username != null) {
  +                    conn = cpds.getPooledConnection(username, password);
  +                }
  +                else {
  +                    conn = cpds.getPooledConnection();
  +                }
  +                if (conn == null) {
  +                    throw new SQLException("Cannot connect using the supplied username/password");
  +                }
  +            }
  +            finally {
  +                if (conn != null) {
  +                    try {
  +                        conn.close();
  +                    }
  +                    catch (SQLException e) {
  +                        // at least we could connect
  +                    }
  +                }
               }
   
               Object whicheverPool = null;
  
  
  

Mime
View raw message