[Proxool-cvs] proxool/src/java/org/logicalcobwebs/proxool WrappedConnection.java,1.4,1.5
UNMAINTAINED!
Brought to you by:
billhorsman
From: <bil...@us...> - 2005-10-02 19:18:39
|
Update of /cvsroot/proxool/proxool/src/java/org/logicalcobwebs/proxool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11492/src/java/org/logicalcobwebs/proxool Modified Files: WrappedConnection.java Log Message: Improve the trapping of operations after a wrapped connection is closed. Index: WrappedConnection.java =================================================================== RCS file: /cvsroot/proxool/proxool/src/java/org/logicalcobwebs/proxool/WrappedConnection.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** WrappedConnection.java 4 May 2005 16:31:41 -0000 1.4 --- WrappedConnection.java 2 Oct 2005 12:32:58 -0000 1.5 *************** *** 54,57 **** --- 54,65 ---- private String alias; + + /** + * This gets set if the close() method is explicitly called. The {@link #getProxyConnection() proxyConnection} + * could still be {@link org.logicalcobwebs.proxool.ProxyConnectionIF#isReallyClosed() really closed} without + * this wrapper knowing about it yet. + */ + private boolean manuallyClosed; + /** * Construct this wrapper around the proxy connection *************** *** 104,114 **** } try { if (concreteMethod.getName().equals(CLOSE_METHOD)) { // It's okay to close a connection twice. Only we ignore the // second time. ! if (proxyConnection != null) { proxyConnection.close(); // Set it to null so that we can't do anything else to it. proxyConnection = null; } } else if (concreteMethod.getName().equals(EQUALS_METHOD) && argCount == 1) { --- 112,139 ---- } try { + if (proxyConnection != null && proxyConnection.isReallyClosed()) { + // The user is trying to do something to this connection and it's been closed. + if (concreteMethod.getName().equals(IS_CLOSED_METHOD)) { + // That's cool. No problem checking as many times as you like. + } else if (concreteMethod.getName().equals(CLOSE_METHOD)) { + // That's cool. You can call close as often as you like. + } else if (manuallyClosed) { + // We've already manually closed this connection yet we trying to do something + // to it that isn't another close(). That is bad client coding :) + throw new SQLException("You can't perform any operations on a connection after you've called close()"); + } else { + // The connection has been closed automatically. The client probably wasn't expecting + // that. Still, throw an exception so that they know it's all gone pear shaped. + throw new SQLException("You can't perform any operations on this connection. It has been automatically closed by Proxool for some reason (see logs)."); + } + } if (concreteMethod.getName().equals(CLOSE_METHOD)) { // It's okay to close a connection twice. Only we ignore the // second time. ! if (proxyConnection != null && !proxyConnection.isReallyClosed()) { proxyConnection.close(); // Set it to null so that we can't do anything else to it. proxyConnection = null; + manuallyClosed = true; } } else if (concreteMethod.getName().equals(EQUALS_METHOD) && argCount == 1) { *************** *** 180,184 **** throw e.getTargetException(); } catch (SQLException e) { ! throw new SQLException("Couldn't perform the operation " + concreteMethod.getName()); } catch (Exception e) { LOG.error("Unexpected invocation exception", e); --- 205,209 ---- throw e.getTargetException(); } catch (SQLException e) { ! throw new SQLException("Couldn't perform the operation " + concreteMethod.getName() + ": " + e.getMessage()); } catch (Exception e) { LOG.error("Unexpected invocation exception", e); *************** *** 242,245 **** --- 267,273 ---- Revision history: $Log$ + Revision 1.5 2005/10/02 12:32:58 billhorsman + Improve the trapping of operations after a wrapped connection is closed. + Revision 1.4 2005/05/04 16:31:41 billhorsman Use the definition referenced by the proxy connection rather than the pool instead. |