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 BasicDataSource.java
Date Sun, 14 Sep 2003 00:15:47 GMT
dirkv       2003/09/13 17:15:47

  Modified:    dbcp/src/java/org/apache/commons/dbcp BasicDataSource.java
  Log:
  Bugzilla Bug 23081: DBCP - Bad DB Validation Query Hangs Everything
  - handle empty validationquery
  - improve validationQuery error reporting by testing the connectionFactory upon creation
  
  Revision  Changes    Path
  1.25      +23 -10    jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/BasicDataSource.java
  
  Index: BasicDataSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/BasicDataSource.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- BasicDataSource.java	13 Sep 2003 22:29:39 -0000	1.24
  +++ BasicDataSource.java	14 Sep 2003 00:15:47 -0000	1.25
  @@ -416,11 +416,15 @@
       protected String validationQuery = null;
   
       public String getValidationQuery() {
  -        return (this.validationQuery);
  +        return this.validationQuery;
       }
   
       public void setValidationQuery(String validationQuery) {
  -        this.validationQuery = validationQuery;
  +        if ((validationQuery != null) && (validationQuery.trim().length() >
0)) {
  +            this.validationQuery = validationQuery;
  +        } else {
  +            this.validationQuery = null;
  +        }
       }
   
       /** 
  @@ -800,9 +804,10 @@
               if (connectionFactory == null) {
                   throw new SQLException("Cannot create PoolableConnectionFactory");
               }
  -        } catch(RuntimeException e) {
  +            validateConnectionFactory(connectionFactory);
  +        } catch (RuntimeException e) {
               throw e;
  -        } catch(Exception e) {
  +        } catch (Exception e) {
               throw new SQLNestedException("Cannot create PoolableConnectionFactory", e);
           }
   
  @@ -811,8 +816,16 @@
           ((PoolingDataSource) dataSource).setAccessToUnderlyingConnectionAllowed(isAccessToUnderlyingConnectionAllowed());
           dataSource.setLogWriter(logWriter);
           return (dataSource);
  -
       }
  -
  -
  +    
  +    private void validateConnectionFactory(PoolableConnectionFactory connectionFactory)
throws Exception {
  +        Connection conn = null;
  +        try {
  +            conn = (Connection) connectionFactory.makeObject();
  +            connectionFactory.validateConnection(conn);
  +        }
  +        finally {
  +            connectionFactory.destroyObject(conn);
  +        }
  +    }
   }
  
  
  

Mime
View raw message