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);
}
}
}