You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rw...@apache.org on 2002/11/08 20:17:25 UTC

cvs commit: jakarta-commons/dbcp/src/test/org/apache/commons/dbcp TestBasicDataSource.java TestAll.java TestConnectionPool.java

rwaldhoff    2002/11/08 11:17:24

  Modified:    dbcp/src/java/org/apache/commons/dbcp PoolingDataSource.java
                        PoolingDriver.java
               dbcp/src/java/org/apache/commons/dbcp/jdbc2pool
                        Jdbc2PoolDataSource.java
               dbcp/src/test/org/apache/commons/dbcp TestAll.java
                        TestConnectionPool.java
  Added:       dbcp/src/test/org/apache/commons/dbcp
                        TestBasicDataSource.java
  Log:
  add TestBasicDataSource
  ensure we throw SQLException when the pool is exhausted, rather than NoSuchElement
  
  Revision  Changes    Path
  1.4       +11 -11    jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/PoolingDataSource.java
  
  Index: PoolingDataSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/PoolingDataSource.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PoolingDataSource.java	16 May 2002 21:25:38 -0000	1.3
  +++ PoolingDataSource.java	8 Nov 2002 19:17:23 -0000	1.4
  @@ -61,16 +61,14 @@
   
   package org.apache.commons.dbcp;
   
  -import org.apache.commons.pool.ObjectPool;
  -import java.util.Properties;
  +import java.io.PrintWriter;
   import java.sql.Connection;
  -import java.sql.Driver;
  -import java.sql.Statement;
  -import java.sql.ResultSet;
   import java.sql.SQLException;
  -import java.io.PrintWriter;
  +import java.util.NoSuchElementException;
  +
   import javax.sql.DataSource;
  -import java.util.Enumeration;
  +
  +import org.apache.commons.pool.ObjectPool;
   
   /**
    * A simple {@link DataSource} implementation that obtains
  @@ -110,6 +108,8 @@
               return (Connection)(_pool.borrowObject());
           } catch(SQLException e) {
               throw e;
  +        } catch(NoSuchElementException e) {
  +            throw new SQLException(e.toString());
           } catch(RuntimeException e) {
               throw e;
           } catch(Exception e) {
  
  
  
  1.4       +13 -10    jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/PoolingDriver.java
  
  Index: PoolingDriver.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/PoolingDriver.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PoolingDriver.java	20 Jul 2002 22:55:34 -0000	1.3
  +++ PoolingDriver.java	8 Nov 2002 19:17:23 -0000	1.4
  @@ -61,17 +61,18 @@
   
   package org.apache.commons.dbcp;
   
  -import org.apache.commons.pool.ObjectPool;
  -import org.apache.commons.jocl.JOCLContentHandler;
  +import java.io.InputStream;
  +import java.sql.Connection;
   import java.sql.Driver;
   import java.sql.DriverManager;
   import java.sql.DriverPropertyInfo;
  -import java.sql.Connection;
   import java.sql.SQLException;
  -import java.util.Properties;
   import java.util.HashMap;
  -import java.util.Enumeration;
  -import java.io.InputStream;
  +import java.util.NoSuchElementException;
  +import java.util.Properties;
  +
  +import org.apache.commons.jocl.JOCLContentHandler;
  +import org.apache.commons.pool.ObjectPool;
   
   
   /**
  @@ -146,6 +147,8 @@
                       return (Connection)(pool.borrowObject());
                   } catch(SQLException e) {
                       throw e;
  +                } catch(NoSuchElementException e) {
  +                    throw new SQLException(e.toString());
                   } catch(RuntimeException e) {
                       throw e;
                   } catch(Exception e) {
  
  
  
  1.6       +48 -37    jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/jdbc2pool/Jdbc2PoolDataSource.java
  
  Index: Jdbc2PoolDataSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/jdbc2pool/Jdbc2PoolDataSource.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Jdbc2PoolDataSource.java	7 Nov 2002 21:31:19 -0000	1.5
  +++ Jdbc2PoolDataSource.java	8 Nov 2002 19:17:24 -0000	1.6
  @@ -54,39 +54,40 @@
    * <http://www.apache.org/>.
    */
    
  +import java.io.ByteArrayOutputStream;
  +import java.io.IOException;
  +import java.io.ObjectOutputStream;
  +import java.io.PrintWriter;
  +import java.io.Serializable;
  +import java.sql.Connection;
  +import java.sql.SQLException;
   import java.util.HashMap;
  +import java.util.Hashtable;
   import java.util.Iterator;
   import java.util.Map;
  +import java.util.NoSuchElementException;
   import java.util.Properties;
   
  -import java.util.Hashtable;
  -import java.io.PrintWriter;
  -import java.io.Serializable;
  -import java.io.ByteArrayOutputStream;
  -import java.io.ObjectOutputStream;
  -import java.io.IOException;
  -import java.sql.Connection;
  -import java.sql.SQLException;
  -import javax.sql.DataSource;
  -import javax.sql.ConnectionPoolDataSource;
  -import javax.sql.PooledConnection;
  -import javax.naming.Name;
  +import javax.naming.BinaryRefAddr;
   import javax.naming.Context;
   import javax.naming.InitialContext;
  -import javax.naming.Referenceable;
  -import javax.naming.Reference;
  +import javax.naming.Name;
  +import javax.naming.NamingException;
   import javax.naming.RefAddr;
  -import javax.naming.BinaryRefAddr;
  +import javax.naming.Reference;
  +import javax.naming.Referenceable;
   import javax.naming.StringRefAddr;
  -import javax.naming.NamingException;
   import javax.naming.spi.ObjectFactory;
  +import javax.sql.ConnectionPoolDataSource;
  +import javax.sql.DataSource;
  +import javax.sql.PooledConnection;
   
   import org.apache.commons.collections.FastHashMap;
   import org.apache.commons.lang.SerializationUtils;
  -import org.apache.commons.pool.ObjectPool;
  -import org.apache.commons.pool.impl.GenericObjectPool;
   import org.apache.commons.pool.KeyedObjectPool;
  +import org.apache.commons.pool.ObjectPool;
   import org.apache.commons.pool.impl.GenericKeyedObjectPool;
  +import org.apache.commons.pool.impl.GenericObjectPool;
   import org.apache.commons.pool.impl.StackObjectPool;
   
   /**
  @@ -1066,17 +1067,22 @@
               try
               {
                   pc = (PooledConnection)((ObjectPool)pool).borrowObject();
  +            } 
  +            catch(NoSuchElementException e) 
  +            {
  +                throw new SQLException(e.getMessage());
               }
  -            catch (Exception e)
  +            catch(RuntimeException e) 
               {
  -                if (e instanceof RuntimeException) 
  -                {
  -                    throw (RuntimeException)e;
  -                }
  -                else 
  -                {
  -                    throw new SQLException(e.getMessage());
  -                }
  +                throw e;
  +            }
  +            catch(SQLException e) 
  +            {
  +                throw e;
  +            }
  +            catch(Exception e) 
  +            {
  +                throw new SQLException(e.getMessage());
               }
           }
           else // assume KeyedObjectPool
  @@ -1088,16 +1094,21 @@
                       ((KeyedObjectPool)pool).borrowObject(upkey);
                   returnPCKey(upkey);
               }
  -            catch (Exception e)
  +            catch(NoSuchElementException e) 
               {
  -                if (e instanceof RuntimeException) 
  -                {
  -                    throw (RuntimeException)e;
  -                }
  -                else 
  -                {
  -                    throw new SQLException(e.getMessage());
  -                }
  +                throw new SQLException(e.getMessage());
  +            }
  +            catch(RuntimeException e) 
  +            {
  +                throw e;
  +            }
  +            catch(SQLException e) 
  +            {
  +                throw e;
  +            }
  +            catch(Exception e) 
  +            {
  +                throw new SQLException(e.getMessage());
               }
           }
           
  
  
  
  1.5       +5 -4      jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/TestAll.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestAll.java	8 Nov 2002 18:51:07 -0000	1.4
  +++ TestAll.java	8 Nov 2002 19:17:24 -0000	1.5
  @@ -77,6 +77,7 @@
           TestSuite suite = new TestSuite();
           suite.addTest(TestManual.suite());
           suite.addTest(TestJOCLed.suite());
  +        suite.addTest(TestBasicDataSource.suite());
           suite.addTest(TestDelegatingStatement.suite());
           suite.addTest(TestDelegatingPreparedStatement.suite());
           suite.addTest(TestJdbc2PoolDataSource.suite());
  
  
  
  1.2       +5 -5      jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/TestConnectionPool.java
  
  Index: TestConnectionPool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/TestConnectionPool.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestConnectionPool.java	8 Nov 2002 18:51:07 -0000	1.1
  +++ TestConnectionPool.java	8 Nov 2002 19:17:24 -0000	1.2
  @@ -332,7 +332,7 @@
           try {
               getConnection();
               fail("Allowed to open more than DefaultMaxActive connections.");
  -        } catch (java.util.NoSuchElementException e) {
  +        } catch (java.sql.SQLException e) {
               // should only be able to open 10 connections, so this test should
               // throw an exception
           }
  
  
  
  1.1                  jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/TestBasicDataSource.java
  
  Index: TestBasicDataSource.java
  ===================================================================
  /*
   * $Id: TestBasicDataSource.java,v 1.1 2002/11/08 19:17:24 rwaldhoff Exp $
   * $Revision: 1.1 $
   * $Date: 2002/11/08 19:17:24 $
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.commons.dbcp;
  
  import java.sql.Connection;
  import java.sql.DriverManager;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import org.apache.commons.pool.ObjectPool;
  import org.apache.commons.pool.impl.GenericKeyedObjectPool;
  import org.apache.commons.pool.impl.GenericKeyedObjectPoolFactory;
  import org.apache.commons.pool.impl.GenericObjectPool;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2002/11/08 19:17:24 $
   */
  public class TestBasicDataSource extends TestConnectionPool {
      public TestBasicDataSource(String testName) {
          super(testName);
      }
  
      public static Test suite() {
          return new TestSuite(TestBasicDataSource.class);
      }
  
      protected Connection getConnection() throws Exception {
          return ds.getConnection();
      }
  
      private BasicDataSource ds = null;
      
      public void setUp() throws Exception {
          super.setUp();
          ds = new BasicDataSource();
          ds.setDriverClassName("org.apache.commons.dbcp.TesterDriver");
          ds.setUrl("jdbc:apache:commons:testdriver");
          ds.setMaxActive(getMaxActive());
          ds.setMaxWait(getMaxWait());
          ds.setDefaultAutoCommit(true);
          ds.setDefaultReadOnly(false);
          ds.setUsername("username");
          ds.setPassword("password");
          ds.setValidationQuery("SELECT DUMMY FROM DUAL");
      }
  
      public void tearDown() throws Exception {
          ds = null;
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>