rwaldhoff    2002/11/01 07:27:21

  Modified:    dbcp/src/java/org/apache/commons/dbcp
                        PoolableConnection.java
               dbcp/src/test/org/apache/commons/dbcp TestManual.java
  Log:
  fix bug #12409 (http://nagaoya.apache.org/bugzilla/show_bug.cgi?id=12409), ensuring 
a connection can only be closed once
  
  Revision  Changes    Path
  1.5       +16 -12    
jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/PoolableConnection.java
  
  Index: PoolableConnection.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/dbcp/src/java/org/apache/commons/dbcp/PoolableConnection.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PoolableConnection.java   28 Jun 2002 15:28:20 -0000      1.4
  +++ PoolableConnection.java   1 Nov 2002 15:27:21 -0000       1.5
  @@ -106,14 +106,18 @@
        * Returns me to my pool.
        */
       public void close() throws SQLException {
  -        try {
  -            _pool.returnObject(this);
  -        } catch(SQLException e) {
  -            throw e;
  -        } catch(RuntimeException e) {
  -            throw e;
  -        } catch(Exception e) {
  -            throw new SQLException(e.toString());
  +        if(isClosed()) {
  +            throw new SQLException("Already closed.");
  +        } else {
  +            try {
  +                _pool.returnObject(this);
  +            } catch(SQLException e) {
  +                throw e;
  +            } catch(RuntimeException e) {
  +                throw e;
  +            } catch(Exception e) {
  +                throw new SQLException(e.toString());
  +            }
           }
       }
   
  
  
  
  1.9       +21 -4     
jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/TestManual.java
  
  Index: TestManual.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/dbcp/src/test/org/apache/commons/dbcp/TestManual.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TestManual.java   19 Oct 2002 19:21:51 -0000      1.8
  +++ TestManual.java   1 Nov 2002 15:27:21 -0000       1.9
  @@ -114,6 +114,23 @@
           }
       }
   
  +    public void testCantCloseTwice() throws Exception {
  +        for(int i=0;i<2;i++) { // loop to show we *can* close again once we've 
borrowed it from the pool again
  +            Connection conn = 
DriverManager.getConnection("jdbc:apache:commons:dbcp:test");
  +            assertTrue(null != conn);
  +            assertTrue(!conn.isClosed());
  +            conn.close();
  +            assertTrue(conn.isClosed());
  +            try {
  +                conn.close();
  +                fail("Expected SQLException on second attempt to close");
  +            } catch(SQLException e) {
  +                // expected
  +            }
  +            assertTrue(conn.isClosed());
  +        }
  +    }
  +
       public void testSimple() throws Exception {
           Connection conn = 
DriverManager.getConnection("jdbc:apache:commons:dbcp:test");
           assertTrue(null != conn);
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@;jakarta.apache.org>

Reply via email to