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

  Modified:    dbcp/src/java/org/apache/commons/dbcp
                        PoolableConnectionFactory.java
  Log:
  add validateConnection() with the same logic as validateObject
  but throws exceptions on error (for detailed error messages)
  
  Revision  Changes    Path
  1.12      +36 -38    jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/PoolableConnectionFactory.java
  
  Index: PoolableConnectionFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/PoolableConnectionFactory.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- PoolableConnectionFactory.java	25 Aug 2003 16:17:45 -0000	1.11
  +++ PoolableConnectionFactory.java	14 Sep 2003 00:12:40 -0000	1.12
  @@ -270,46 +270,44 @@
   
       synchronized public boolean validateObject(Object obj) {
           if(obj instanceof Connection) {
  -            String query = _validationQuery;
  -            Connection conn = (Connection)obj;
               try {
  -                if(conn.isClosed()) {
  -                    return false;
  -                }
  -            } catch(SQLException e) {
  +                validateConnection((Connection) obj);
  +                return true;
  +            } catch(Exception e) {
                   return false;
  -            }
  -            if(null != query) {
  -                Statement stmt = null;
  -                ResultSet rset = null;
  -                try {
  -                    stmt = conn.createStatement();
  -                    rset = stmt.executeQuery(query);
  -                    if(rset.next()) {
  -                        return true;
  -                    } else {
  -                        return false;
  -                    }
  -                } catch(Exception e) {
  -                    return false;
  -                } finally {
  -                    try {
  -                        rset.close();
  -                    } catch(Exception t) {
  -                        // ignored
  -                    }
  -                    try {
  -                        stmt.close();
  -                    } catch(Exception t) {
  -                        // ignored
  -                    }
  +            }           
  +        } else {
  +            return false;
  +        }
  +    }
   
  +    synchronized public void validateConnection(Connection conn) throws SQLException {
  +        String query = _validationQuery;
  +        if(conn.isClosed()) {
  +            throw new SQLException("validateConnection: connection closed");
  +        }
  +        if(null != query) {
  +            Statement stmt = null;
  +            ResultSet rset = null;
  +            try {
  +                stmt = conn.createStatement();
  +                rset = stmt.executeQuery(query);
  +                if(!rset.next()) {
  +                    throw new SQLException("validationQuery didn't return a row");
                   }
  -            } else {
  -                return true;
  +            } finally {
  +                try {
  +                    rset.close();
  +                } catch(Exception t) {
  +                    // ignored
  +                }
  +                try {
  +                    stmt.close();
  +                } catch(Exception t) {
  +                    // ignored
  +                }
  +
               }
  -        } else {
  -            return false;
           }
       }
   
  
  
  

Mime
View raw message