1 16 17 package org.apache.commons.dbcp; 18 19 import java.sql.Connection ; 20 import java.sql.SQLException ; 21 import org.apache.commons.pool.ObjectPool; 22 23 33 public class PoolableConnection extends DelegatingConnection { 34 35 protected ObjectPool _pool = null; 36 37 42 public PoolableConnection(Connection conn, ObjectPool pool) { 43 super(conn); 44 _pool = pool; 45 } 46 47 54 public PoolableConnection(Connection conn, ObjectPool pool, 55 AbandonedConfig config) { 56 super(conn, config); 57 _pool = pool; 58 } 59 60 61 64 public synchronized void close() throws SQLException { 65 boolean isClosed = false; 66 try { 67 isClosed = isClosed(); 68 } catch (SQLException e) { 69 try { 70 _pool.invalidateObject(this); 71 } catch (Exception ie) { 72 } 74 throw new SQLNestedException("Cannot close connection (isClosed check failed)", e); 75 } 76 if (isClosed) { 77 throw new SQLException ("Already closed."); 78 } else { 79 try { 80 _pool.returnObject(this); 81 } catch(SQLException e) { 82 throw e; 83 } catch(RuntimeException e) { 84 throw e; 85 } catch(Exception e) { 86 throw new SQLNestedException("Cannot close connection (return to pool failed)", e); 87 } 88 } 89 } 90 91 94 public void reallyClose() throws SQLException { 95 super.close(); 96 } 97 98 } 99 100 | Popular Tags |