follow sun coding conventions (code was developed as part of torque, so it followed the turbine conventions)


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/dbcp/trunk@131969 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/java/org/apache/commons/dbcp/cpdsadapter/ConnectionImpl.java b/src/java/org/apache/commons/dbcp/cpdsadapter/ConnectionImpl.java
index 830a312..8b58384 100644
--- a/src/java/org/apache/commons/dbcp/cpdsadapter/ConnectionImpl.java
+++ b/src/java/org/apache/commons/dbcp/cpdsadapter/ConnectionImpl.java
@@ -1,7 +1,7 @@
 /* ====================================================================
  * The Apache Software License, Version 1.1
  *
- * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
+ * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -72,27 +72,19 @@
  * SQLException.
  *
  * @author <a href="mailto:jmcnally@collab.net">John D. McNally</a>
- * @version $Id: ConnectionImpl.java,v 1.4 2003/03/07 00:24:09 rwaldhoff Exp $
+ * @version $Id: ConnectionImpl.java,v 1.5 2003/06/29 12:42:16 mpoeschl Exp $
  */
-class ConnectionImpl 
-    implements Connection
-{
-    private static final String CLOSED = 
-        "Attempted to use Connection after closed() was called.";
+class ConnectionImpl implements Connection {
+    private static final String CLOSED 
+            = "Attempted to use Connection after closed() was called.";
 
-    /**
-     * The JDBC database connection.
-     */
+    /** The JDBC database connection. */
     private Connection connection;
 
-    /**
-     * The object that instantiated this object
-     */
+    /** The object that instantiated this object */
      private PooledConnectionImpl pooledConnection;
 
-    /**
-     * Marks whether is Connection is still usable.
-     */
+    /** Marks whether is Connection is still usable. */
     boolean isClosed;
 
     /**
@@ -102,40 +94,32 @@
      * @param connection The JDBC 1.x Connection to wrap.
      */
     ConnectionImpl(PooledConnectionImpl pooledConnection, 
-                   Connection connection)
-    {
+            Connection connection) {
         this.pooledConnection = pooledConnection;
         this.connection = connection;
         isClosed = false;
     }
 
-
     /**
      * The finalizer helps prevent <code>ConnectionPool</code> leakage.
      */
-    protected void finalize()
-        throws Throwable
-    {
-        if (!isClosed)
-        {
+    protected void finalize() throws Throwable {
+        if (!isClosed) {
             // If this DBConnection object is finalized while linked
             // to a ConnectionPool, it means that it was taken from a pool
             // and not returned.  We log this fact, close the underlying
             // Connection, and return it to the ConnectionPool.
             throw new SQLException("A ConnectionImpl was finalized "
                       + "without being closed which will cause leakage of "
-                      + " PooledConnections from the ConnectionPool." );
+                      + " PooledConnections from the ConnectionPool.");
         }
     }
 
     /**
      * Throws an SQLException, if isClosed() is true
      */
-    private void assertOpen()
-        throws SQLException 
-    {
-        if ( isClosed ) 
-        {
+    private void assertOpen() throws SQLException {
+        if (isClosed) {
             throw new SQLException(CLOSED);
         }
     }
@@ -150,9 +134,7 @@
      * @exception SQLException if this connection is closed or an error occurs
      * in the wrapped connection.
      */
-    public void clearWarnings() 
-        throws SQLException 
-    {
+    public void clearWarnings() throws SQLException {
         assertOpen();
         connection.clearWarnings();
     }
@@ -166,9 +148,7 @@
      *
      * @exception SQLException The database connection couldn't be closed.
      */
-    public void close()
-        throws SQLException
-    {
+    public void close() throws SQLException {
         assertOpen();
         isClosed = true;
         pooledConnection.notifyListeners();
@@ -180,9 +160,7 @@
      * @exception SQLException if this connection is closed or an error occurs
      * in the wrapped connection.
      */
-    public void commit()
-        throws SQLException
-    {
+    public void commit() throws SQLException {
         assertOpen();
         connection.commit();
     }
@@ -193,9 +171,7 @@
      * @exception SQLException if this connection is closed or an error occurs
      * in the wrapped connection.
      */
-    public Statement createStatement()
-        throws SQLException 
-    {
+    public Statement createStatement() throws SQLException {
         assertOpen();
         return connection.createStatement();
     }
@@ -208,8 +184,7 @@
      */
     public Statement createStatement(int resultSetType, 
                                      int resultSetConcurrency) 
-        throws SQLException 
-    {
+            throws SQLException {
         assertOpen();
         return connection
                 .createStatement(resultSetType, resultSetConcurrency);
@@ -221,9 +196,7 @@
      * @exception SQLException if this connection is closed or an error occurs
      * in the wrapped connection.
      */
-    public boolean getAutoCommit() 
-        throws SQLException 
-    {
+    public boolean getAutoCommit() throws SQLException {
         assertOpen();
         return connection.getAutoCommit();
     }
@@ -234,9 +207,7 @@
      * @exception SQLException if this connection is closed or an error occurs
      * in the wrapped connection.
      */
-    public String getCatalog() 
-        throws SQLException 
-    {
+    public String getCatalog() throws SQLException {
         assertOpen();
         return connection.getCatalog();
     }
@@ -247,9 +218,7 @@
      * @exception SQLException if this connection is closed or an error occurs
      * in the wrapped connection.
      */
-    public DatabaseMetaData getMetaData() 
-        throws SQLException 
-    {
+    public DatabaseMetaData getMetaData() throws SQLException {
         assertOpen();
         return connection.getMetaData();
     }
@@ -260,9 +229,7 @@
      * @exception SQLException if this connection is closed or an error occurs
      * in the wrapped connection.
      */
-    public int getTransactionIsolation() 
-        throws SQLException 
-    {
+    public int getTransactionIsolation() throws SQLException {
         assertOpen();
         return connection.getTransactionIsolation();
     }
@@ -273,9 +240,7 @@
      * @exception SQLException if this connection is closed or an error occurs
      * in the wrapped connection.
      */
-    public Map getTypeMap() 
-        throws SQLException 
-    {
+    public Map getTypeMap() throws SQLException {
         assertOpen();
         return connection.getTypeMap();
     }
@@ -286,9 +251,7 @@
      * @exception SQLException if this connection is closed or an error occurs
      * in the wrapped connection.
      */
-    public SQLWarning getWarnings() 
-        throws SQLException 
-    {
+    public SQLWarning getWarnings() throws SQLException {
         assertOpen();
         return connection.getWarnings();
     }
@@ -298,8 +261,7 @@
      *
      * @return a <code>boolean</code> value
      */
-    public boolean isClosed() 
-    {
+    public boolean isClosed() {
         return isClosed;
     }
 
@@ -309,9 +271,7 @@
      * @exception SQLException if this connection is closed or an error occurs
      * in the wrapped connection.
      */
-    public boolean isReadOnly() 
-        throws SQLException 
-    {
+    public boolean isReadOnly() throws SQLException {
         assertOpen();
         return connection.isReadOnly();
     }
@@ -322,9 +282,7 @@
      * @exception SQLException if this connection is closed or an error occurs
      * in the wrapped connection.
      */
-    public String nativeSQL(String sql) 
-        throws SQLException 
-    {
+    public String nativeSQL(String sql) throws SQLException {
         assertOpen();
         return connection.nativeSQL(sql);
     }    
@@ -335,9 +293,7 @@
      * @exception SQLException if this connection is closed or an error occurs
      * in the wrapped connection.
      */
-    public CallableStatement prepareCall(String sql) 
-        throws SQLException 
-    {
+    public CallableStatement prepareCall(String sql) throws SQLException {
         assertOpen();
         return connection.prepareCall(sql);
     }
@@ -350,11 +306,9 @@
      */
     public CallableStatement prepareCall(String sql, int resultSetType, 
                                          int resultSetConcurrency) 
-        throws SQLException 
-    {
+            throws SQLException {
         assertOpen();
-        return connection
-            .prepareCall(sql, resultSetType, resultSetConcurrency);
+        return connection.prepareCall(sql, resultSetType, resultSetConcurrency);
     }
 
     /**
@@ -365,9 +319,7 @@
      * @exception SQLException if this connection is closed or an error occurs
      * in the wrapped connection.
      */
-    public PreparedStatement prepareStatement(String sql)
-        throws SQLException
-    {
+    public PreparedStatement prepareStatement(String sql) throws SQLException {
         assertOpen();
         return pooledConnection.prepareStatement(sql);
     }
@@ -382,8 +334,7 @@
      */
     public PreparedStatement prepareStatement(String sql, int resultSetType, 
                                               int resultSetConcurrency) 
-        throws SQLException 
-    {
+            throws SQLException {
         assertOpen();
         return pooledConnection
             .prepareStatement(sql, resultSetType, resultSetConcurrency);
@@ -395,9 +346,7 @@
      * @exception SQLException if this connection is closed or an error occurs
      * in the wrapped connection.
      */
-    public void rollback()
-        throws SQLException
-    {
+    public void rollback() throws SQLException {
         assertOpen();
         connection.rollback();
     }
@@ -408,9 +357,7 @@
      * @exception SQLException if this connection is closed or an error occurs
      * in the wrapped connection.
      */
-    public void setAutoCommit(boolean b)
-        throws SQLException
-    {
+    public void setAutoCommit(boolean b) throws SQLException {
         assertOpen();
         connection.setAutoCommit(b);
     }
@@ -421,9 +368,7 @@
      * @exception SQLException if this connection is closed or an error occurs
      * in the wrapped connection.
      */
-    public void setCatalog(String catalog) 
-        throws SQLException 
-    {
+    public void setCatalog(String catalog) throws SQLException {
         assertOpen();
         connection.setCatalog(catalog);
     }
@@ -434,9 +379,7 @@
      * @exception SQLException if this connection is closed or an error occurs
      * in the wrapped connection.
      */
-    public void setReadOnly(boolean readOnly) 
-        throws SQLException 
-    {
+    public void setReadOnly(boolean readOnly) throws SQLException {
         assertOpen();
         connection.setReadOnly(readOnly);
     }
@@ -447,9 +390,7 @@
      * @exception SQLException if this connection is closed or an error occurs
      * in the wrapped connection.
      */
-    public void setTransactionIsolation(int level) 
-        throws SQLException 
-    {
+    public void setTransactionIsolation(int level) throws SQLException {
         assertOpen();
         connection.setTransactionIsolation(level);
     }
@@ -460,9 +401,7 @@
      * @exception SQLException if this connection is closed or an error occurs
      * in the wrapped connection.
      */
-    public void setTypeMap(Map map) 
-        throws SQLException 
-    {
+    public void setTypeMap(Map map) throws SQLException {
         assertOpen();
         connection.setTypeMap(map);
     }
@@ -497,7 +436,8 @@
         connection.rollback(savepoint);
     }
 
-    public void releaseSavepoint(java.sql.Savepoint savepoint) throws SQLException {
+    public void releaseSavepoint(java.sql.Savepoint savepoint) 
+            throws SQLException {
         assertOpen();
         connection.releaseSavepoint(savepoint);
     }
@@ -505,7 +445,7 @@
     public Statement createStatement(int resultSetType,
                                      int resultSetConcurrency,
                                      int resultSetHoldability)
-        throws SQLException {
+            throws SQLException {
         assertOpen();
         return connection.createStatement(resultSetType, resultSetConcurrency,
                                      resultSetHoldability);
@@ -514,7 +454,7 @@
     public PreparedStatement prepareStatement(String sql, int resultSetType,
                                               int resultSetConcurrency,
                                               int resultSetHoldability)
-        throws SQLException {
+            throws SQLException {
         assertOpen();
         return connection.prepareStatement(sql, resultSetType,
                                       resultSetConcurrency,
@@ -524,7 +464,7 @@
     public CallableStatement prepareCall(String sql, int resultSetType,
                                          int resultSetConcurrency,
                                          int resultSetHoldability)
-        throws SQLException {
+            throws SQLException {
         assertOpen();
         return connection.prepareCall(sql, resultSetType,
                                  resultSetConcurrency,
@@ -532,19 +472,19 @@
     }
 
     public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
-        throws SQLException {
+            throws SQLException {
         assertOpen();
         return connection.prepareStatement(sql, autoGeneratedKeys);
     }
 
     public PreparedStatement prepareStatement(String sql, int columnIndexes[])
-        throws SQLException {
+            throws SQLException {
         assertOpen();
         return connection.prepareStatement(sql, columnIndexes);
     }
 
     public PreparedStatement prepareStatement(String sql, String columnNames[])
-        throws SQLException {
+            throws SQLException {
         assertOpen();
         return connection.prepareStatement(sql, columnNames);
     }
diff --git a/src/java/org/apache/commons/dbcp/cpdsadapter/DriverAdapterCPDS.java b/src/java/org/apache/commons/dbcp/cpdsadapter/DriverAdapterCPDS.java
index f9c30b9..b0bce93 100644
--- a/src/java/org/apache/commons/dbcp/cpdsadapter/DriverAdapterCPDS.java
+++ b/src/java/org/apache/commons/dbcp/cpdsadapter/DriverAdapterCPDS.java
@@ -3,7 +3,7 @@
 /* ====================================================================
  * The Apache Software License, Version 1.1
  *
- * Copyright (c) 2001 The Apache Software Foundation.  All rights
+ * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -119,30 +119,53 @@
  * </p>
  *
  * @author <a href="mailto:jmcnally@collab.net">John D. McNally</a>
- * @version $Id: DriverAdapterCPDS.java,v 1.1 2002/08/05 06:42:01 jmcnally Exp $
+ * @version $Id: DriverAdapterCPDS.java,v 1.2 2003/06/29 12:42:16 mpoeschl Exp $
  */
 public class DriverAdapterCPDS
     implements ConnectionPoolDataSource, Referenceable, Serializable, 
-               ObjectFactory
-{
-    private static final String GET_CONNECTION_CALLED = 
-        "A PooledConnection was already requested from this source, " + 
-        "further initialization is not allowed.";
+               ObjectFactory {
+                   
+    private static final String GET_CONNECTION_CALLED 
+            = "A PooledConnection was already requested from this source, " 
+            + "further initialization is not allowed.";
+
+    /** Description */
+    private String description;
+    /** Password */
+    private String password;
+    /** Url name */
+    private String url;
+    /** User name */
+    private String user;
+    /** Driver class name */
+    private String driver;
+
+    /** Login TimeOut in seconds */
+    private int loginTimeout;
+    /** Log stream */
+    private PrintWriter logWriter = null;
+
+    // PreparedStatement pool properties
+    private boolean poolPreparedStatements;
+    private int maxActive = 10;
+    private int maxIdle = 10;
+    private int _timeBetweenEvictionRunsMillis = -1;
+    private int _numTestsPerEvictionRun = -1;
+    private int _minEvictableIdleTimeMillis = -1;
+
+    private boolean getConnectionCalled = false;
 
     /**
      * Default no-arg constructor for Serialization
      */
-    public DriverAdapterCPDS() 
-    {
+    public DriverAdapterCPDS() {
     }
 
     /**
      * Attempt to establish a database connection using the default
      * user and password.
      */
-    public PooledConnection getPooledConnection() 
-        throws SQLException
-    {
+    public PooledConnection getPooledConnection() throws SQLException {
         return getPooledConnection(getUser(), getPassword());
     }
                      
@@ -151,8 +174,7 @@
      */
     public PooledConnection getPooledConnection(String username, 
                                                 String password)
-        throws SQLException
-    {
+            throws SQLException {
         getConnectionCalled = true;
         /*
         public GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, 
@@ -163,8 +185,7 @@
         boolean testWhileIdle) {
         */
         KeyedObjectPool stmtPool = null;
-        if (isPoolPreparedStatements()) 
-        {
+        if (isPoolPreparedStatements()) {
             stmtPool = new GenericKeyedObjectPool(null,
                 getMaxActive(), GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW, 0, 
                 getMaxIdle(), false, false, getTimeBetweenEvictionRunsMillis(),
@@ -174,19 +195,16 @@
         
         // Workaround for buggy WebLogic 5.1 classloader - ignore the
         // exception upon first invocation.
-        try
-        {
+        try {
             return new PooledConnectionImpl(
-                DriverManager.getConnection( getUrl(),
-                                             username,
-                                             password ), stmtPool );
+                    DriverManager.getConnection(getUrl(), username, password), 
+                    stmtPool );
         }
-        catch( ClassCircularityError e )
+        catch (ClassCircularityError e)
         {
             return new PooledConnectionImpl(
-                DriverManager.getConnection( getUrl(),
-                                             username,
-                                             password ), stmtPool );
+                    DriverManager.getConnection(getUrl(), username, password), 
+                    stmtPool );
         }
     }
 
@@ -196,9 +214,7 @@
     /**
      * <CODE>Referenceable</CODE> implementation.
      */
-    public Reference getReference() 
-        throws NamingException 
-    {
+    public Reference getReference() throws NamingException {
         // this class implements its own factory
         String factory = getClass().getName();
         
@@ -237,80 +253,64 @@
      */ 
     public Object getObjectInstance(Object refObj, Name name, 
                                     Context context, Hashtable env) 
-        throws Exception 
-    {
+            throws Exception {
         // The spec says to return null if we can't create an instance 
         // of the reference
         DriverAdapterCPDS cpds = null;
-        if (refObj instanceof Reference) 
-        {
+        if (refObj instanceof Reference) {
             Reference ref = (Reference)refObj;
-            if (ref.getClassName().equals(getClass().getName())) 
-            {
+            if (ref.getClassName().equals(getClass().getName())) {
                 RefAddr ra = ref.get("description");
-                if (ra != null && ra.getContent() != null) 
-                {
+                if (ra != null && ra.getContent() != null) {
                     setDescription(ra.getContent().toString());
                 }
 
                 ra = ref.get("driver");
-                if (ra != null && ra.getContent() != null) 
-                {
+                if (ra != null && ra.getContent() != null) {
                     setDriver(ra.getContent().toString());
                 }
                 ra = ref.get("url");
-                if (ra != null && ra.getContent() != null) 
-                {
+                if (ra != null && ra.getContent() != null) {
                     setUrl(ra.getContent().toString());
                 }
                 ra = ref.get("user");
-                if (ra != null && ra.getContent() != null) 
-                {
+                if (ra != null && ra.getContent() != null) {
                     setUser(ra.getContent().toString());
                 }
                 ra = ref.get("password");
-                if (ra != null && ra.getContent() != null) 
-                {
+                if (ra != null && ra.getContent() != null) {
                     setPassword(ra.getContent().toString());
                 }
 
                 ra = ref.get("poolPreparedStatements");
-                if (ra != null && ra.getContent() != null) 
-                {
+                if (ra != null && ra.getContent() != null) {
                     setPoolPreparedStatements(
                         Boolean.getBoolean(ra.getContent().toString()));
                 }
                 ra = ref.get("maxActive");
-                if (ra != null && ra.getContent() != null) 
-                {
-                    setMaxActive(
-                        Integer.parseInt(ra.getContent().toString()));
+                if (ra != null && ra.getContent() != null) {
+                    setMaxActive(Integer.parseInt(ra.getContent().toString()));
                 }
 
                 ra = ref.get("maxIdle");
-                if (ra != null && ra.getContent() != null) 
-                {
-                    setMaxIdle(
-                        Integer.parseInt(ra.getContent().toString()));
+                if (ra != null && ra.getContent() != null) {
+                    setMaxIdle(Integer.parseInt(ra.getContent().toString()));
                 }
 
                 ra = ref.get("timeBetweenEvictionRunsMillis");
-                if (ra != null && ra.getContent() != null) 
-                {
+                if (ra != null && ra.getContent() != null) {
                     setTimeBetweenEvictionRunsMillis(
                         Integer.parseInt(ra.getContent().toString()));
                 }
 
                 ra = ref.get("numTestsPerEvictionRun");
-                if (ra != null && ra.getContent() != null) 
-                {
+                if (ra != null && ra.getContent() != null) {
                     setNumTestsPerEvictionRun(
                         Integer.parseInt(ra.getContent().toString()));
                 }
 
                 ra = ref.get("minEvictableIdleTimeMillis");
-                if (ra != null && ra.getContent() != null) 
-                {
+                if (ra != null && ra.getContent() != null) {
                     setMinEvictableIdleTimeMillis(
                         Integer.parseInt(ra.getContent().toString()));
                 }
@@ -318,18 +318,15 @@
                 cpds = this;
             }
         }
-            return cpds;
+        return cpds;
     }
 
     /**
      * Throws an IllegalStateException, if a PooledConnection has already
      * been requested.
      */
-    private void assertInitializationAllowed()
-        throws IllegalStateException 
-    {
-        if (getConnectionCalled) 
-        {
+    private void assertInitializationAllowed() throws IllegalStateException {
+        if (getConnectionCalled) {
             throw new IllegalStateException(GET_CONNECTION_CALLED);
         }
     }
@@ -344,8 +341,7 @@
      *
      * @return value of description.
      */
-    public String getDescription() 
-    {
+    public String getDescription() {
         return description;
     }
     
@@ -356,8 +352,7 @@
      *
      * @param v  Value to assign to description.
      */
-    public void setDescription(String  v) 
-    {
+    public void setDescription(String  v) {
         this.description = v;
     }
 
@@ -365,8 +360,7 @@
      * Get the value of password for the default user.
      * @return value of password.
      */
-    public String getPassword() 
-    {
+    public String getPassword() {
         return password;
     }
     
@@ -374,8 +368,7 @@
      * Set the value of password for the default user.
      * @param v  Value to assign to password.
      */
-    public void setPassword(String  v) 
-    {
+    public void setPassword(String v) {
         assertInitializationAllowed();
         this.password = v;
     }
@@ -384,8 +377,7 @@
      * Get the value of url used to locate the database for this datasource.
      * @return value of url.
      */
-    public String getUrl() 
-    {
+    public String getUrl() {
         return url;
     }
     
@@ -393,8 +385,7 @@
      * Set the value of url used to locate the database for this datasource.
      * @param v  Value to assign to url.
      */
-    public void setUrl(String  v) 
-    {
+    public void setUrl(String v) {
         assertInitializationAllowed();
         this.url = v;
     }
@@ -403,8 +394,7 @@
      * Get the value of default user (login or username).
      * @return value of user.
      */
-    public String getUser() 
-    {
+    public String getUser() {
         return user;
     }
     
@@ -412,8 +402,7 @@
      * Set the value of default user (login or username).
      * @param v  Value to assign to user.
      */
-    public void setUser(String  v) 
-    {
+    public void setUser(String v) {
         assertInitializationAllowed();
         this.user = v;
     }
@@ -422,8 +411,7 @@
      * Get the driver classname.
      * @return value of driver.
      */
-    public String getDriver() 
-    {
+    public String getDriver() {
         return driver;
     }
     
@@ -432,9 +420,7 @@
      * driver to be registered with the DriverManager.
      * @param v  Value to assign to driver.
      */
-    public void setDriver(String  v)
-        throws ClassNotFoundException
-    {
+    public void setDriver(String v) throws ClassNotFoundException {
         assertInitializationAllowed();
         this.driver = v;
         // make sure driver is registered
@@ -445,16 +431,14 @@
      * Gets the maximum time in seconds that this data source can wait 
      * while attempting to connect to a database. NOT USED.
      */
-    public int getLoginTimeout() 
-    {
+    public int getLoginTimeout() {
         return loginTimeout;
     }
                            
     /**
      * Get the log writer for this data source. NOT USED.
      */
-    public PrintWriter getLogWriter() 
-    {
+    public PrintWriter getLogWriter() {
         return logWriter;
     }
                            
@@ -462,16 +446,14 @@
      * Sets the maximum time in seconds that this data source will wait 
      * while attempting to connect to a database. NOT USED.
      */
-    public void setLoginTimeout(int seconds)
-    {
+    public void setLoginTimeout(int seconds) {
         loginTimeout = seconds;
     } 
                            
     /**
      * Set the log writer for this data source. NOT USED.
      */
-    public void setLogWriter(java.io.PrintWriter out)
-    {
+    public void setLogWriter(java.io.PrintWriter out) {
         logWriter = out;
     } 
 
@@ -484,8 +466,7 @@
      * Flag to toggle the pooling of <code>PreparedStatement</code>s
      * @return value of poolPreparedStatements.
      */
-    public boolean isPoolPreparedStatements() 
-    {
+    public boolean isPoolPreparedStatements() {
         return poolPreparedStatements;
     }
     
@@ -493,8 +474,7 @@
      * Flag to toggle the pooling of <code>PreparedStatement</code>s
      * @param v  true to pool statements.
      */
-    public void setPoolPreparedStatements(boolean  v) 
-    {
+    public void setPoolPreparedStatements(boolean v) {
         assertInitializationAllowed();
         this.poolPreparedStatements = v;
     }
@@ -553,10 +533,10 @@
      *
      * *see #getTimeBetweenEvictionRunsMillis
      */
-    public void 
-        setTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis) {
+    public void setTimeBetweenEvictionRunsMillis(
+            int timeBetweenEvictionRunsMillis) {
         assertInitializationAllowed();
-            _timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
+        _timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
     }
 
     /**
@@ -608,35 +588,8 @@
      * *see #getMinEvictableIdleTimeMillis
      * *see #setTimeBetweenEvictionRunsMillis
      */
-    public void 
-        setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) {
+    public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) {
         assertInitializationAllowed();
         _minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
     }
-
-    /** Description */
-    private String description;
-    /** Password */
-    private String password;
-    /** Url name */
-    private String url;
-    /** User name */
-    private String user;
-    /** Driver class name */
-    private String driver;
-
-    /** Login TimeOut in seconds */
-    private int loginTimeout;
-    /** Log stream */
-    private PrintWriter logWriter = null;
-
-    // PreparedStatement pool properties
-    private boolean poolPreparedStatements;
-    private int maxActive = 10;
-    private int maxIdle = 10;
-    private int _timeBetweenEvictionRunsMillis = -1;
-    private int _numTestsPerEvictionRun = -1;
-    private int _minEvictableIdleTimeMillis = -1;
-
-    private boolean getConnectionCalled = false;
 }
diff --git a/src/java/org/apache/commons/dbcp/cpdsadapter/PoolablePreparedStatementStub.java b/src/java/org/apache/commons/dbcp/cpdsadapter/PoolablePreparedStatementStub.java
index 2787cec..fc02cf1 100644
--- a/src/java/org/apache/commons/dbcp/cpdsadapter/PoolablePreparedStatementStub.java
+++ b/src/java/org/apache/commons/dbcp/cpdsadapter/PoolablePreparedStatementStub.java
@@ -1,13 +1,13 @@
 /*
- * $Id: PoolablePreparedStatementStub.java,v 1.2 2002/11/08 18:51:07 rwaldhoff Exp $
- * $Revision: 1.2 $
- * $Date: 2002/11/08 18:51:07 $
+ * $Id: PoolablePreparedStatementStub.java,v 1.3 2003/06/29 12:42:16 mpoeschl Exp $
+ * $Revision: 1.3 $
+ * $Date: 2003/06/29 12:42:16 $
  *
  * ====================================================================
  *
  * The Apache Software License, Version 1.1
  *
- * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
+ * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -73,10 +73,9 @@
  * package.
  *
  * @author <a href="mailto:jmcnally@collab.net">John D. McNally</a>
- * @version $Id: PoolablePreparedStatementStub.java,v 1.2 2002/11/08 18:51:07 rwaldhoff Exp $
+ * @version $Id: PoolablePreparedStatementStub.java,v 1.3 2003/06/29 12:42:16 mpoeschl Exp $
  */
-class PoolablePreparedStatementStub 
-    extends PoolablePreparedStatement {
+class PoolablePreparedStatementStub extends PoolablePreparedStatement {
 
     /**
      * Constructor
@@ -86,7 +85,7 @@
      * @param conn the {@link Connection} from which I was created
      */
     public PoolablePreparedStatementStub(PreparedStatement stmt, Object key, 
-        KeyedObjectPool pool, Connection conn) {
+            KeyedObjectPool pool, Connection conn) {
         super(stmt, key, pool, conn);
     }
 
diff --git a/src/java/org/apache/commons/dbcp/cpdsadapter/PooledConnectionImpl.java b/src/java/org/apache/commons/dbcp/cpdsadapter/PooledConnectionImpl.java
index de1c36c..ad22efd 100644
--- a/src/java/org/apache/commons/dbcp/cpdsadapter/PooledConnectionImpl.java
+++ b/src/java/org/apache/commons/dbcp/cpdsadapter/PooledConnectionImpl.java
@@ -3,7 +3,7 @@
 /* ====================================================================
  * The Apache Software License, Version 1.1
  *
- * Copyright (c) 2001 The Apache Software Foundation.  All rights
+ * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -73,13 +73,12 @@
  * PooledConnectionDataSource.
  *
  * @author <a href="mailto:jmcnally@collab.net">John D. McNally</a>
- * @version $Id: PooledConnectionImpl.java,v 1.5 2003/04/02 00:48:49 rwaldhoff Exp $
+ * @version $Id: PooledConnectionImpl.java,v 1.6 2003/06/29 12:42:16 mpoeschl Exp $
  */
 class PooledConnectionImpl 
-    implements PooledConnection, KeyedPoolableObjectFactory
-{
-    private static final String CLOSED = 
-        "Attempted to use PooledConnection after closed() was called.";
+        implements PooledConnection, KeyedPoolableObjectFactory {
+    private static final String CLOSED 
+            = "Attempted to use PooledConnection after closed() was called.";
 
     /**
      * The JDBC database connection that represents the physical db connection.
@@ -108,13 +107,11 @@
     /**
      * Wrap the real connection.
      */
-    PooledConnectionImpl(Connection connection, KeyedObjectPool pool)
-    {
+    PooledConnectionImpl(Connection connection, KeyedObjectPool pool) {
         this.connection = connection;
         eventListeners = new Vector();
         isClosed = false;
-        if (pool != null) 
-        {
+        if (pool != null) {
             pstmtPool = pool;
             pstmtPool.setFactory(this);            
         }
@@ -123,10 +120,8 @@
     /**
      * Add an event listener.
      */
-    public void addConnectionEventListener(ConnectionEventListener listener)
-    {
-        if ( !eventListeners.contains(listener) )
-        {
+    public void addConnectionEventListener(ConnectionEventListener listener) {
+        if (!eventListeners.contains(listener)) {
             eventListeners.add(listener);
         }
     }
@@ -138,38 +133,24 @@
      *
      * @exception SQLException if an error occurs
      */
-    public void close()
-        throws SQLException
-    {        
+    public void close() throws SQLException {        
         assertOpen();
         isClosed = true;
-        try
-        {
-            if (pstmtPool != null) 
-            {
-                try
-                {
+        try {
+            if (pstmtPool != null) {
+                try {
                     pstmtPool.close();
-                }
-                finally
-                {
+                } finally {
                     pstmtPool = null;
                 }
             }
-        }
-        catch (Exception e)
-        {
-            if (e instanceof RuntimeException) 
-            {
+        } catch (Exception e) {
+            if (e instanceof RuntimeException) {
                 throw (RuntimeException)e;
-            }
-            else 
-            {
+            } else {
                 throw new SQLException(e.getMessage());
             }
-        }
-        finally
-        {
+        } finally {
             connection.close();
         }
     }
@@ -177,11 +158,8 @@
     /**
      * Throws an SQLException, if isClosed() is true
      */
-    private void assertOpen()
-        throws SQLException 
-    {
-        if ( isClosed ) 
-        {
+    private void assertOpen() throws SQLException {
+        if (isClosed) {
             throw new SQLException(CLOSED);
         }
     }
@@ -191,17 +169,14 @@
      *
      * @return The database connection.
      */
-    public Connection getConnection()
-        throws SQLException
-    {
+    public Connection getConnection() throws SQLException {
         assertOpen();
         // make sure the last connection is marked as closed
-        if ( logicalConnection != null && !logicalConnection.isClosed() ) 
-        {
+        if (logicalConnection != null && !logicalConnection.isClosed()) {
             // should notify pool of error so the pooled connection can
             // be removed !FIXME!
-            throw new SQLException("PooledConnection was reused, without" +
-                                   "its previous Connection being closed.");
+            throw new SQLException("PooledConnection was reused, without" 
+                    + "its previous Connection being closed.");
         }
 
         // the spec requires that this return a new Connection instance.
@@ -212,8 +187,8 @@
     /**
      * Remove an event listener.
      */
-    public void removeConnectionEventListener(ConnectionEventListener listener)
-    {
+    public void removeConnectionEventListener(
+            ConnectionEventListener listener) {
         eventListeners.remove(listener);
     }
 
@@ -221,37 +196,29 @@
      * Closes the physical connection and checks that the logical connection
      * was closed as well.
      */
-    protected void finalize()
-        throws Throwable
-    {
+    protected void finalize() throws Throwable {
         // Closing the Connection ensures that if anyone tries to use it,
         // an error will occur.
-        try
-        {
+        try {
             connection.close();
-        }
-        catch (Exception ignored)
-        {
+        } catch (Exception ignored) {
         }
 
         // make sure the last connection is marked as closed
-        if ( logicalConnection != null && !logicalConnection.isClosed() ) 
-        {
-            throw new SQLException("PooledConnection was gc'ed, without" +
-                                   "its last Connection being closed.");
+        if (logicalConnection != null && !logicalConnection.isClosed()) {
+            throw new SQLException("PooledConnection was gc'ed, without" 
+                    + "its last Connection being closed.");
         }        
     }
 
     /**
      * sends a connectionClosed event.
      */
-    void notifyListeners()
-    {
+    void notifyListeners() {
         ConnectionEvent event = new ConnectionEvent(this);
         Iterator i = eventListeners.iterator();
-        while ( i.hasNext() ) 
-        {
-            ((ConnectionEventListener)i.next()).connectionClosed(event);
+        while (i.hasNext()) {
+            ((ConnectionEventListener) i.next()).connectionClosed(event);
         }
     }
 
@@ -262,21 +229,16 @@
      * Create or obtain a {*link PreparedStatement} from my pool.
      * @return a {*link PoolablePreparedStatement}
      */
-    PreparedStatement prepareStatement(String sql) 
-        throws SQLException 
-    {
-        if (pstmtPool == null) 
-        {
+    PreparedStatement prepareStatement(String sql) throws SQLException {
+        if (pstmtPool == null) {
             return connection.prepareStatement(sql);
-        }
-        else 
-        {
+        } else {
             try {
-                return (PreparedStatement)
-                    pstmtPool.borrowObject(createKey(sql));
-            } catch(RuntimeException e) {
+                return (PreparedStatement) 
+                        pstmtPool.borrowObject(createKey(sql));
+            } catch (RuntimeException e) {
                 throw e;
-            } catch(Exception e) {
+            } catch (Exception e) {
                 throw new SQLException(e.toString());
             }
         }
@@ -288,20 +250,16 @@
      */
     PreparedStatement prepareStatement(String sql, int resultSetType, 
                                        int resultSetConcurrency) 
-        throws SQLException 
-    {
-        if (pstmtPool == null) 
-        {
+            throws SQLException {
+        if (pstmtPool == null) {
             return connection.prepareStatement(sql);
-        }
-        else 
-        {
+        } else {
             try {
                 return (PreparedStatement) pstmtPool.borrowObject(
                     createKey(sql,resultSetType,resultSetConcurrency));
-            } catch(RuntimeException e) {
+            } catch (RuntimeException e) {
                 throw e;
-            } catch(Exception e) {
+            } catch (Exception e) {
                 throw new SQLException(e.toString());
             }
         }
@@ -338,26 +296,25 @@
      */
     public Object makeObject(Object obj) {
         try {
-            if(null == obj || !(obj instanceof PStmtKey)) {
+            if (null == obj || !(obj instanceof PStmtKey)) {
                 throw new IllegalArgumentException();
             } else {
                 // _openPstmts++;
                 PStmtKey key = (PStmtKey)obj;
-                if(null == key._resultSetType && null == 
-                   key._resultSetConcurrency) 
-                {
+                if (null == key._resultSetType 
+                        && null == key._resultSetConcurrency) {
                     return new PoolablePreparedStatementStub(
-                        connection.prepareStatement(key._sql),
-                        key, pstmtPool, connection);
+                            connection.prepareStatement(key._sql),
+                            key, pstmtPool, connection);
                 } else {
                     return new PoolablePreparedStatementStub(
-                        connection.prepareStatement(key._sql,
-                        key._resultSetType.intValue(),
-                        key._resultSetConcurrency.intValue()),
-                        key, pstmtPool, connection);
+                            connection.prepareStatement(key._sql,
+                            key._resultSetType.intValue(),
+                            key._resultSetConcurrency.intValue()),
+                            key, pstmtPool, connection);
                 }
             }
-        } catch(Exception e) {
+        } catch (Exception e) {
             throw new RuntimeException(e.toString());
         }
     }
@@ -370,10 +327,10 @@
      */
     public void destroyObject(Object key, Object obj) throws Exception {
         //_openPstmts--;
-        if(obj instanceof DelegatingPreparedStatement) {
-            ((DelegatingPreparedStatement)obj).getInnermostDelegate().close();
+        if (obj instanceof DelegatingPreparedStatement) {
+            ((DelegatingPreparedStatement) obj).getInnermostDelegate().close();
         } else {
-            ((PreparedStatement)obj).close();
+            ((PreparedStatement) obj).close();
         }
     }
 
@@ -395,7 +352,7 @@
      * @param obj ignored
      */
     public void activateObject(Object key, Object obj) {
-        ((PoolablePreparedStatementStub)obj).activate();
+        ((PoolablePreparedStatementStub) obj).activate();
     }
 
     /**
@@ -405,8 +362,8 @@
      * @param obj a {*link PreparedStatement}
      */
     public void passivateObject(Object key, Object obj) throws Exception {
-        ((PreparedStatement)obj).clearParameters();
-        ((PoolablePreparedStatementStub)obj).passivate();
+        ((PreparedStatement) obj).clearParameters();
+        ((PoolablePreparedStatementStub) obj).passivate();
     }
 
     /**
@@ -429,14 +386,14 @@
 
         public boolean equals(Object that) {
             try {
-                PStmtKey key = (PStmtKey)that;
-                return( ((null == _sql && null == key._sql) || _sql.equals(key._sql)) &&
-                        ((null == _resultSetType && null == key._resultSetType) || _resultSetType.equals(key._resultSetType)) &&
-                        ((null == _resultSetConcurrency && null == key._resultSetConcurrency) || _resultSetConcurrency.equals(key._resultSetConcurrency))
+                PStmtKey key = (PStmtKey) that;
+                return(((null == _sql && null == key._sql) || _sql.equals(key._sql)) &&
+                       ((null == _resultSetType && null == key._resultSetType) || _resultSetType.equals(key._resultSetType)) &&
+                       ((null == _resultSetConcurrency && null == key._resultSetConcurrency) || _resultSetConcurrency.equals(key._resultSetConcurrency))
                       );
-            } catch(ClassCastException e) {
+            } catch (ClassCastException e) {
                 return false;
-            } catch(NullPointerException e) {
+            } catch (NullPointerException e) {
                 return false;
             }
         }
diff --git a/src/java/org/apache/commons/dbcp/jdbc2pool/CPDSConnectionFactory.java b/src/java/org/apache/commons/dbcp/jdbc2pool/CPDSConnectionFactory.java
index 2385233..1b37c6d 100644
--- a/src/java/org/apache/commons/dbcp/jdbc2pool/CPDSConnectionFactory.java
+++ b/src/java/org/apache/commons/dbcp/jdbc2pool/CPDSConnectionFactory.java
@@ -1,13 +1,13 @@
 /*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//dbcp/src/java/org/apache/commons/dbcp/jdbc2pool/Attic/CPDSConnectionFactory.java,v 1.5 2003/04/02 00:48:49 rwaldhoff Exp $
- * $Revision: 1.5 $
- * $Date: 2003/04/02 00:48:49 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//dbcp/src/java/org/apache/commons/dbcp/jdbc2pool/Attic/CPDSConnectionFactory.java,v 1.6 2003/06/29 12:42:16 mpoeschl Exp $
+ * $Revision: 1.6 $
+ * $Date: 2003/06/29 12:42:16 $
  *
  * ====================================================================
  *
  * The Apache Software License, Version 1.1
  *
- * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
+ * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -82,15 +82,32 @@
  * {@link PoolableConnection}s.
  *
  * @author <a href="mailto:jmcnally@collab.net">John D. McNally</a>
- * @version $Id: CPDSConnectionFactory.java,v 1.5 2003/04/02 00:48:49 rwaldhoff Exp $
+ * @version $Id: CPDSConnectionFactory.java,v 1.6 2003/06/29 12:42:16 mpoeschl Exp $
  */
 class CPDSConnectionFactory 
-    implements PoolableObjectFactory, ConnectionEventListener {
+        implements PoolableObjectFactory, ConnectionEventListener {
+
+    private static final String NO_KEY_MESSAGE 
+            = "close() was called on a Connection, but " 
+            + "I have no record of the underlying PooledConnection.";
+
+    protected ConnectionPoolDataSource _cpds = null;
+    protected String _validationQuery = null;
+    protected ObjectPool _pool = null;
+    protected String _username = null;
+    protected String _password = null;
+    private Map validatingMap = new HashMap();
+    private WeakHashMap pcMap = new WeakHashMap();
+
     /**
      * Create a new <tt>PoolableConnectionFactory</tt>.
-     * @param cpds the ConnectionPoolDataSource from which to obtain PooledConnection's
-     * @param pool the {*link ObjectPool} in which to pool those {*link Connection}s
-     * @param validationQuery a query to use to {*link #validateObject validate} {*link Connection}s.  Should return at least one row. May be <tt>null</tt>
+     * @param cpds the ConnectionPoolDataSource from which to obtain 
+     *        PooledConnection's
+     * @param pool the {*link ObjectPool} in which to pool those 
+     *        {*link Connection}s
+     * @param validationQuery a query to use to {*link #validateObject validate}
+     *        {*link Connection}s. Should return at least one row. 
+     *        May be <tt>null</tt>
      * @param username 
      * @param password
      */
@@ -108,43 +125,40 @@
     }
 
     /**
-     * Sets the {*link ConnectionFactory} from which to obtain base {*link Connection}s.
-     * @param connFactory the {*link ConnectionFactory} from which to obtain base {*link Connection}s
+     * Sets the {*link ConnectionFactory} from which to obtain base 
+     * {*link Connection}s.
+     * @param connFactory the {*link ConnectionFactory} from which to obtain 
+     *        base {*link Connection}s
      */
-    synchronized public void setCPDS(ConnectionPoolDataSource cpds) {
+    public synchronized void setCPDS(ConnectionPoolDataSource cpds) {
         _cpds = cpds;
     }
 
     /**
-     * Sets the query I use to {*link #validateObject validate} {*link Connection}s.
+     * Sets the query I use to {*link #validateObject validate} 
+     * {*link Connection}s.
      * Should return at least one row.
      * May be <tt>null</tt>
-     * @param validationQuery a query to use to {*link #validateObject validate} {*link Connection}s.
+     * @param validationQuery a query to use to {*link #validateObject validate} 
+     *        {*link Connection}s.
      */
-    synchronized public void setValidationQuery(String validationQuery) {
+    public synchronized void setValidationQuery(String validationQuery) {
         _validationQuery = validationQuery;
     }
 
     /**
      * Sets the {*link ObjectPool} in which to pool {*link Connection}s.
-     * @param pool the {*link ObjectPool} in which to pool those {*link Connection}s
+     * @param pool the {*link ObjectPool} in which to pool those 
+     *        {*link Connection}s
      */
-    synchronized public void setPool(ObjectPool pool) 
-        throws SQLException
-    {
-        if(null != _pool && pool != _pool) {
-            try
-            {
+    public synchronized void setPool(ObjectPool pool) throws SQLException {
+        if (null != _pool && pool != _pool) {
+            try {
                 _pool.close();
-            }
-            catch (Exception e)
-            {
-                if (e instanceof RuntimeException) 
-                {
-                    throw (RuntimeException)e;
-                }
-                else 
-                {
+            } catch (Exception e) {
+                if (e instanceof RuntimeException) {
+                    throw (RuntimeException) e;
+                } else {
                     throw new SQLException(e.getMessage());
                 }
             }
@@ -156,18 +170,13 @@
         return _pool;
     }
 
-
-    synchronized public Object makeObject() {
+    public synchronized Object makeObject() {
         Object obj;
-        try
-        {
+        try {
             PooledConnection pc = null;
-            if ( _username == null ) 
-            {
+            if (_username == null) {
                 pc = _cpds.getPooledConnection();
-            }
-            else 
-            {
+            } else {
                 pc = _cpds.getPooledConnection(_username, _password);
             }
             // should we add this object as a listener or the pool.
@@ -175,28 +184,25 @@
             pc.addConnectionEventListener(this);
             obj = new PooledConnectionAndInfo(pc, _username, _password);
             pcMap.put(pc, obj);
-        }
-        catch (SQLException e)
-        {
+        } catch (SQLException e) {
             throw new RuntimeException(e.getMessage());
         }
         return obj;
     }
 
     public void destroyObject(Object obj) throws Exception {
-        if(obj instanceof PooledConnectionAndInfo) {
-            ((PooledConnectionAndInfo)obj)
-                .getPooledConnection().close();
+        if (obj instanceof PooledConnectionAndInfo) {
+            ((PooledConnectionAndInfo) obj).getPooledConnection().close();
         }
     }
 
     public boolean validateObject(Object obj) {
         boolean valid = false;
-        if(obj instanceof PooledConnectionAndInfo) {
+        if (obj instanceof PooledConnectionAndInfo) {
             PooledConnection pconn = 
-                ((PooledConnectionAndInfo)obj).getPooledConnection();
+                ((PooledConnectionAndInfo) obj).getPooledConnection();
             String query = _validationQuery;
-            if(null != query) {
+            if (null != query) {
                 Connection conn = null;
                 Statement stmt = null;
                 ResultSet rset = null;
@@ -209,29 +215,27 @@
                     conn = pconn.getConnection();
                     stmt = conn.createStatement();
                     rset = stmt.executeQuery(query);
-                    if(rset.next()) {
+                    if (rset.next()) {
                         valid = true;
                     } else {
                         valid = false;
                     }
-                } catch(Exception e) {
+                } catch (Exception e) {
                     valid = false;
-                }
-                finally 
-                {
+                } finally {
                     try {
                         rset.close();
-                    } catch(Throwable t) {
+                    } catch (Throwable t) {
                         // ignore
                     }
                     try {
                         stmt.close();
-                    } catch(Throwable t) {
+                    } catch (Throwable t) {
                         // ignore
                     }
                     try {
                         conn.close();
-                    } catch(Throwable t) {
+                    } catch (Throwable t) {
                         // ignore
                     }
                     validatingMap.remove(pconn);
@@ -261,34 +265,27 @@
      * method of this connection object. What we need to do here is to
      * release this PooledConnection from our pool...
      */
-    public void connectionClosed(ConnectionEvent event)  
-    {
-        PooledConnection pc = (PooledConnection)event.getSource();
+    public void connectionClosed(ConnectionEvent event) {
+        PooledConnection pc = (PooledConnection) event.getSource();
         // if this event occured becase we were validating, ignore it
         // otherwise return the connection to the pool.
-        if (!validatingMap.containsKey(pc)) 
-        {
+        if (!validatingMap.containsKey(pc)) {
             Object info = pcMap.get(pc);
-            if (info == null) 
-            {
+            if (info == null) {
                 throw new IllegalStateException(NO_KEY_MESSAGE);
             }            
 
-            try
-            {
+            try {
                 _pool.returnObject(info);
-            }
-            catch (Exception e)
-            {
-                System.err.println("CLOSING DOWN CONNECTION AS IT COULD " + 
-                                   "NOT BE RETURNED TO THE POOL");
+            } catch (Exception e) {
+                System.err.println("CLOSING DOWN CONNECTION AS IT COULD " 
+                        + "NOT BE RETURNED TO THE POOL");
                 try {
                     destroyObject(info);
-                } catch(Exception e2) {
-                    System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + 
-                                       info);
+                } catch (Exception e2) {
+                    System.err.println("EXCEPTION WHILE DESTROYING OBJECT " 
+                            + info);
                     e2.printStackTrace();
-
                 }
             }
         }
@@ -298,48 +295,31 @@
      * If a fatal error occurs, close the underlying physical connection so as
      * not to be returned in the future
      */
-    public void connectionErrorOccurred(ConnectionEvent event) 
-    {
+    public void connectionErrorOccurred(ConnectionEvent event) {
         PooledConnection pc = (PooledConnection)event.getSource();
-        try 
-        {
-            if(null != event.getSQLException()) {
-                System.err
-                    .println("CLOSING DOWN CONNECTION DUE TO INTERNAL ERROR (" +
-                             event.getSQLException() + ")");
+        try {
+            if (null != event.getSQLException()) {
+                System.err.println(
+                        "CLOSING DOWN CONNECTION DUE TO INTERNAL ERROR (" 
+                        + event.getSQLException() + ")");
             }
             //remove this from the listener list because we are no more 
             //interested in errors since we are about to close this connection
             pc.removeConnectionEventListener(this);
-        }
-        catch (Exception ignore) 
-        {
+        } catch (Exception ignore) {
             // ignore
         }
 
         Object info = pcMap.get(pc);
-        if (info == null) 
-        {
+        if (info == null) {
             throw new IllegalStateException(NO_KEY_MESSAGE);
         }            
         try {
             destroyObject(info);
-        } catch(Exception e) {
-            System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + 
-                               info);
+        } catch (Exception e) {
+            System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + info);
             e.printStackTrace();
         }
     }
 
-    private static final String NO_KEY_MESSAGE = 
-        "close() was called on a Connection, but " + 
-        "I have no record of the underlying PooledConnection.";
-
-    protected ConnectionPoolDataSource _cpds = null;
-    protected String _validationQuery = null;
-    protected ObjectPool _pool = null;
-    protected String _username = null;
-    protected String _password = null;
-    private Map validatingMap = new HashMap();
-    private WeakHashMap pcMap = new WeakHashMap();
 }
diff --git a/src/java/org/apache/commons/dbcp/jdbc2pool/Jdbc2PoolDataSource.java b/src/java/org/apache/commons/dbcp/jdbc2pool/Jdbc2PoolDataSource.java
index a2d4b7b..f42fbe7 100644
--- a/src/java/org/apache/commons/dbcp/jdbc2pool/Jdbc2PoolDataSource.java
+++ b/src/java/org/apache/commons/dbcp/jdbc2pool/Jdbc2PoolDataSource.java
@@ -3,7 +3,7 @@
 /* ====================================================================
  * The Apache Software License, Version 1.1
  *
- * Copyright (c) 2001 The Apache Software Foundation.  All rights
+ * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -145,14 +145,13 @@
  * </p>
  *
  * @author <a href="mailto:jmcnally@collab.net">John D. McNally</a>
- * @version $Id: Jdbc2PoolDataSource.java,v 1.11 2003/04/15 01:58:54 dgraham Exp $
+ * @version $Id: Jdbc2PoolDataSource.java,v 1.12 2003/06/29 12:42:16 mpoeschl Exp $
  */
 public class Jdbc2PoolDataSource
-    implements DataSource, Referenceable, Serializable, ObjectFactory
-{
-    private static final String GET_CONNECTION_CALLED = 
-        "A Connection was already requested from this source, " + 
-        "further initialization is not allowed.";
+        implements DataSource, Referenceable, Serializable, ObjectFactory {
+    private static final String GET_CONNECTION_CALLED 
+            = "A Connection was already requested from this source, " 
+            + "further initialization is not allowed.";
 
     private static Map dsInstanceMap = new HashMap();
 
@@ -206,8 +205,7 @@
     /**
      * Default no-arg constructor for Serialization
      */
-    public Jdbc2PoolDataSource() 
-    {
+    public Jdbc2PoolDataSource() {
         isNew = true;
         defaultAutoCommit = true;
     }
@@ -217,10 +215,8 @@
      * been requested.
      */
     private void assertInitializationAllowed()
-        throws IllegalStateException 
-    {
-        if (getConnectionCalled) 
-        {
+        throws IllegalStateException {
+        if (getConnectionCalled) {
             throw new IllegalStateException(GET_CONNECTION_CALLED);
         }
     }
@@ -228,13 +224,11 @@
     /**
      * Close all pools associated with this class.
      */
-    public static void closeAll() 
-    {
+    public static void closeAll() {
         //Get iterator to loop over all instances of this datasource.
         Iterator instanceIterator = dsInstanceMap.entrySet().iterator();
         
-        while (instanceIterator.hasNext()) 
-        {        
+        while (instanceIterator.hasNext()) {        
             Map.Entry nextInstance = (Map.Entry) instanceIterator.next();
             Map nextPoolMap = (Map) nextInstance.getValue();
             close(nextPoolMap);
@@ -245,36 +239,26 @@
     /**
      * Close all pools in the given Map.
      */
-    private static void close(Map poolMap) 
-    {
+    private static void close(Map poolMap) {
         //Get iterator to loop over all pools.
         Iterator poolIter = poolMap.entrySet().iterator();
         
-        while (poolIter.hasNext()) 
-        {    
+        while (poolIter.hasNext()) {    
             Map.Entry nextPoolEntry = (Map.Entry) poolIter.next();
             
-            if (nextPoolEntry.getValue() instanceof ObjectPool) 
-            {
+            if (nextPoolEntry.getValue() instanceof ObjectPool) {
                 ObjectPool nextPool = (ObjectPool) nextPoolEntry.getValue();
-                try 
-                {
+                try {
                     nextPool.close();
-                } 
-                catch (Exception closePoolException) 
-                {
+                } catch (Exception closePoolException) {
                     //ignore and try to close others.
                 }
-            } 
-            else 
-            {
+            } else {
                 KeyedObjectPool nextPool = 
                     (KeyedObjectPool) nextPoolEntry.getValue();
                 try {
                     nextPool.close();
-                } 
-                catch (Exception closePoolException) 
-                {
+                } catch (Exception closePoolException) {
                     //ignore and try to close others.
                 }                                               
             }
@@ -284,8 +268,7 @@
     /**
      * Close pool(s) being maintained by this datasource.
      */
-    public void close() 
-    {
+    public void close() {
         close((Map)dsInstanceMap.get(instanceKey));
     }
 
@@ -298,8 +281,7 @@
      *
      * @return value of connectionPoolDataSource.
      */
-    public ConnectionPoolDataSource getConnectionPoolDataSource() 
-    {
+    public ConnectionPoolDataSource getConnectionPoolDataSource() {
         return cpds;
     }
     
@@ -309,17 +291,14 @@
      *
      * @param v  Value to assign to connectionPoolDataSource.
      */
-    public void setConnectionPoolDataSource(ConnectionPoolDataSource  v) 
-    {
+    public void setConnectionPoolDataSource(ConnectionPoolDataSource v) {
         assertInitializationAllowed();
-        if (dataSourceName != null) 
-        {
+        if (dataSourceName != null) {
             throw new IllegalStateException(
                 "Cannot set the DataSource, if JNDI is used.");
         }
         this.cpds = v;
-        if (isNew) 
-        {
+        if (isNew) {
             registerInstance();
         }
     }
@@ -331,8 +310,7 @@
      *
      * @return value of dataSourceName.
      */
-    public String getDataSourceName() 
-    {
+    public String getDataSourceName() {
         return dataSourceName;
     }
     
@@ -343,23 +321,19 @@
      *
      * @param v  Value to assign to dataSourceName.
      */
-    public void setDataSourceName(String  v) 
-    {
+    public void setDataSourceName(String v) {
         assertInitializationAllowed();
-        if (cpds != null) 
-        {
+        if (cpds != null) {
             throw new IllegalStateException(
                 "Cannot set the JNDI name for the DataSource, if already " +
                 "set using setConnectionPoolDataSource.");
         }
         this.dataSourceName = v;
-        if (isNew) 
-        {
+        if (isNew) {
             registerInstance();
         }
     }
 
-    
     /** 
      * Get the value of defaultAutoCommit, which defines the state of 
      * connections handed out from this pool.  The value can be changed
@@ -368,8 +342,7 @@
      *
      * @return value of defaultAutoCommit.
      */
-    public boolean isDefaultAutoCommit() 
-    {
+    public boolean isDefaultAutoCommit() {
         return defaultAutoCommit;
     }
     
@@ -381,13 +354,11 @@
      *
      * @param v  Value to assign to defaultAutoCommit.
      */
-    public void setDefaultAutoCommit(boolean  v) 
-    {
+    public void setDefaultAutoCommit(boolean v) {
         assertInitializationAllowed();
         this.defaultAutoCommit = v;
     }
 
-
     /**
      * The maximum number of active connections that can be allocated from
      * this pool at the same time, or zero for no limit.
@@ -409,7 +380,6 @@
         this.defaultMaxActive = maxActive;
     }
 
-
     /**
      * The maximum number of active connections that can remain idle in the
      * pool, without extra ones being released, or zero for no limit.
@@ -431,7 +401,6 @@
         this.defaultMaxIdle = defaultMaxIdle;
     }
 
-
     /**
      * The maximum number of milliseconds that the pool will wait (when there
      * are no available connections) for a connection to be returned before
@@ -457,7 +426,6 @@
         this.defaultMaxWait = defaultMaxWait;
     }
 
-
     /**
      * Get the value of defaultReadOnly, which defines the state of 
      * connections handed out from this pool.  The value can be changed
@@ -466,8 +434,7 @@
      *
      * @return value of defaultReadOnly.
      */
-    public boolean isDefaultReadOnly() 
-    {
+    public boolean isDefaultReadOnly() {
         return defaultReadOnly;
     }
     
@@ -479,12 +446,10 @@
      *
      * @param v  Value to assign to defaultReadOnly.
      */
-    public void setDefaultReadOnly(boolean  v) 
-    {
+    public void setDefaultReadOnly(boolean v) {
         assertInitializationAllowed();
         this.defaultReadOnly = v;
     }
-
     
     /**
      * Get the description.  This property is defined by jdbc as for use with
@@ -493,8 +458,7 @@
      *
      * @return value of description.
      */
-    public String getDescription() 
-    {
+    public String getDescription() {
         return description;
     }
     
@@ -505,12 +469,10 @@
      * 
      * @param v  Value to assign to description.
      */
-    public void setDescription(String  v) 
-    {
+    public void setDescription(String v) {
         this.description = v;
     }
         
-
     /**
      * Get the value of jndiEnvironment which is used when instantiating
      * a jndi InitialContext.  This InitialContext is used to locate the
@@ -518,11 +480,9 @@
      *
      * @return value of jndiEnvironment.
      */
-    public String getJndiEnvironment(String key) 
-    {
+    public String getJndiEnvironment(String key) {
         String value = null;
-        if (jndiEnvironment != null) 
-        {
+        if (jndiEnvironment != null) {
             value = jndiEnvironment.getProperty(key);
         }
         return value;
@@ -535,22 +495,18 @@
      *
      * @param v  Value to assign to jndiEnvironment.
      */
-    public void setJndiEnvironment(String key, String value) 
-    {
-        if (jndiEnvironment == null) 
-        {
+    public void setJndiEnvironment(String key, String value) {
+        if (jndiEnvironment == null) {
             jndiEnvironment = new Properties();
         }
         jndiEnvironment.setProperty(key, value);
     }
-
     
     /**
      * Get the value of loginTimeout.
      * @return value of loginTimeout.
      */
-    public int getLoginTimeout() 
-    {
+    public int getLoginTimeout() {
         return loginTimeout;
     }
     
@@ -558,20 +514,16 @@
      * Set the value of loginTimeout.
      * @param v  Value to assign to loginTimeout.
      */
-    public void setLoginTimeout(int  v) 
-    {
+    public void setLoginTimeout(int v) {
         this.loginTimeout = v;
     }
-    
-    
+        
     /**
      * Get the value of logWriter.
      * @return value of logWriter.
      */
-    public PrintWriter getLogWriter() 
-    {
-        if (logWriter == null) 
-        {
+    public PrintWriter getLogWriter() {
+        if (logWriter == null) {
             logWriter = new PrintWriter(System.out);
         }        
         return logWriter;
@@ -581,22 +533,18 @@
      * Set the value of logWriter.
      * @param v  Value to assign to logWriter.
      */
-    public void setLogWriter(PrintWriter  v) 
-    {
+    public void setLogWriter(PrintWriter v) {
         this.logWriter = v;
     }
     
-
     /**
      * The keys are usernames and the value is the --.  Any 
      * username specified here will override the value of defaultAutoCommit.
      */
-    public Boolean getPerUserDefaultAutoCommit(String key) 
-    {
+    public Boolean getPerUserDefaultAutoCommit(String key) {
         Boolean value = null;
-        if (perUserDefaultAutoCommit != null) 
-        {
-            value = (Boolean)perUserDefaultAutoCommit.get(key);
+        if (perUserDefaultAutoCommit != null) {
+            value = (Boolean) perUserDefaultAutoCommit.get(key);
         }
         return value;
     }
@@ -605,16 +553,13 @@
      * The keys are usernames and the value is the --.  Any 
      * username specified here will override the value of defaultAutoCommit.
      */
-    public void setPerUserDefaultAutoCommit(String username, Boolean value) 
-    {
+    public void setPerUserDefaultAutoCommit(String username, Boolean value) {
         assertInitializationAllowed();
-        if (perUserDefaultAutoCommit == null) 
-        {
+        if (perUserDefaultAutoCommit == null) {
             perUserDefaultAutoCommit = new HashMap();
         }
         perUserDefaultAutoCommit.put(username, value);
     }
-
     
     /**
      * The maximum number of active connections that can be allocated from
@@ -622,12 +567,10 @@
      * The keys are usernames and the value is the maximum connections.  Any 
      * username specified here will override the value of defaultMaxActive.
      */
-    public Integer getPerUserMaxActive(String username) 
-    {
+    public Integer getPerUserMaxActive(String username) {
         Integer value = null;
-        if (perUserMaxActive != null) 
-        {
-            value = (Integer)perUserMaxActive.get(username);
+        if (perUserMaxActive != null) {
+            value = (Integer) perUserMaxActive.get(username);
         }
         return value;
     }
@@ -638,11 +581,9 @@
      * The keys are usernames and the value is the maximum connections.  Any 
      * username specified here will override the value of defaultMaxActive.
      */
-    public void setPerUserMaxActive(String username, Integer value) 
-    {
+    public void setPerUserMaxActive(String username, Integer value) {
         assertInitializationAllowed();
-        if (perUserMaxActive == null) 
-        {
+        if (perUserMaxActive == null) {
             perUserMaxActive = new HashMap();
         }
         perUserMaxActive.put(username, value);
@@ -655,12 +596,10 @@
      * The keys are usernames and the value is the maximum connections.  Any 
      * username specified here will override the value of defaultMaxIdle.
      */
-    public Integer getPerUserMaxIdle(String username) 
-    {
+    public Integer getPerUserMaxIdle(String username) {
         Integer value = null;
-        if (perUserMaxIdle != null) 
-        {
-            value = (Integer)perUserMaxIdle.get(username);
+        if (perUserMaxIdle != null) {
+            value = (Integer) perUserMaxIdle.get(username);
         }
         return value;
     }
@@ -671,11 +610,9 @@
      * The keys are usernames and the value is the maximum connections.  Any 
      * username specified here will override the value of defaultMaxIdle.
      */
-    public void setPerUserMaxIdle(String username, Integer value) 
-    {
+    public void setPerUserMaxIdle(String username, Integer value) {
         assertInitializationAllowed();
-        if (perUserMaxIdle == null) 
-        {
+        if (perUserMaxIdle == null) {
             perUserMaxIdle = new HashMap();
         }
         perUserMaxIdle.put(username, value);
@@ -689,12 +626,10 @@
      * The keys are usernames and the value is the maximum connections.  Any 
      * username specified here will override the value of defaultMaxWait.
      */
-    public Integer getPerUserMaxWait(String username) 
-    {
+    public Integer getPerUserMaxWait(String username) {
         Integer value = null;
-        if (perUserMaxWait != null) 
-        {
-            value = (Integer)perUserMaxWait.get(username);
+        if (perUserMaxWait != null) {
+            value = (Integer) perUserMaxWait.get(username);
         }
         return value;
     }
@@ -707,27 +642,22 @@
      * The keys are usernames and the value is the maximum connections.  Any 
      * username specified here will override the value of defaultMaxWait.
      */
-    public void setPerUserMaxWait(String username, Integer value) 
-    {
+    public void setPerUserMaxWait(String username, Integer value) {
         assertInitializationAllowed();
-        if (perUserMaxWait == null) 
-        {
+        if (perUserMaxWait == null) {
             perUserMaxWait = new HashMap();
         }
         perUserMaxWait.put(username, value);
     }
 
-
     /**
      * The keys are usernames and the value is the --.  Any 
      * username specified here will override the value of defaultReadOnly.
      */
-    public Boolean getPerUserDefaultReadOnly(String username) 
-    {
+    public Boolean getPerUserDefaultReadOnly(String username) {
         Boolean value = null;
-        if (perUserDefaultReadOnly != null) 
-        {
-            value = (Boolean)perUserDefaultReadOnly.get(username);
+        if (perUserDefaultReadOnly != null) {
+            value = (Boolean) perUserDefaultReadOnly.get(username);
         }
         return value;
     }
@@ -736,21 +666,18 @@
      * The keys are usernames and the value is the --.  Any 
      * username specified here will override the value of defaultReadOnly.
      */
-    public void setPerUserDefaultReadOnly(String username, Boolean value) 
-    {
+    public void setPerUserDefaultReadOnly(String username, Boolean value) {
         assertInitializationAllowed();
-        if (perUserDefaultReadOnly == null) 
-        {
+        if (perUserDefaultReadOnly == null) {
             perUserDefaultReadOnly = new HashMap();
         }
         perUserDefaultReadOnly.put(username, value);
     }
 
-
     /**
      * @see #getTestOnBorrow
      */
-    final public boolean isTestOnBorrow() {
+    public final boolean isTestOnBorrow() {
         return getTestOnBorrow();
     }
     
@@ -787,7 +714,7 @@
     /**
      * @see #getTestOnReturn
      */
-    final public boolean isTestOnReturn() {
+    public final boolean isTestOnReturn() {
         return getTestOnReturn();
     }
     
@@ -892,8 +819,7 @@
      * @see #getMinEvictableIdleTimeMillis
      * @see #setTimeBetweenEvictionRunsMillis
      */
-    public void 
-        setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) {
+    public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) {
         assertInitializationAllowed();
         _minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
     }
@@ -901,9 +827,10 @@
     /**
      * @see #getTestWhileIdle
      */
-    final public boolean isTestWhileIdle() {
+    public final boolean isTestWhileIdle() {
         return getTestWhileIdle();
     }
+    
     /**
      * When <tt>true</tt>, objects will be
      * {*link PoolableObjectFactory#validateObject validated}
@@ -932,7 +859,6 @@
         testPositionSet = true;
     }
 
-
     /**
      * The SQL query that will be used to validate connections from this pool
      * before returning them to the caller.  If specified, this query
@@ -953,8 +879,7 @@
     public void setValidationQuery(String validationQuery) {
         assertInitializationAllowed();
         this.validationQuery = validationQuery;
-        if (!testPositionSet) 
-        {
+        if (!testPositionSet) {
             setTestOnBorrow(true);
         }
     }
@@ -965,54 +890,44 @@
     /**
      * Get the number of active connections in the default pool.
      */
-    public int getNumActive()
-    {
-        return getNumActive( null, null );
+    public int getNumActive() {
+        return getNumActive(null, null);
     }
 
     /**
      * Get the number of active connections in the pool for a given user.
      */
-    public int getNumActive( String username, String password )
-    {
-        PoolKey key = getPoolKey( username );
+    public int getNumActive(String username, String password) {
+        PoolKey key = getPoolKey(username);
 
-        Object pool = ( ( Map ) dsInstanceMap.get( instanceKey ) ).get( key );
+        Object pool = ((Map) dsInstanceMap.get(instanceKey)).get(key);
 
-        if ( pool instanceof ObjectPool )
-        {
-            return ( ( ObjectPool ) pool ).getNumActive();
-        }
-        else
-        {
-            return ( ( KeyedObjectPool ) pool ).getNumActive();
+        if (pool instanceof ObjectPool) {
+            return ((ObjectPool) pool).getNumActive();
+        } else {
+            return ((KeyedObjectPool) pool).getNumActive();
         }
     }
 
     /**
      * Get the number of idle connections in the default pool.
      */
-    public int getNumIdle()
-    {
-        return getNumIdle( null, null );
+    public int getNumIdle() {
+        return getNumIdle(null, null);
     }
 
     /**
      * Get the number of idle connections in the pool for a given user.
      */
-    public int getNumIdle( String username, String password )
-    {
-        PoolKey key = getPoolKey( username );
+    public int getNumIdle(String username, String password) {
+        PoolKey key = getPoolKey(username);
 
-        Object pool = ( ( Map ) dsInstanceMap.get( instanceKey ) ).get( key );
+        Object pool = ((Map) dsInstanceMap.get(instanceKey)).get(key);
 
-        if ( pool instanceof ObjectPool )
-        {
-            return ( ( ObjectPool ) pool ).getNumIdle();
-        }
-        else
-        {
-            return ( ( KeyedObjectPool ) pool ).getNumIdle();
+        if (pool instanceof ObjectPool) {
+            return ((ObjectPool) pool).getNumIdle();
+        } else {
+            return ((KeyedObjectPool) pool).getNumIdle();
         }
     }
 
@@ -1022,103 +937,76 @@
     /**
      * Attempt to establish a database connection.
      */
-    public Connection getConnection() 
-        throws SQLException
-    {
+    public Connection getConnection() throws SQLException {
         return getConnection(null, null);
     }
 
     /**
      * Attempt to establish a database connection.
      */
-    synchronized public Connection getConnection(String username, String password)
-        throws SQLException
-    {
-        if (isNew) 
-        {
-            throw new SQLException("Must set the ConnectionPoolDataSource " + 
-                "through setDataSourceName or setConnectionPoolDataSource " + 
-                "before calling getConnection.");
+    public synchronized Connection getConnection(String username, 
+            String password)
+            throws SQLException {
+        if (isNew) {
+            throw new SQLException("Must set the ConnectionPoolDataSource " 
+                    + "through setDataSourceName or setConnectionPoolDataSource"
+                    + " before calling getConnection.");
         }
 
         getConnectionCalled = true;
-        Map pools = (Map)dsInstanceMap.get(instanceKey);
+        Map pools = (Map) dsInstanceMap.get(instanceKey);
         PoolKey key = getPoolKey(username);
         Object pool = pools.get(key);
-        if ( pool == null ) 
-        {
-            try
-            {
+        if (pool == null) {
+            try {
                 registerPool(username, password);
                 pool = pools.get(key);
-            }
-            catch (Exception e)
-            {
+            } catch (Exception e) {
                 e.printStackTrace();
                 throw new SQLException(e.getMessage());
             }
         }
 
         PooledConnectionAndInfo info = null;        
-        if (pool instanceof ObjectPool) 
-        {
-            try
-            {
+        if (pool instanceof ObjectPool) {
+            try {
                 info = (PooledConnectionAndInfo)
-                    ((ObjectPool)pool).borrowObject();
-            } 
-            catch(NoSuchElementException e) 
-            {
+                    ((ObjectPool) pool).borrowObject();
+            } catch (NoSuchElementException e) {
+                closeDueToException(info);
+                throw new SQLException(e.getMessage());
+            } catch (RuntimeException e) {
+                closeDueToException(info);
+                throw e;
+            } catch (SQLException e) {
+                closeDueToException(info);
+                throw e;
+            } catch (Exception e) {
                 closeDueToException(info);
                 throw new SQLException(e.getMessage());
             }
-            catch(RuntimeException e) 
-            {
-                closeDueToException(info);
-                throw e;
-            }
-            catch(SQLException e) 
-            {
-                closeDueToException(info);
-                throw e;
-            }
-            catch(Exception e) 
-            {
-                closeDueToException(info);
-                throw new SQLException(e.getMessage());
-            }
-        }
-        else // assume KeyedObjectPool
-        { 
-            try
-            {
+        } else {
+            // assume KeyedObjectPool
+            try {
                 UserPassKey upkey = getUserPassKey(username, password);
                 info = (PooledConnectionAndInfo)
-                    ((KeyedObjectPool)pool).borrowObject(upkey);
-            }
-            catch(NoSuchElementException e) 
-            {
+                    ((KeyedObjectPool) pool).borrowObject(upkey);
+            } catch (NoSuchElementException e) {
                 closeDueToException(info);
                 throw new SQLException(e.getMessage());
-            }
-            catch(RuntimeException e) 
-            {
+            } catch (RuntimeException e) {
                 closeDueToException(info);
                 throw e;
-            }
-            catch(SQLException e) 
-            {            
+            } catch (SQLException e) {            
                 closeDueToException(info);
                 throw e;
-            }
-            catch(Exception e) 
-            {
+            } catch (Exception e) {
                 closeDueToException(info);
                 throw new SQLException(e.getMessage());
             }
         }
-        if(!(null == password ? null == info.getPassword() : password.equals(info.getPassword())))
-        {
+        if (!(null == password ? null == info.getPassword() 
+                : password.equals(info.getPassword()))) {
             closeDueToException(info);
             throw new SQLException("Given password did not match password used "
                                    + "to create the PooledConnection.");
@@ -1126,23 +1014,17 @@
         PooledConnection pc = info.getPooledConnection();
 
         boolean defaultAutoCommit = isDefaultAutoCommit();
-        if ( username != null ) 
-        {
-            Boolean userMax = 
-                getPerUserDefaultAutoCommit(username);
-            if ( userMax != null ) 
-            {
+        if (username != null) {
+            Boolean userMax = getPerUserDefaultAutoCommit(username);
+            if (userMax != null) {
                 defaultAutoCommit = userMax.booleanValue();
             }
         }    
 
         boolean defaultReadOnly = isDefaultReadOnly();
-        if ( username != null ) 
-        {
-            Boolean userMax = 
-                getPerUserDefaultReadOnly(username);
-            if ( userMax != null ) 
-            {
+        if (username != null) {
+            Boolean userMax = getPerUserDefaultReadOnly(username);
+            if (userMax != null) {
                 defaultReadOnly = userMax.booleanValue();
             }
         }    
@@ -1153,16 +1035,11 @@
         return con;
     }
         
-    private void closeDueToException(PooledConnectionAndInfo info)
-    {
-        if (info != null) 
-        {
-            try 
-            {
+    private void closeDueToException(PooledConnectionAndInfo info) {
+        if (info != null) {
+            try {
                 info.getPooledConnection().getConnection().close();
-            }
-            catch (Exception e)
-            {
+            } catch (Exception e) {
                 // do not throw this exception because we are in the middle
                 // of handling another exception.  But record it because
                 // it potentially leaks connections from the pool.
@@ -1172,61 +1049,49 @@
         }
     }
 
-    private PoolKey getPoolKey(String username)
-    {
+    private PoolKey getPoolKey(String username) {
         PoolKey key = null;
 
-        if ( username != null && 
-             (perUserMaxActive == null 
-              || !perUserMaxActive.containsKey(username)) ) 
-        {
+        if (username != null && (perUserMaxActive == null 
+                || !perUserMaxActive.containsKey(username))) {
             username = null;
         }
 
         String dsName = getDataSourceName();
-        Map dsMap = (Map)poolKeys.get(dsName);
-        if (dsMap != null) 
-        {
-            key = (PoolKey)dsMap.get(username);
+        Map dsMap = (Map) poolKeys.get(dsName);
+        if (dsMap != null) {
+            key = (PoolKey) dsMap.get(username);
         }
         
-        if (key == null) 
-        {
+        if (key == null) {
             key = new PoolKey(dsName, username);
-            if (dsMap == null) 
-            {
+            if (dsMap == null) {
                 dsMap = new HashMap();
                 poolKeys.put(dsName, dsMap);
             }
             dsMap.put(username, key);
         }
-        
         return key;
     }
 
-    private UserPassKey getUserPassKey(String username, String password)
-    {
-        UserPassKey key = (UserPassKey)userKeys.get(username);
-        if (key == null) 
-        {
+    private UserPassKey getUserPassKey(String username, String password) {
+        UserPassKey key = (UserPassKey) userKeys.get(username);
+        if (key == null) {
             key = new UserPassKey(username, password);
             userKeys.put(username, key);
         }
         return key;
     }
         
-    synchronized private void registerInstance()
-    {
-        if (isNew) 
-        {
+    private synchronized void registerInstance() {
+        if (isNew) {
             int max = 0;
             Iterator i = dsInstanceMap.keySet().iterator();
-            while (i.hasNext()) 
-            {
-                int key = ((Integer)i.next()).intValue();
+            while (i.hasNext()) {
+                int key = ((Integer) i.next()).intValue();
                 max = Math.max(max, key);
             }
-            instanceKey = new Integer(max+1);
+            instanceKey = new Integer(max + 1);
             FastHashMap fhm = new FastHashMap();
             fhm.setFast(true);
             dsInstanceMap.put(instanceKey, fhm);
@@ -1234,50 +1099,40 @@
         }
     }
 
-    synchronized private void registerPool(String username, String password)
-         throws javax.naming.NamingException
-    {
-        Map pools = (Map)dsInstanceMap.get(instanceKey);
+    private synchronized void registerPool(String username, String password) 
+            throws javax.naming.NamingException {
+        Map pools = (Map) dsInstanceMap.get(instanceKey);
         PoolKey key = getPoolKey(username);
-        if ( !pools.containsKey(key) ) 
-        {
+        if (!pools.containsKey(key)) {
             int maxActive = getDefaultMaxActive();
             int maxIdle = getDefaultMaxIdle();
             int maxWait = getDefaultMaxWait();
 
             // The source of physical db connections
             ConnectionPoolDataSource cpds = this.cpds;
-            if ( cpds == null ) 
-            {            
+            if (cpds == null) {            
                 Context ctx = null;
-                if ( jndiEnvironment == null ) 
-                {
+                if (jndiEnvironment == null) {
                     ctx = new InitialContext();                
-                }
-                else 
-                {
+                } else {
                     ctx = new InitialContext(jndiEnvironment);
                 }
-                cpds = (ConnectionPoolDataSource)ctx.lookup(dataSourceName);
+                cpds = (ConnectionPoolDataSource) ctx.lookup(dataSourceName);
             }
 
             Object whicheverPool = null;
             if (perUserMaxActive != null 
-                && perUserMaxActive.containsKey(username)) 
-            {                
+                    && perUserMaxActive.containsKey(username)) {                
                 Integer userMax = getPerUserMaxActive(username);
-                if ( userMax != null ) 
-                {
+                if (userMax != null) {
                     maxActive = userMax.intValue();
                 }
                 userMax = getPerUserMaxIdle(username);
-                if ( userMax != null ) 
-                {
+                if (userMax != null) {
                     maxIdle = userMax.intValue();
                 }
                 userMax = getPerUserMaxWait(username);
-                if ( userMax != null ) 
-                {
+                if (userMax != null) {
                     maxWait = userMax.intValue();
                 }
 
@@ -1287,14 +1142,14 @@
                 pool.setMaxIdle(maxIdle);
                 pool.setMaxWait(maxWait);
                 pool.setWhenExhaustedAction(
-                    getWhenExhausted(maxActive, maxWait));
+                        getWhenExhausted(maxActive, maxWait));
                 pool.setTestOnBorrow(getTestOnBorrow());
                 pool.setTestOnReturn(getTestOnReturn());
                 pool.setTimeBetweenEvictionRunsMillis(
-                    getTimeBetweenEvictionRunsMillis());
+                        getTimeBetweenEvictionRunsMillis());
                 pool.setNumTestsPerEvictionRun(getNumTestsPerEvictionRun());
                 pool.setMinEvictableIdleTimeMillis(
-                    getMinEvictableIdleTimeMillis());
+                        getMinEvictableIdleTimeMillis());
                 pool.setTestWhileIdle(getTestWhileIdle());
                 
                 // Set up the factory we will use (passing the pool associates
@@ -1303,9 +1158,8 @@
                 new CPDSConnectionFactory(cpds, pool, validationQuery,
                                           username, password);
                 whicheverPool = pool;
-            }
-            else // use default pool
-            {
+            } else { 
+                // use default pool
                 // Create an object pool to contain our PooledConnections
                 GenericKeyedObjectPool pool = new GenericKeyedObjectPool(null);
                 pool.setMaxActive(maxActive);
@@ -1328,21 +1182,17 @@
                 new KeyedCPDSConnectionFactory(cpds, pool, validationQuery);
                 whicheverPool = pool;
             }
-            
+           
             // pools is a FastHashMap set to put the pool in a thread-safe way
             pools.put(key, whicheverPool);
         }        
     }
 
-    private byte getWhenExhausted(int maxActive, int maxWait)
-    {
+    private byte getWhenExhausted(int maxActive, int maxWait) {
         byte whenExhausted = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
-        if (maxActive <= 0) 
-        {
+        if (maxActive <= 0) {
             whenExhausted = GenericObjectPool.WHEN_EXHAUSTED_GROW;
-        }
-        else if (maxWait == 0) 
-        {
+        } else if (maxWait == 0) {
             whenExhausted = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
         }
         return whenExhausted;
@@ -1355,17 +1205,14 @@
      * <CODE>Referenceable</CODE> implementation prepares object for
      * binding in jndi.
      */
-    public Reference getReference() 
-        throws NamingException
-    {
+    public Reference getReference() throws NamingException {
         // this class implements its own factory
         String factory = getClass().getName();
         Reference ref = new Reference(getClass().getName(), factory, null);
 
-        ref.add(new StringRefAddr("isNew", 
-                                  String.valueOf(isNew)));
+        ref.add(new StringRefAddr("isNew", String.valueOf(isNew)));
         ref.add(new StringRefAddr("instanceKey", 
-            (instanceKey == null ? null : instanceKey.toString()) ));
+            (instanceKey == null ? null : instanceKey.toString())));
         ref.add(new StringRefAddr("dataSourceName", getDataSourceName()));
         ref.add(new StringRefAddr("defaultAutoCommit", 
                                   String.valueOf(isDefaultAutoCommit())));
@@ -1381,90 +1228,67 @@
 
         byte[] ser = null;
         // BinaryRefAddr does not allow null byte[].
-        if ( jndiEnvironment != null ) 
-        {
-            try
-            {
+        if (jndiEnvironment != null) {
+            try {
                 ser = serialize(jndiEnvironment);
                 ref.add(new BinaryRefAddr("jndiEnvironment", ser));
-            }
-            catch (IOException ioe)
-            {
-                throw new NamingException("An IOException prevented " + 
-                   "serializing the jndiEnvironment properties.");
+            } catch (IOException ioe) {
+                throw new NamingException("An IOException prevented " 
+                        + "serializing the jndiEnvironment properties.");
             }
         }
 
         ref.add(new StringRefAddr("loginTimeout", 
                                   String.valueOf(getLoginTimeout())));
 
-        if ( perUserDefaultAutoCommit != null ) 
-        {
-            try
-            {
-                ser = serialize((Serializable)perUserDefaultAutoCommit);
+        if (perUserDefaultAutoCommit != null) {
+            try {
+                ser = serialize((Serializable) perUserDefaultAutoCommit);
                 ref.add(new BinaryRefAddr("perUserDefaultAutoCommit", ser));
-            }
-            catch (IOException ioe)
-            {
-                throw new NamingException("An IOException prevented " + 
-                   "serializing the perUserDefaultAutoCommit properties.");
+            } catch (IOException ioe) {
+                throw new NamingException("An IOException prevented " 
+                        + "serializing the perUserDefaultAutoCommit "
+                        + "properties.");
             }
         }
 
-        if ( perUserMaxActive != null ) 
-        {
-            try
-            {
-                ser = serialize((Serializable)perUserMaxActive);
+        if (perUserMaxActive != null) {
+            try {
+                ser = serialize((Serializable) perUserMaxActive);
                 ref.add(new BinaryRefAddr("perUserMaxActive", ser));
-            }
-            catch (IOException ioe)
-            {
-                throw new NamingException("An IOException prevented " + 
-                   "serializing the perUserMaxActive properties.");
+            } catch (IOException ioe) {
+                throw new NamingException("An IOException prevented " 
+                        + "serializing the perUserMaxActive properties.");
             }
         }
 
-        if ( perUserMaxIdle != null ) 
-        {
-            try
-            {
-                ser = serialize((Serializable)perUserMaxIdle);
+        if (perUserMaxIdle != null) {
+            try {
+                ser = serialize((Serializable) perUserMaxIdle);
                 ref.add(new BinaryRefAddr("perUserMaxIdle", ser));
-            }
-            catch (IOException ioe)
-            {
-                throw new NamingException("An IOException prevented " + 
-                   "serializing the perUserMaxIdle properties.");
+            } catch (IOException ioe) {
+                throw new NamingException("An IOException prevented " 
+                        + "serializing the perUserMaxIdle properties.");
             }
         }
 
-        if ( perUserMaxWait != null ) 
-        {
-            try
-            {
-                ser = serialize((Serializable)perUserMaxWait);
+        if (perUserMaxWait != null) {
+            try {
+                ser = serialize((Serializable) perUserMaxWait);
                 ref.add(new BinaryRefAddr("perUserMaxWait", ser));
-            }
-            catch (IOException ioe)
-            {
-                throw new NamingException("An IOException prevented " + 
-                   "serializing the perUserMaxWait properties.");
+            } catch (IOException ioe) {
+                throw new NamingException("An IOException prevented " 
+                        + "serializing the perUserMaxWait properties.");
             }
         }
 
-        if ( perUserDefaultReadOnly != null ) 
-        {
-            try
-            {
-                ser = serialize((Serializable)perUserDefaultReadOnly);
+        if (perUserDefaultReadOnly != null) {
+            try {
+                ser = serialize((Serializable) perUserDefaultReadOnly);
                 ref.add(new BinaryRefAddr("perUserDefaultReadOnly", ser));
-            }
-            catch (IOException ioe)
-            {
-                throw new NamingException("An IOException prevented " + 
-                   "serializing the perUserDefaultReadOnly properties.");
+            } catch (IOException ioe) {
+                throw new NamingException("An IOException prevented " 
+                        + "serializing the perUserDefaultReadOnly properties.");
             }
         }
 
@@ -1492,25 +1316,19 @@
      * @return A byte[] with the converted Serializable.
      * @exception IOException, if conversion to a byte[] fails.
      */
-    private static byte[] serialize(Serializable obj)
-        throws IOException
-    {
+    private static byte[] serialize(Serializable obj) throws IOException {
         byte[] byteArray = null;
         ByteArrayOutputStream baos = null;
         ObjectOutputStream out = null;
-        try
-        {
+        try {
             // These objects are closed in the finally.
             baos = new ByteArrayOutputStream();
             out = new ObjectOutputStream(baos);
 
             out.writeObject(obj);
             byteArray = baos.toByteArray();
-        }
-        finally
-        {
-            if (out != null) 
-            {
+        } finally {
+            if (out != null) {
                 out.close();
             }
         }
@@ -1525,184 +1343,151 @@
      * implements ObjectFactory to create an instance of this class
      */ 
     public Object getObjectInstance(Object refObj, Name name, 
-                                    Context context, Hashtable env) 
-        throws Exception 
-    {
+            Context context, Hashtable env) 
+            throws Exception {
         // The spec says to return null if we can't create an instance 
         // of the reference
         Jdbc2PoolDataSource ds = null;
-        if (refObj instanceof Reference) 
-        {
-            Reference ref = (Reference)refObj;
-	
-            if (ref.getClassName().equals(getClass().getName())) 
-            {   
+        if (refObj instanceof Reference) {
+            Reference ref = (Reference) refObj;
+
+            if (ref.getClassName().equals(getClass().getName())) {   
                 RefAddr ra = ref.get("isNew");
-                if (ra != null && ra.getContent() != null) 
-                {
-                    isNew = Boolean.valueOf(ra.getContent().toString()).booleanValue();
+                if (ra != null && ra.getContent() != null) {
+                    isNew = Boolean.valueOf(ra.getContent().toString())
+                            .booleanValue();
                 }
 
                 ra = ref.get("instanceKey");
-                if (ra != null && ra.getContent() != null) 
-                {
+                if (ra != null && ra.getContent() != null) {
                     instanceKey = new Integer(ra.getContent().toString());
                 }
 
                 ra = ref.get("dataSourceName");
-                if (ra != null && ra.getContent() != null) 
-                {
+                if (ra != null && ra.getContent() != null) {
                     setDataSourceName(ra.getContent().toString());
                 }
 
                 ra = ref.get("defaultAutoCommit");
-                if (ra != null && ra.getContent() != null) 
-                {
-                    setDefaultAutoCommit
-                        (Boolean.valueOf(ra.getContent().toString()).booleanValue());
+                if (ra != null && ra.getContent() != null) {
+                    setDefaultAutoCommit(Boolean.valueOf(
+                            ra.getContent().toString()).booleanValue());
                 }
 
                 ra = ref.get("defaultMaxActive");
-                if (ra != null && ra.getContent() != null) 
-                {
+                if (ra != null && ra.getContent() != null) {
                     setDefaultMaxActive(
                         Integer.parseInt(ra.getContent().toString()));
                 }
 
                 ra = ref.get("defaultMaxIdle");
-                if (ra != null && ra.getContent() != null) 
-                {
+                if (ra != null && ra.getContent() != null) {
                     setDefaultMaxIdle(
                         Integer.parseInt(ra.getContent().toString()));
                 }
 
                 ra = ref.get("defaultMaxWait");
-                if (ra != null && ra.getContent() != null) 
-                {
+                if (ra != null && ra.getContent() != null) {
                     setDefaultMaxWait(
                         Integer.parseInt(ra.getContent().toString()));
                 }
 
                 ra = ref.get("defaultReadOnly");
-                if (ra != null && ra.getContent() != null) 
-                {
-                    setDefaultReadOnly
-                        (Boolean.valueOf(ra.getContent().toString()).booleanValue());
+                if (ra != null && ra.getContent() != null) {
+                    setDefaultReadOnly(Boolean.valueOf(
+                            ra.getContent().toString()).booleanValue());
                 }
 
                 ra = ref.get("description");
-                if (ra != null && ra.getContent() != null) 
-                {
+                if (ra != null && ra.getContent() != null) {
                     setDescription(ra.getContent().toString());
                 }
 
                 ra = ref.get("jndiEnvironment");
-                if (ra != null  && ra.getContent() != null) 
-                {
-                    byte[] serialized = (byte[])ra.getContent();
-                    jndiEnvironment = 
-                        (Properties)deserialize(serialized);
+                if (ra != null  && ra.getContent() != null) {
+                    byte[] serialized = (byte[]) ra.getContent();
+                    jndiEnvironment = (Properties) deserialize(serialized);
                 }
                 
                 ra = ref.get("loginTimeout");
-                if (ra != null && ra.getContent() != null) 
-                {
+                if (ra != null && ra.getContent() != null) {
                     setLoginTimeout(
-                        Integer.parseInt(ra.getContent().toString()));
+                            Integer.parseInt(ra.getContent().toString()));
                 }
 
                 ra = ref.get("perUserDefaultAutoCommit");
-                if (ra != null  && ra.getContent() != null) 
-                {
-                    byte[] serialized = (byte[])ra.getContent();
-                    perUserDefaultAutoCommit = 
-                        (Map)deserialize(serialized);
+                if (ra != null  && ra.getContent() != null) {
+                    byte[] serialized = (byte[]) ra.getContent();
+                    perUserDefaultAutoCommit = (Map) deserialize(serialized);
                 }
                 
                 ra = ref.get("perUserMaxActive");
-                if (ra != null  && ra.getContent() != null) 
-                {
-                    byte[] serialized = (byte[])ra.getContent();
-                    perUserMaxActive = 
-                        (Map)deserialize(serialized);
+                if (ra != null  && ra.getContent() != null) {
+                    byte[] serialized = (byte[]) ra.getContent();
+                    perUserMaxActive = (Map) deserialize(serialized);
                 }
 
                 ra = ref.get("perUserMaxIdle");
-                if (ra != null  && ra.getContent() != null) 
-                {
-                    byte[] serialized = (byte[])ra.getContent();
-                    perUserMaxIdle = 
-                        (Map)deserialize(serialized);
+                if (ra != null  && ra.getContent() != null) {
+                    byte[] serialized = (byte[]) ra.getContent();
+                    perUserMaxIdle = (Map) deserialize(serialized);
                 }
 
                 ra = ref.get("perUserMaxWait");
-                if (ra != null  && ra.getContent() != null) 
-                {
-                    byte[] serialized = (byte[])ra.getContent();
-                    perUserMaxWait = 
-                        (Map)deserialize(serialized);
+                if (ra != null  && ra.getContent() != null) {
+                    byte[] serialized = (byte[]) ra.getContent();
+                    perUserMaxWait = (Map) deserialize(serialized);
                 }
                 
                 ra = ref.get("perUserDefaultReadOnly");
-                if (ra != null  && ra.getContent() != null) 
-                {
-                    byte[] serialized = (byte[])ra.getContent();
-                    perUserDefaultReadOnly = 
-                        (Map)deserialize(serialized);
+                if (ra != null  && ra.getContent() != null) {
+                    byte[] serialized = (byte[]) ra.getContent();
+                    perUserDefaultReadOnly = (Map) deserialize(serialized);
                 }
                 
                 ra = ref.get("testOnBorrow");
-                if (ra != null && ra.getContent() != null) 
-                {
-                    setTestOnBorrow
-                        (Boolean.valueOf(ra.getContent().toString()).booleanValue());
+                if (ra != null && ra.getContent() != null) {
+                    setTestOnBorrow(Boolean.valueOf(ra.getContent().toString())
+                            .booleanValue());
                 }
 
                 ra = ref.get("testOnReturn");
-                if (ra != null && ra.getContent() != null) 
-                {
-                    setTestOnReturn
-                        (Boolean.valueOf(ra.getContent().toString()).booleanValue());
+                if (ra != null && ra.getContent() != null) {
+                    setTestOnReturn(Boolean.valueOf(ra.getContent().toString())
+                            .booleanValue());
                 }
 
                 ra = ref.get("timeBetweenEvictionRunsMillis");
-                if (ra != null && ra.getContent() != null) 
-                {
+                if (ra != null && ra.getContent() != null) {
                     setTimeBetweenEvictionRunsMillis(
                         Integer.parseInt(ra.getContent().toString()));
                 }
 
                 ra = ref.get("numTestsPerEvictionRun");
-                if (ra != null && ra.getContent() != null) 
-                {
+                if (ra != null && ra.getContent() != null) {
                     setNumTestsPerEvictionRun(
                         Integer.parseInt(ra.getContent().toString()));
                 }
 
                 ra = ref.get("minEvictableIdleTimeMillis");
-                if (ra != null && ra.getContent() != null) 
-                {
+                if (ra != null && ra.getContent() != null) {
                     setMinEvictableIdleTimeMillis(
                         Integer.parseInt(ra.getContent().toString()));
                 }
 
                 ra = ref.get("testWhileIdle");
-                if (ra != null && ra.getContent() != null) 
-                {
-                    setTestWhileIdle
-                        (Boolean.valueOf(ra.getContent().toString()).booleanValue());
+                if (ra != null && ra.getContent() != null) {
+                    setTestWhileIdle(Boolean.valueOf(ra.getContent().toString())
+                            .booleanValue());
                 }
                 
                 ra = ref.get("validationQuery");
-                if (ra != null && ra.getContent() != null) 
-                {
+                if (ra != null && ra.getContent() != null) {
                     setValidationQuery(ra.getContent().toString());
                 }
-
                 ds = this;
             }            
         }
-        
         return ds;
     }
 
@@ -1712,8 +1497,10 @@
             in = new ObjectInputStream(new ByteArrayInputStream(data));
             return in.readObject();
         } finally {
-            try { in.close(); } catch (IOException ex) {}
+            try { 
+                in.close(); 
+            } catch (IOException ex) {
+            }
         }
     }
-
 }
diff --git a/src/java/org/apache/commons/dbcp/jdbc2pool/KeyedCPDSConnectionFactory.java b/src/java/org/apache/commons/dbcp/jdbc2pool/KeyedCPDSConnectionFactory.java
index 3bb6272..442ab48 100644
--- a/src/java/org/apache/commons/dbcp/jdbc2pool/KeyedCPDSConnectionFactory.java
+++ b/src/java/org/apache/commons/dbcp/jdbc2pool/KeyedCPDSConnectionFactory.java
@@ -1,7 +1,7 @@
 /*
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//dbcp/src/java/org/apache/commons/dbcp/jdbc2pool/Attic/KeyedCPDSConnectionFactory.java,v 1.6 2003/04/09 00:33:36 dgraham Exp $
- * $Revision: 1.6 $
- * $Date: 2003/04/09 00:33:36 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//dbcp/src/java/org/apache/commons/dbcp/jdbc2pool/Attic/KeyedCPDSConnectionFactory.java,v 1.7 2003/06/29 12:42:16 mpoeschl Exp $
+ * $Revision: 1.7 $
+ * $Date: 2003/06/29 12:42:16 $
  *
  * ====================================================================
  *
@@ -82,10 +82,21 @@
  * {*link PoolableConnection}s.
  *
  * @author <a href="mailto:jmcnally@collab.net">John D. McNally</a>
- * @version $Id: KeyedCPDSConnectionFactory.java,v 1.6 2003/04/09 00:33:36 dgraham Exp $
+ * @version $Id: KeyedCPDSConnectionFactory.java,v 1.7 2003/06/29 12:42:16 mpoeschl Exp $
  */
 class KeyedCPDSConnectionFactory 
     implements KeyedPoolableObjectFactory, ConnectionEventListener {
+
+    private static final String NO_KEY_MESSAGE 
+            = "close() was called on a Connection, but " 
+            + "I have no record of the underlying PooledConnection.";
+
+    protected ConnectionPoolDataSource _cpds = null;
+    protected String _validationQuery = null;
+    protected KeyedObjectPool _pool = null;
+    private Map validatingMap = new HashMap();
+    private WeakHashMap pcMap = new WeakHashMap();
+
     /**
      * Create a new <tt>KeyedPoolableConnectionFactory</tt>.
      * @param cpds the ConnectionPoolDataSource from which to obtain PooledConnection's
@@ -124,21 +135,14 @@
      * @param pool the {*link ObjectPool} in which to pool those {*link Connection}s
      */
     synchronized public void setPool(KeyedObjectPool pool) 
-        throws SQLException
-    {
-        if(null != _pool && pool != _pool) {
-            try
-            {
+        throws SQLException {
+        if (null != _pool && pool != _pool) {
+            try {
                 _pool.close();
-            }
-            catch (Exception e)
-            {
-                if (e instanceof RuntimeException) 
-                {
+            } catch (Exception e) {
+                if (e instanceof RuntimeException) {
                     throw (RuntimeException)e;
-                }
-                else 
-                {
+                } else {
                     throw new SQLException(e.getMessage());
                 }
             }
@@ -162,12 +166,9 @@
         PooledConnection pc = null;
         String username = upkey.getUsername();
         String password = upkey.getPassword();
-        if ( username == null ) 
-        {
+        if (username == null) {
             pc = _cpds.getPooledConnection();
-        }
-        else 
-        {
+        } else {
             pc = _cpds.getPooledConnection(username, password);
         }
         // should we add this object as a listener or the pool.
@@ -180,18 +181,18 @@
     }
 
     public void destroyObject(Object key, Object obj) throws Exception {
-        if(obj instanceof PooledConnectionAndInfo) {
+        if (obj instanceof PooledConnectionAndInfo) {
             ((PooledConnectionAndInfo)obj).getPooledConnection().close();
         }
     }
 
     public boolean validateObject(Object key, Object obj) {
         boolean valid = false;
-        if(obj instanceof PooledConnectionAndInfo) {
+        if (obj instanceof PooledConnectionAndInfo) {
             PooledConnection pconn = 
                 ((PooledConnectionAndInfo)obj).getPooledConnection();
             String query = _validationQuery;
-            if(null != query) {
+            if (null != query) {
                 Connection conn = null;
                 Statement stmt = null;
                 ResultSet rset = null;
@@ -204,29 +205,27 @@
                     conn = pconn.getConnection();
                     stmt = conn.createStatement();
                     rset = stmt.executeQuery(query);
-                    if(rset.next()) {
+                    if (rset.next()) {
                         valid = true;
                     } else {
                         valid = false;
                     }
                 } catch(Exception e) {
                     valid = false;
-                }
-                finally 
-                {
+                } finally {
                     try {
                         rset.close();
-                    } catch(Throwable t) {
+                    } catch (Throwable t) {
                         // ignore
                     }
                     try {
                         stmt.close();
-                    } catch(Throwable t) {
+                    } catch (Throwable t) {
                         // ignore
                     }
                     try {
                         conn.close();
-                    } catch(Throwable t) {
+                    } catch (Throwable t) {
                         // ignore
                     }
                     validatingMap.remove(pconn);
@@ -256,30 +255,24 @@
      * method of this connection object. What we need to do here is to
      * release this PooledConnection from our pool...
      */
-    public void connectionClosed(ConnectionEvent event) 
-    {
+    public void connectionClosed(ConnectionEvent event) {
         PooledConnection pc = (PooledConnection)event.getSource();
         // if this event occured becase we were validating, ignore it
         // otherwise return the connection to the pool.
-        if (!validatingMap.containsKey(pc)) 
-        {
+        if (!validatingMap.containsKey(pc)) {
             PooledConnectionAndInfo info = 
-                (PooledConnectionAndInfo)pcMap.get(pc);
-            if (info == null) 
-            {
+                (PooledConnectionAndInfo) pcMap.get(pc);
+            if (info == null) {
                 throw new IllegalStateException(NO_KEY_MESSAGE);
             }            
-            try
-            {
+            try {
                 _pool.returnObject(info.getUserPassKey(), info);
-            }
-            catch (Exception e)
-            {
+            } catch (Exception e) {
                 System.err.println("CLOSING DOWN CONNECTION AS IT COULD " + 
                                    "NOT BE RETURNED TO THE POOL");
                 try {
                     destroyObject(info.getUserPassKey(), info);
-                } catch(Exception e2) {
+                } catch (Exception e2) {
                     System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + 
                                        info);
                     e2.printStackTrace();
@@ -292,12 +285,10 @@
      * If a fatal error occurs, close the underlying physical connection so as
      * not to be returned in the future
      */
-    public void connectionErrorOccurred(ConnectionEvent event) 
-    {
+    public void connectionErrorOccurred(ConnectionEvent event) {
         PooledConnection pc = (PooledConnection)event.getSource();
-        try 
-        {
-            if(null != event.getSQLException()) {
+        try {
+            if (null != event.getSQLException()) {
                 System.err
                     .println("CLOSING DOWN CONNECTION DUE TO INTERNAL ERROR (" +
                              event.getSQLException() + ")");
@@ -305,33 +296,19 @@
             //remove this from the listener list because we are no more 
             //interested in errors since we are about to close this connection
             pc.removeConnectionEventListener(this);
-        }
-        catch (Exception ignore) 
-        {
+        } catch (Exception ignore) {
             // ignore
         }
 
-        PooledConnectionAndInfo info = (PooledConnectionAndInfo)pcMap.get(pc);
-        if (info == null) 
-        {
+        PooledConnectionAndInfo info = (PooledConnectionAndInfo) pcMap.get(pc);
+        if (info == null) {
             throw new IllegalStateException(NO_KEY_MESSAGE);
         }            
         try {
             destroyObject(info.getUserPassKey(), info);
-        } catch(Exception e) {
-            System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + 
-                               info);
+        } catch (Exception e) {
+            System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + info);
             e.printStackTrace();
         }
     }
-
-    private static final String NO_KEY_MESSAGE = 
-        "close() was called on a Connection, but " + 
-        "I have no record of the underlying PooledConnection.";
-
-    protected ConnectionPoolDataSource _cpds = null;
-    protected String _validationQuery = null;
-    protected KeyedObjectPool _pool = null;
-    private Map validatingMap = new HashMap();
-    private WeakHashMap pcMap = new WeakHashMap();
 }
diff --git a/src/java/org/apache/commons/dbcp/jdbc2pool/PoolKey.java b/src/java/org/apache/commons/dbcp/jdbc2pool/PoolKey.java
index 4581288..be41f6c 100644
--- a/src/java/org/apache/commons/dbcp/jdbc2pool/PoolKey.java
+++ b/src/java/org/apache/commons/dbcp/jdbc2pool/PoolKey.java
@@ -1,7 +1,7 @@
 /* 
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//dbcp/src/java/org/apache/commons/dbcp/jdbc2pool/Attic/PoolKey.java,v 1.4 2003/04/15 01:35:55 dgraham Exp $
- * $Revision: 1.4 $
- * $Date: 2003/04/15 01:35:55 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//dbcp/src/java/org/apache/commons/dbcp/jdbc2pool/Attic/PoolKey.java,v 1.5 2003/06/29 12:42:16 mpoeschl Exp $
+ * $Revision: 1.5 $
+ * $Date: 2003/06/29 12:42:16 $
  * 
  * ====================================================================
  * 
@@ -62,47 +62,37 @@
  
 import java.io.Serializable;
 
-class PoolKey implements Serializable
-{
+class PoolKey implements Serializable {
     private String datasourceName;
     private String username;
     
-    PoolKey(String datasourceName, String username)
-    {
+    PoolKey(String datasourceName, String username) {
         this.datasourceName = datasourceName;
         this.username = username;
     }
     
-    public boolean equals(Object obj)
-    {
-        if ( obj instanceof PoolKey ) 
-        {
+    public boolean equals(Object obj) {
+        if (obj instanceof PoolKey) {
             PoolKey pk = (PoolKey)obj;
             return (null == datasourceName ? null == pk.datasourceName : datasourceName.equals(pk.datasourceName)) &&
                 (null == username ? null == pk.username : username.equals(pk.username));
-        } 
-        else
-        {
+        } else {
             return false;   
         }
     }
 
-    public int hashCode()
-    {
+    public int hashCode() {
         int h = 0;
-        if (datasourceName != null) 
-        {
+        if (datasourceName != null) {
             h += datasourceName.hashCode();
         }
-        if (username != null) 
-        {
+        if (username != null) {
             h = 29 * h + username.hashCode();
         }
         return h;
     }
 
-    public String toString()
-    {
+    public String toString() {
         StringBuffer sb = new StringBuffer(50);
         sb.append("PoolKey(");
         sb.append(username).append(", ").append(datasourceName);
diff --git a/src/java/org/apache/commons/dbcp/jdbc2pool/PooledConnectionAndInfo.java b/src/java/org/apache/commons/dbcp/jdbc2pool/PooledConnectionAndInfo.java
index 79ab926..d21b6e3 100644
--- a/src/java/org/apache/commons/dbcp/jdbc2pool/PooledConnectionAndInfo.java
+++ b/src/java/org/apache/commons/dbcp/jdbc2pool/PooledConnectionAndInfo.java
@@ -1,7 +1,7 @@
 /* 
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//dbcp/src/java/org/apache/commons/dbcp/jdbc2pool/Attic/PooledConnectionAndInfo.java,v 1.2 2003/04/15 01:35:55 dgraham Exp $
- * $Revision: 1.2 $
- * $Date: 2003/04/15 01:35:55 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//dbcp/src/java/org/apache/commons/dbcp/jdbc2pool/Attic/PooledConnectionAndInfo.java,v 1.3 2003/06/29 12:42:16 mpoeschl Exp $
+ * $Revision: 1.3 $
+ * $Date: 2003/06/29 12:42:16 $
  * 
  * ====================================================================
  * 
@@ -62,29 +62,25 @@
 
 import javax.sql.PooledConnection;
 
-final class PooledConnectionAndInfo
-{
+final class PooledConnectionAndInfo {
     private final PooledConnection pooledConnection;
     private final String password;
     private final String username;
     private final UserPassKey upkey;
 
     PooledConnectionAndInfo(PooledConnection pc, 
-                            String username, String password)
-    {
+                            String username, String password) {
         this.pooledConnection = pc;
         this.username = username;
         this.password = password;
         upkey = new UserPassKey(username, password);
     }
 
-    final PooledConnection getPooledConnection()
-    {
+    final PooledConnection getPooledConnection() {
         return pooledConnection;
     }
 
-    final UserPassKey getUserPassKey()
-    {
+    final UserPassKey getUserPassKey() {
         return upkey;
     }
 
@@ -92,8 +88,7 @@
      * Get the value of password.
      * @return value of password.
      */
-    final String getPassword() 
-    {
+    final String getPassword() {
         return password;
     }
     
@@ -101,8 +96,7 @@
      * Get the value of username.
      * @return value of username.
      */
-    final String getUsername() 
-    {
+    final String getUsername() {
         return username;
     }
 }
diff --git a/src/java/org/apache/commons/dbcp/jdbc2pool/UserPassKey.java b/src/java/org/apache/commons/dbcp/jdbc2pool/UserPassKey.java
index 8b9a386..39809ea 100644
--- a/src/java/org/apache/commons/dbcp/jdbc2pool/UserPassKey.java
+++ b/src/java/org/apache/commons/dbcp/jdbc2pool/UserPassKey.java
@@ -1,7 +1,7 @@
 /* 
- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//dbcp/src/java/org/apache/commons/dbcp/jdbc2pool/Attic/UserPassKey.java,v 1.4 2003/04/15 01:32:42 dgraham Exp $
- * $Revision: 1.4 $
- * $Date: 2003/04/15 01:32:42 $
+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//dbcp/src/java/org/apache/commons/dbcp/jdbc2pool/Attic/UserPassKey.java,v 1.5 2003/06/29 12:42:16 mpoeschl Exp $
+ * $Revision: 1.5 $
+ * $Date: 2003/06/29 12:42:16 $
  * 
  * ====================================================================
  * 
@@ -65,13 +65,11 @@
 /**
  * Holds a username, password pair.
  */
-class UserPassKey implements Serializable
-{
+class UserPassKey implements Serializable {
     private String password;
     private String username;
     
-    UserPassKey(String username, String password)
-    {
+    UserPassKey(String username, String password) {
         this.username = username;
         this.password = password;
     }
@@ -80,8 +78,7 @@
      * Get the value of password.
      * @return value of password.
      */
-    public String getPassword() 
-    {
+    public String getPassword() {
         return password;
     }
     
@@ -89,8 +86,7 @@
      * Get the value of username.
      * @return value of username.
      */
-    public String getUsername() 
-    {
+    public String getUsername() {
         return username;
     }
     
@@ -99,16 +95,18 @@
      * objects are equal.
      * @see java.lang.Object#equals(java.lang.Object)
      */
-    public boolean equals(Object obj)
-    {
-        if (obj == null)
+    public boolean equals(Object obj) {
+        if (obj == null) {
             return false;
+        }
 
-        if (obj == this)
+        if (obj == this) {
             return true;
+        }
         
-        if (!(obj instanceof UserPassKey))
+        if (!(obj instanceof UserPassKey)) {
             return false;
+        }
         
         UserPassKey key = (UserPassKey) obj;
         
@@ -125,13 +123,11 @@
         return (usersEqual && passwordsEqual);
     }
 
-    public int hashCode()
-    {
+    public int hashCode() {
         return (this.username != null ? this.username.hashCode() : 0);
     }
 
-    public String toString()
-    {
+    public String toString() {
         StringBuffer sb = new StringBuffer(50);
         sb.append("UserPassKey(");
         sb.append(username).append(", ").append(password).append(')');