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 PoolingDriver.java
Date Mon, 11 Aug 2003 14:53:34 GMT
dirkv       2003/08/11 07:53:34

  Modified:    dbcp/src/java/org/apache/commons/dbcp PoolingDriver.java
  Log:
  Use SQLNestedException to report errors
  
  Revision  Changes    Path
  1.5       +34 -14    jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/PoolingDriver.java
  
  Index: PoolingDriver.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/PoolingDriver.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PoolingDriver.java	8 Nov 2002 19:17:23 -0000	1.4
  +++ PoolingDriver.java	11 Aug 2003 14:53:34 -0000	1.5
  @@ -61,6 +61,7 @@
   
   package org.apache.commons.dbcp;
   
  +import java.io.IOException;
   import java.io.InputStream;
   import java.sql.Connection;
   import java.sql.Driver;
  @@ -68,11 +69,11 @@
   import java.sql.DriverPropertyInfo;
   import java.sql.SQLException;
   import java.util.HashMap;
  -import java.util.NoSuchElementException;
   import java.util.Properties;
   
   import org.apache.commons.jocl.JOCLContentHandler;
   import org.apache.commons.pool.ObjectPool;
  +import org.xml.sax.SAXException;
   
   
   /**
  @@ -81,6 +82,7 @@
    * {@link ObjectPool}.
    *
    * @author Rodney Waldhoff
  + * @author Dirk Verbeeck
    * @version $Id$
    */
   public class PoolingDriver implements Driver {
  @@ -98,7 +100,22 @@
       public PoolingDriver() {
       }
   
  +    /**
  +     * WARNING: This method throws DbcpExceptions (RuntimeExceptions)
  +     * and will be replaced by the protected getConnectionPool method.
  +     * 
  +     * @deprecated This will be removed in a future version of DBCP.
  +     */
       synchronized public ObjectPool getPool(String name) {
  +        try {
  +            return getConnectionPool(name);
  +        }
  +        catch (Exception e) {
  +            throw new DbcpException(e);
  +        }
  +    }
  +    
  +    synchronized protected ObjectPool getConnectionPool(String name) throws SQLException
{
           ObjectPool pool = (ObjectPool)(_pools.get(name));
           if(null == pool) {
               InputStream in = this.getClass().getResourceAsStream(String.valueOf(name) +
".jocl");
  @@ -106,8 +123,12 @@
                   JOCLContentHandler jocl = null;
                   try {
                       jocl = JOCLContentHandler.parse(in);
  -                } catch(Exception e) {
  -                    throw new DbcpException(e);
  +                }
  +                catch (SAXException e) {
  +                    throw new SQLNestedException("Could not parse configuration file",
e);
  +                }
  +                catch (IOException e) {
  +                    throw new SQLNestedException("Could not load configuration file", e);
                   }
                   if(jocl.getType(0).equals(String.class)) {
                       pool = getPool((String)(jocl.getValue(0)));
  @@ -121,6 +142,9 @@
                       }
                   }
               }
  +            else {
  +                throw new SQLException("Configuration file not found");
  +            }
           }
           return pool;
       }
  @@ -139,7 +163,7 @@
   
       public Connection connect(String url, Properties info) throws SQLException {
           if(acceptsURL(url)) {
  -            ObjectPool pool = getPool(url.substring(URL_PREFIX_LEN));
  +            ObjectPool pool = getConnectionPool(url.substring(URL_PREFIX_LEN));
               if(null == pool) {
                   throw new SQLException("No pool found for " + url + ".");
               } else {
  @@ -147,12 +171,8 @@
                       return (Connection)(pool.borrowObject());
                   } catch(SQLException e) {
                       throw e;
  -                } catch(NoSuchElementException e) {
  -                    throw new SQLException(e.toString());
  -                } catch(RuntimeException e) {
  -                    throw e;
  -                } catch(Exception e) {
  -                    throw new SQLException(e.toString());
  +                } catch(Throwable e) {
  +                    throw new SQLNestedException("Connect failed", e);
                   }
               }
           } else {
  
  
  

Mime
View raw message