commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Jeffrey.Constan...@cox.com>
Subject "Already closed." exception in org.apache.commons.dbcp.PoolableConnection
Date Mon, 19 Nov 2007 21:28:08 GMT
To Whom It May Concern:
 
Why is it necessary to throw a new SQLException("Already closed") when
the purpose of the close() method is to close the connection. Seems to
me this Exception is not necessary.
 
In my code (Tomcat/DBCP/iBATIS) apparently iBATIS is trying to close an
already closed connection( without checking ) and this causes the
close() method to throw the exception.
 
Any design thoughts are greatly appreciated.
 
Thanks,
 
Jeff
 
    /**
     * Returns me to my pool.
     */
     public synchronized void close() throws SQLException {
        boolean isClosed = false;
        try {
            isClosed = isClosed();
        } catch (SQLException e) {
            try {
                _pool.invalidateObject(this); // XXX should be guarded
to happen at most once
            } catch (Exception ie) {
                // DO NOTHING the original exception will be rethrown
            }
            throw new SQLNestedException("Cannot close connection
(isClosed check failed)", e);
        }
        if (isClosed) {
            try {
                _pool.invalidateObject(this); // XXX should be guarded
to happen at most once
            } catch (Exception ie) {
                // DO NOTHING, "Already closed" exception thrown below
            }
            throw new SQLException("Already closed.");
        } else {
            try {
                _pool.returnObject(this); // XXX should be guarded to
happen at most once
            } catch(SQLException e) {
                throw e;
            } catch(RuntimeException e) {
                throw e;
            } catch(Exception e) {
                throw new SQLNestedException("Cannot close connection
(return to pool failed)", e);
            }
        }
    }

 

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message