[Proxool-cvs] proxool/src/java/org/logicalcobwebs/proxool AbstractProxyStatement.java,1.11,1.12 Conn
UNMAINTAINED!
Brought to you by:
billhorsman
Update of /cvsroot/proxool/proxool/src/java/org/logicalcobwebs/proxool In directory sc8-pr-cvs1:/tmp/cvs-serv30271 Modified Files: AbstractProxyStatement.java ConnectionPool.java ConnectionPoolDefinition.java ConnectionPoolDefinitionIF.java FatalSqlExceptionHelper.java Prototyper.java ProxoolConstants.java ProxoolDriver.java ProxyConnection.java ProxyFactory.java ProxyStatement.java Log Message: New test-before-use, test-after-use and fatal-sql-exception-wrapper-class properties. Index: AbstractProxyStatement.java =================================================================== RCS file: /cvsroot/proxool/proxool/src/java/org/logicalcobwebs/proxool/AbstractProxyStatement.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** AbstractProxyStatement.java 5 Sep 2003 16:26:50 -0000 1.11 --- AbstractProxyStatement.java 30 Sep 2003 18:39:07 -0000 1.12 *************** *** 12,16 **** import java.sql.Statement; import java.util.Comparator; - import java.util.Iterator; import java.util.Map; import java.util.StringTokenizer; --- 12,15 ---- *************** *** 58,85 **** * Check to see whether an exception is a fatal one. If it is, then throw the connection * away (and it won't be made available again) ! * @param e the exception to test */ ! protected boolean testException(SQLException e) { ! boolean fatalSqlExceptionDetected = false; ! Iterator i = connectionPool.getDefinition().getFatalSqlExceptions().iterator(); ! while (i.hasNext()) { ! if (e.getMessage().indexOf((String) i.next()) > -1) { ! // This SQL exception indicates a fatal problem with this connection. We should probably ! // just junk it. ! fatalSqlExceptionDetected = true; ! try { ! statement.close(); ! connectionPool.throwConnection(proxyConnection, "Fatal SQL Exception has been detected"); ! // We should check all the existing connections as soon as possible ! HouseKeeperController.sweepNow(connectionPool.getDefinition().getAlias()); ! LOG.warn("Connection has been thrown away because fatal exception was detected", e); ! } catch (SQLException e2) { ! LOG.error("Problem trying to throw away suspect connection", e2); ! } } } - return fatalSqlExceptionDetected; } --- 57,81 ---- * Check to see whether an exception is a fatal one. If it is, then throw the connection * away (and it won't be made available again) ! * @param t the exception to test */ ! protected boolean testException(Throwable t) { ! if (FatalSqlExceptionHelper.testException(connectionPool.getDefinition(), t)) { ! // This SQL exception indicates a fatal problem with this connection. We should probably ! // just junk it. ! try { ! statement.close(); ! connectionPool.throwConnection(proxyConnection, "Fatal SQL Exception has been detected"); ! // We should check all the existing connections as soon as possible ! HouseKeeperController.sweepNow(connectionPool.getDefinition().getAlias()); ! LOG.warn("Connection has been thrown away because fatal exception was detected", t); ! } catch (SQLException e2) { ! LOG.error("Problem trying to throw away suspect connection", e2); } + return true; + } else { + return false; } } *************** *** 213,216 **** --- 209,215 ---- Revision history: $Log$ + Revision 1.12 2003/09/30 18:39:07 billhorsman + New test-before-use, test-after-use and fatal-sql-exception-wrapper-class properties. + Revision 1.11 2003/09/05 16:26:50 billhorsman testException() now returns true if a fatal exception was detected. Index: ConnectionPool.java =================================================================== RCS file: /cvsroot/proxool/proxool/src/java/org/logicalcobwebs/proxool/ConnectionPool.java,v retrieving revision 1.69 retrieving revision 1.70 diff -C2 -d -r1.69 -r1.70 *** ConnectionPool.java 30 Sep 2003 07:50:04 -0000 1.69 --- ConnectionPool.java 30 Sep 2003 18:39:08 -0000 1.70 *************** *** 15,18 **** --- 15,19 ---- import java.sql.Connection; import java.sql.SQLException; + import java.sql.Statement; import java.util.Collection; import java.util.Comparator; *************** *** 199,204 **** // in between) if (proxyConnection != null && proxyConnection.setStatus(ProxyConnectionIF.STATUS_AVAILABLE, ProxyConnectionIF.STATUS_ACTIVE)) { ! nextAvailableConnection++; ! break; } else { proxyConnection = null; --- 200,215 ---- // in between) if (proxyConnection != null && proxyConnection.setStatus(ProxyConnectionIF.STATUS_AVAILABLE, ProxyConnectionIF.STATUS_ACTIVE)) { ! ! // Okay. So we have it. But is it working ok? ! if (getDefinition().isTestBeforeUse()) { ! if (!testConnection(proxyConnection)) { ! // Oops. No it's not. Let's choose another. ! proxyConnection = null; ! } ! } ! if (proxyConnection != null) { ! nextAvailableConnection++; ! break; ! } } else { proxyConnection = null; *************** *** 212,222 **** proxyConnection = PrototyperController.buildConnection( getDefinition().getAlias(), ProxyConnection.STATUS_ACTIVE, "on demand"); } catch (SQLException e) { - log.debug("Couldn't get connection", e); throw e; } catch (ProxoolException e) { log.debug("Couldn't get connection", e); throw new SQLException(e.toString()); ! } catch (Exception e) { log.error("Couldn't get connection", e); throw new SQLException(e.toString()); --- 223,239 ---- proxyConnection = PrototyperController.buildConnection( getDefinition().getAlias(), ProxyConnection.STATUS_ACTIVE, "on demand"); + // Okay. So we have it. But is it working ok? + if (getDefinition().isTestBeforeUse()) { + if (!testConnection(proxyConnection)) { + // Oops. No it's not. There's not much more we can do for now + throw new SQLException("Created a new connection but it failed its test"); + } + } } catch (SQLException e) { throw e; } catch (ProxoolException e) { log.debug("Couldn't get connection", e); throw new SQLException(e.toString()); ! } catch (Throwable e) { log.error("Couldn't get connection", e); throw new SQLException(e.toString()); *************** *** 225,231 **** } catch (SQLException e) { - if (log.isDebugEnabled()) { - log.debug("Problem getting connection", e); - } throw e; } catch (Throwable t) { --- 242,245 ---- *************** *** 257,260 **** --- 271,300 ---- } + private boolean testConnection(ProxyConnectionIF proxyConnection) { + boolean success = false; + final String testSql = getDefinition().getHouseKeepingTestSql(); + if (testSql != null && testSql.length() > 0) { + Statement s = null; + try { + s = proxyConnection.getConnection().createStatement(); + s.execute(testSql); + success = true; + if (LOG.isDebugEnabled()) { + LOG.debug(displayStatistics() + " - Connection #" + proxyConnection.getId() + " tested: OK"); + } + } catch (Throwable t) { + proxyConnection.setStatus(ProxyConnectionIF.STATUS_NULL); + removeProxyConnection(proxyConnection, "it has problems: " + t, ConnectionPool.REQUEST_EXPIRY, true); + } finally { + try { + s.close(); + } catch (SQLException e) { + // Ignore + } + } + } + return success; + } + /** * Add a ProxyConnection to the pool *************** *** 306,309 **** --- 346,355 ---- } + // Optionally, test it to see if it is ok + if (getDefinition().isTestAfterUse()) { + // It will get removed by this call if it is no good + testConnection(proxyConnection); + } + if (log.isDebugEnabled() && getDefinition().isVerbose()) { log.debug(displayStatistics() + " - Connection #" + proxyConnection.getId() + " returned"); *************** *** 1049,1052 **** --- 1095,1101 ---- Revision history: $Log$ + Revision 1.70 2003/09/30 18:39:08 billhorsman + New test-before-use, test-after-use and fatal-sql-exception-wrapper-class properties. + Revision 1.69 2003/09/30 07:50:04 billhorsman Smarter throwing of caught SQLExceptions without wrapping them up inside another (and losing the stack trace) Index: ConnectionPoolDefinition.java =================================================================== RCS file: /cvsroot/proxool/proxool/src/java/org/logicalcobwebs/proxool/ConnectionPoolDefinition.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** ConnectionPoolDefinition.java 29 Sep 2003 17:48:08 -0000 1.23 --- ConnectionPoolDefinition.java 30 Sep 2003 18:39:08 -0000 1.24 *************** *** 109,112 **** --- 109,116 ---- private String houseKeepingTestSql; + private boolean testBeforeUse; + + private boolean testAfterUse; + /** * So we can set the values one by one if we want *************** *** 278,295 **** } } ! } else if (key.equals(ProxoolConstants.HOUSE_KEEPING_SLEEP_TIME_PROPERTY)) { ! if (getHouseKeepingSleepTime() != getInt(key, value)) { ! changed = true; ! if (!pretend) { ! setHouseKeepingSleepTime(getInt(key, value)); ! } ! } ! } else if (key.equals(ProxoolConstants.HOUSE_KEEPING_TEST_SQL_PROPERTY)) { ! if (isChanged(getHouseKeepingTestSql(), value)) { ! changed = true; ! if (!pretend) { ! setHouseKeepingTestSql(value); ! } ! } } else if (key.equals(ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY)) { if (getMaximumConnectionCount() != getInt(key, value)) { --- 282,287 ---- } } ! } else if (setHouseKeeperProperty(key, value, pretend)) { ! changed = true; } else if (key.equals(ProxoolConstants.MAXIMUM_CONNECTION_COUNT_PROPERTY)) { if (getMaximumConnectionCount() != getInt(key, value)) { *************** *** 447,450 **** --- 439,482 ---- /** + * Subset of {@link #setAnyProperty} to avoid overly long method. + * @see #setAnyProperty + */ + private boolean setHouseKeeperProperty(String key, String value, boolean pretend) throws ProxoolException { + boolean changed = false; + if (key.equals(ProxoolConstants.HOUSE_KEEPING_SLEEP_TIME_PROPERTY)) { + if (getHouseKeepingSleepTime() != getInt(key, value)) { + changed = true; + if (!pretend) { + setHouseKeepingSleepTime(getInt(key, value)); + } + } + } else if (key.equals(ProxoolConstants.HOUSE_KEEPING_TEST_SQL_PROPERTY)) { + if (isChanged(getHouseKeepingTestSql(), value)) { + changed = true; + if (!pretend) { + setHouseKeepingTestSql(value); + } + } + } else if (key.equals(ProxoolConstants.TEST_BEFORE_USE_PROPERTY)) { + final boolean valueAsBoolean = Boolean.valueOf(value).booleanValue(); + if (isTestBeforeUse() != valueAsBoolean) { + changed = true; + if (!pretend) { + setTestBeforeUse(valueAsBoolean); + } + } + } else if (key.equals(ProxoolConstants.TEST_AFTER_USE_PROPERTY)) { + final boolean valueAsBoolean = Boolean.valueOf(value).booleanValue(); + if (isTestAfterUse() != valueAsBoolean) { + changed = true; + if (!pretend) { + setTestAfterUse(valueAsBoolean); + } + } + } + return changed; + } + + /** * Subset of {@link #setAnyProperty} to avoid overly long method * @see #setAnyProperty *************** *** 538,541 **** --- 570,575 ---- houseKeepingSleepTime = DEFAULT_HOUSE_KEEPING_SLEEP_TIME; houseKeepingTestSql = null; + testAfterUse = false; + testBeforeUse = false; simultaneousBuildThrottle = DEFAULT_SIMULTANEOUS_BUILD_THROTTLE; recentlyStartedThreshold = DEFAULT_RECENTLY_STARTED_THRESHOLD; *************** *** 547,550 **** --- 581,585 ---- statisticsLogLevel = null; fatalSqlExceptions.clear(); + fatalSqlExceptionWrapper = null; } *************** *** 947,950 **** --- 982,1013 ---- /** + * @see ConnectionPoolDefinitionIF#isTestBeforeUse + */ + public boolean isTestBeforeUse() { + return testBeforeUse; + } + + /** + * @see ConnectionPoolDefinitionIF#isTestBeforeUse + */ + public void setTestBeforeUse(boolean testBeforeUse) { + this.testBeforeUse = testBeforeUse; + } + + /** + * @see ConnectionPoolDefinitionIF#isTestAfterUse + */ + public boolean isTestAfterUse() { + return testAfterUse; + } + + /** + * @see ConnectionPoolDefinitionIF#isTestAfterUse + */ + public void setTestAfterUse(boolean testAfterUse) { + this.testAfterUse = testAfterUse; + } + + /** * @see ConnectionPoolDefinitionIF#getStatistics */ *************** *** 1064,1067 **** --- 1127,1133 ---- Revision history: $Log$ + Revision 1.24 2003/09/30 18:39:08 billhorsman + New test-before-use, test-after-use and fatal-sql-exception-wrapper-class properties. + Revision 1.23 2003/09/29 17:48:08 billhorsman New fatal-sql-exception-wrapper-class allows you to define what exception is used as a wrapper. This means that you Index: ConnectionPoolDefinitionIF.java =================================================================== RCS file: /cvsroot/proxool/proxool/src/java/org/logicalcobwebs/proxool/ConnectionPoolDefinitionIF.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** ConnectionPoolDefinitionIF.java 29 Sep 2003 17:48:08 -0000 1.19 --- ConnectionPoolDefinitionIF.java 30 Sep 2003 18:39:08 -0000 1.20 *************** *** 168,181 **** * is always thrown back to the user. * @return the list of exception fragments (String) ! * @see #FATAL_SQL_EXCEPTIONS_DELIMITER */ Set getFatalSqlExceptions(); /** ! * ! * @return */ String getHouseKeepingTestSql(); /** * The URL that was used to define this pool. For example: --- 168,197 ---- * is always thrown back to the user. * @return the list of exception fragments (String) ! * @see #FATAL_SQL_EXCEPTIONS_DELIMITER */ Set getFatalSqlExceptions(); /** ! * The test SQL that we perform to see if a connection is alright. ! * Should be fast and robust. ! * @return house keeping test SQL */ String getHouseKeepingTestSql(); + /** + * Whether we test each connection before it is served + * @return true if we do the test + * @see #getHouseKeepingTestSql + */ + boolean isTestBeforeUse(); + + /** + * Whether we test each connection after it is closed + * (that is, returned to the pool) + * @return true if we do the test + * @see #getHouseKeepingTestSql + */ + boolean isTestAfterUse(); + /** * The URL that was used to define this pool. For example: *************** *** 279,282 **** --- 295,301 ---- Revision history: $Log$ + Revision 1.20 2003/09/30 18:39:08 billhorsman + New test-before-use, test-after-use and fatal-sql-exception-wrapper-class properties. + Revision 1.19 2003/09/29 17:48:08 billhorsman New fatal-sql-exception-wrapper-class allows you to define what exception is used as a wrapper. This means that you Index: FatalSqlExceptionHelper.java =================================================================== RCS file: /cvsroot/proxool/proxool/src/java/org/logicalcobwebs/proxool/FatalSqlExceptionHelper.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FatalSqlExceptionHelper.java 29 Sep 2003 18:12:33 -0000 1.2 --- FatalSqlExceptionHelper.java 30 Sep 2003 18:39:08 -0000 1.3 *************** *** 6,12 **** --- 6,17 ---- package org.logicalcobwebs.proxool; + import org.logicalcobwebs.logging.Log; + import org.logicalcobwebs.logging.LogFactory; + import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; + import java.lang.reflect.Method; import java.sql.SQLException; + import java.util.Iterator; /** *************** *** 18,21 **** --- 23,28 ---- class FatalSqlExceptionHelper { + private static final Log LOG = LogFactory.getLog(FatalSqlExceptionHelper.class); + /** * Throws a wrapped SQLException if a wrapper is defined *************** *** 27,31 **** * @throws RuntimeException a wrapped up version of the orginal */ ! protected static void throwFatalSQLException(String className, SQLException originalException) throws ProxoolException, SQLException, RuntimeException { if (className != null && className.trim().length() > 0) { Class clazz = null; --- 34,38 ---- * @throws RuntimeException a wrapped up version of the orginal */ ! protected static void throwFatalSQLException(String className, Throwable originalException) throws ProxoolException, SQLException, RuntimeException { if (className != null && className.trim().length() > 0) { Class clazz = null; *************** *** 62,65 **** --- 69,73 ---- Object exceptionToThrow = toUse.newInstance(args); if (exceptionToThrow instanceof RuntimeException) { + LOG.debug("Wrapping up a fatal exception: " + originalException.getMessage(), originalException); throw (RuntimeException) exceptionToThrow; } else if (exceptionToThrow instanceof SQLException) { *************** *** 76,82 **** } } else { ! throw originalException; } } } --- 84,196 ---- } } else { ! if (originalException instanceof SQLException) { ! throw (SQLException) originalException; ! } else if (originalException instanceof RuntimeException) { ! throw (RuntimeException) originalException; ! } else { ! throw new RuntimeException("Unexpected exception:" + originalException.getMessage()); ! } } } + + /** + * Test to see if an exception is a fatal one + * @param cpd the definition so we can find out what a fatal exception looks like + * @param t the exception to test + * @return true if it is fatal + */ + protected static boolean testException(ConnectionPoolDefinitionIF cpd, Throwable t) { + return testException(cpd, t, 0); + } + + /** + * Test to see if an exception is a fatal one + * @param cpd the definition so we can find out what a fatal exception looks like + * @param t the exception to test + * @param level the recursion level (max 20) + * @return true if it is fatal + */ + protected static boolean testException(ConnectionPoolDefinitionIF cpd, Throwable t, int level) { + boolean fatalSqlExceptionDetected = false; + Iterator i = cpd.getFatalSqlExceptions().iterator(); + while (i.hasNext()) { + if (t.getMessage().indexOf((String) i.next()) > -1) { + // This SQL exception indicates a fatal problem with this connection. + fatalSqlExceptionDetected = true; + } + } + + // If it isn't fatal, then try testing the contained exception + if (!fatalSqlExceptionDetected && level < 20) { + Throwable cause = getCause(t); + if (cause != null) { + fatalSqlExceptionDetected = testException(cpd, cause, level + 1); + } + } + + return fatalSqlExceptionDetected; + } + + /** + * Tries to drill down into an exception to find its cause. Only goes one level deep. + * Uses reflection to look at getCause(), getTargetException(), getRootCause() and + * finally getOriginalException() methods to see if it can find one. Doesn't throw + * an error - it will just log a warning and return a null if nothing was found. + * @param t the exception to look inside + * @return the original exception or null if none was found. + */ + protected static Throwable getCause(Throwable t) { + Throwable cause = null; + Method causeMethod = null; + + try { + // Try a series of likely accessor methods + if (causeMethod == null) { + causeMethod = getMethod(t, "getCause"); + } + if (causeMethod == null) { + causeMethod = getMethod(t, "getTargetException"); + } + if (causeMethod == null) { + causeMethod = getMethod(t, "getRootCause"); + } + if (causeMethod == null) { + causeMethod = getMethod(t, "getOriginalException"); + } + + // If one was found, invoke it. + if (causeMethod != null) { + try { + cause = (Throwable) causeMethod.invoke(t, null); + } catch (IllegalAccessException e) { + LOG.warn("Problem invoking " + t.getClass().getName() + "." + causeMethod.getName() + ". Ignoring.", e); + } catch (IllegalArgumentException e) { + LOG.warn("Problem invoking " + t.getClass().getName() + "." + causeMethod.getName() + ". Ignoring.", e); + } catch (InvocationTargetException e) { + LOG.warn("Problem invoking " + t.getClass().getName() + "." + causeMethod.getName() + ". Ignoring.", e); + } + } + } catch (Exception e) { + LOG.warn("Unexpected exception drilling into exception. Ignoring.", e); + } + return cause; + } + + private static Method getMethod(Object o, String methodName) { + Method m = null; + try { + m = o.getClass().getMethod(methodName, null); + // Reject any method that doesn't return a throwable. + if (!Throwable.class.isAssignableFrom(m.getReturnType())) { + m = null; + } + } catch (NoSuchMethodException e) { + // That's OK + } catch (SecurityException e) { + LOG.warn("Problem finding method " + methodName, e); + } + return m; + } + } *************** *** 84,87 **** --- 198,204 ---- Revision history: $Log$ + Revision 1.3 2003/09/30 18:39:08 billhorsman + New test-before-use, test-after-use and fatal-sql-exception-wrapper-class properties. + Revision 1.2 2003/09/29 18:12:33 billhorsman Doc Index: Prototyper.java =================================================================== RCS file: /cvsroot/proxool/proxool/src/java/org/logicalcobwebs/proxool/Prototyper.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Prototyper.java 11 Sep 2003 10:44:54 -0000 1.6 --- Prototyper.java 30 Sep 2003 18:39:08 -0000 1.7 *************** *** 87,90 **** --- 87,91 ---- } + ProxyConnectionIF freshlyBuiltProxyConnection = null; try { // If it has been shutdown then we should just stop now. *************** *** 92,96 **** break; } ! buildConnection(ProxyConnection.STATUS_AVAILABLE, reason); somethingDone = true; } catch (Throwable e) { --- 93,97 ---- break; } ! freshlyBuiltProxyConnection = buildConnection(ProxyConnection.STATUS_AVAILABLE, reason); somethingDone = true; } catch (Throwable e) { *************** *** 104,107 **** --- 105,112 ---- // housekeeping thread runs. } + if (freshlyBuiltProxyConnection == null) { + // That's strange. No double the buildConnection() method logged the + // error, but we should have build a connection here. + } } } catch (Throwable t) { *************** *** 181,191 **** } catch (RuntimeException e) { if (log.isDebugEnabled()) { ! log.debug(e); } throw e; } catch (Throwable t) { if (log.isDebugEnabled()) { ! log.debug(t); } } finally { synchronized (lock) { --- 186,197 ---- } catch (RuntimeException e) { if (log.isDebugEnabled()) { ! log.debug("Prototyping problem", e); } throw e; } catch (Throwable t) { if (log.isDebugEnabled()) { ! log.debug("Prototyping problem", t); } + throw new ProxoolException("Unexpected prototyping problem", t); } finally { synchronized (lock) { *************** *** 261,264 **** --- 267,273 ---- Revision history: $Log$ + Revision 1.7 2003/09/30 18:39:08 billhorsman + New test-before-use, test-after-use and fatal-sql-exception-wrapper-class properties. + Revision 1.6 2003/09/11 10:44:54 billhorsman Catch throwable not just exception during creation of connection Index: ProxoolConstants.java =================================================================== RCS file: /cvsroot/proxool/proxool/src/java/org/logicalcobwebs/proxool/ProxoolConstants.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** ProxoolConstants.java 29 Sep 2003 17:48:21 -0000 1.18 --- ProxoolConstants.java 30 Sep 2003 18:39:08 -0000 1.19 *************** *** 62,65 **** --- 62,77 ---- public final String HOUSE_KEEPING_TEST_SQL_PROPERTY = PROPERTY_PREFIX + HOUSE_KEEPING_TEST_SQL; + /** @see #TEST_BEFORE_USE_PROPERTY */ + public final String TEST_BEFORE_USE = "test-before-use"; + + /** @see ProxoolDriver#getPropertyInfo */ + public final String TEST_BEFORE_USE_PROPERTY = PROPERTY_PREFIX + TEST_BEFORE_USE; + + /** @see #TEST_AFTER_USE_PROPERTY */ + public final String TEST_AFTER_USE = "test-after-use"; + + /** @see ProxoolDriver#getPropertyInfo */ + public final String TEST_AFTER_USE_PROPERTY = PROPERTY_PREFIX + TEST_AFTER_USE; + /** @see #MAXIMUM_CONNECTION_COUNT_PROPERTY */ public final String MAXIMUM_CONNECTION_COUNT = "maximum-connection-count"; *************** *** 253,256 **** --- 265,271 ---- Revision history: $Log$ + Revision 1.19 2003/09/30 18:39:08 billhorsman + New test-before-use, test-after-use and fatal-sql-exception-wrapper-class properties. + Revision 1.18 2003/09/29 17:48:21 billhorsman New fatal-sql-exception-wrapper-class allows you to define what exception is used as a wrapper. This means that you Index: ProxoolDriver.java =================================================================== RCS file: /cvsroot/proxool/proxool/src/java/org/logicalcobwebs/proxool/ProxoolDriver.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** ProxoolDriver.java 5 Sep 2003 16:59:42 -0000 1.24 --- ProxoolDriver.java 30 Sep 2003 18:39:08 -0000 1.25 *************** *** 66,70 **** public Connection connect(String url, Properties info) throws SQLException { - if (!url.startsWith("proxool")) { return null; --- 66,69 ---- *************** *** 90,93 **** --- 89,107 ---- return cp.getConnection(); + } catch (SQLException e) { + LOG.error("Problem", e); + // Check to see if it's fatal. We might need to wrap it up. + try { + String alias = ProxoolFacade.getAlias(url); + cp = ConnectionPoolManager.getInstance().getConnectionPool(alias); + if (FatalSqlExceptionHelper.testException(cp.getDefinition(), e)) { + FatalSqlExceptionHelper.throwFatalSQLException(cp.getDefinition().getFatalSqlExceptionWrapper(), e); + } + // This bit isn't reached if throwFatalSQLException() above throws another exception + throw e; + } catch (ProxoolException e1) { + LOG.error("Problem", e); + throw new SQLException(e.toString()); + } } catch (ProxoolException e) { LOG.error("Problem", e); *************** *** 212,215 **** --- 226,232 ---- Revision history: $Log$ + Revision 1.25 2003/09/30 18:39:08 billhorsman + New test-before-use, test-after-use and fatal-sql-exception-wrapper-class properties. + Revision 1.24 2003/09/05 16:59:42 billhorsman Added wrap-fatal-sql-exceptions property Index: ProxyConnection.java =================================================================== RCS file: /cvsroot/proxool/proxool/src/java/org/logicalcobwebs/proxool/ProxyConnection.java,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** ProxyConnection.java 10 Sep 2003 22:21:04 -0000 1.27 --- ProxyConnection.java 30 Sep 2003 18:39:08 -0000 1.28 *************** *** 84,90 **** --- 84,97 ---- } catch (InvocationTargetException e) { + // We might get a fatal exception here. Let's test for it. + if (FatalSqlExceptionHelper.testException(getConnectionPool().getDefinition(), e.getTargetException())) { + FatalSqlExceptionHelper.throwFatalSQLException(getConnectionPool().getDefinition().getFatalSqlExceptionWrapper(), e.getTargetException()); + } throw e.getTargetException(); } catch (Exception e) { LOG.error("Unexpected invocation exception", e); + if (FatalSqlExceptionHelper.testException(getConnectionPool().getDefinition(), e)) { + FatalSqlExceptionHelper.throwFatalSQLException(getConnectionPool().getDefinition().getFatalSqlExceptionWrapper(), e); + } throw new RuntimeException("Unexpected invocation exception: " + e.getMessage()); *************** *** 99,102 **** --- 106,112 ---- Revision history: $Log$ + Revision 1.28 2003/09/30 18:39:08 billhorsman + New test-before-use, test-after-use and fatal-sql-exception-wrapper-class properties. + Revision 1.27 2003/09/10 22:21:04 chr32 Removing > jdk 1.2 dependencies. Index: ProxyFactory.java =================================================================== RCS file: /cvsroot/proxool/proxool/src/java/org/logicalcobwebs/proxool/ProxyFactory.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** ProxyFactory.java 10 Sep 2003 22:21:04 -0000 1.23 --- ProxyFactory.java 30 Sep 2003 18:39:08 -0000 1.24 *************** *** 41,45 **** Object delegate = Proxy.newProxyInstance( ! realConnection.getClass().getClassLoader(), realConnection.getClass().getInterfaces(), new ProxyConnection(realConnection, id, url, connectionPool, status)); --- 41,45 ---- Object delegate = Proxy.newProxyInstance( ! null, realConnection.getClass().getInterfaces(), new ProxyConnection(realConnection, id, url, connectionPool, status)); *************** *** 56,60 **** protected static Connection getConnection(ProxyConnectionIF proxyConnection) { return (Connection) Proxy.newProxyInstance( ! Connection.class.getClassLoader(), new Class[]{Connection.class}, (InvocationHandler) proxyConnection); --- 56,60 ---- protected static Connection getConnection(ProxyConnectionIF proxyConnection) { return (Connection) Proxy.newProxyInstance( ! null, new Class[]{Connection.class}, (InvocationHandler) proxyConnection); *************** *** 103,107 **** } */ ! return (Statement) Proxy.newProxyInstance(delegate.getClass().getClassLoader(), interfaces, new ProxyStatement(delegate, connectionPool, proxyConnection, sqlStatement)); } --- 103,107 ---- } */ ! return (Statement) Proxy.newProxyInstance(null, interfaces, new ProxyStatement(delegate, connectionPool, proxyConnection, sqlStatement)); } *************** *** 114,118 **** protected static DatabaseMetaData getDatabaseMetaData(Connection connection, ProxyConnectionIF proxyConnection) throws SQLException { return (DatabaseMetaData) Proxy.newProxyInstance( ! DatabaseMetaData.class.getClassLoader(), new Class[]{DatabaseMetaData.class}, new ProxyDatabaseMetaData(connection, proxyConnection) --- 114,118 ---- protected static DatabaseMetaData getDatabaseMetaData(Connection connection, ProxyConnectionIF proxyConnection) throws SQLException { return (DatabaseMetaData) Proxy.newProxyInstance( ! null, new Class[]{DatabaseMetaData.class}, new ProxyDatabaseMetaData(connection, proxyConnection) *************** *** 126,129 **** --- 126,132 ---- Revision history: $Log$ + Revision 1.24 2003/09/30 18:39:08 billhorsman + New test-before-use, test-after-use and fatal-sql-exception-wrapper-class properties. + Revision 1.23 2003/09/10 22:21:04 chr32 Removing > jdk 1.2 dependencies. Index: ProxyStatement.java =================================================================== RCS file: /cvsroot/proxool/proxool/src/java/org/logicalcobwebs/proxool/ProxyStatement.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** ProxyStatement.java 29 Sep 2003 17:48:49 -0000 1.21 --- ProxyStatement.java 30 Sep 2003 18:39:08 -0000 1.22 *************** *** 12,16 **** import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; - import java.sql.SQLException; import java.sql.Statement; --- 12,15 ---- *************** *** 80,99 **** } catch (InvocationTargetException e) { exception = e; ! if (e.getTargetException() instanceof SQLException) { ! final SQLException sqlException = (SQLException) e.getTargetException(); ! if (testException(sqlException)) { ! // This is really a fatal one ! FatalSqlExceptionHelper.throwFatalSQLException(getConnectionPool().getDefinition().getFatalSqlExceptionWrapper(), sqlException); ! } } throw e.getTargetException(); } catch (Exception e) { exception = e; ! if (e instanceof SQLException) { ! final SQLException sqlException = (SQLException) e; ! if (testException(sqlException)) { ! // This is really a fatal one ! FatalSqlExceptionHelper.throwFatalSQLException(getConnectionPool().getDefinition().getFatalSqlExceptionWrapper(), sqlException); ! } } throw e; --- 79,92 ---- } catch (InvocationTargetException e) { exception = e; ! if (testException(e.getTargetException())) { ! // This is really a fatal one ! FatalSqlExceptionHelper.throwFatalSQLException(getConnectionPool().getDefinition().getFatalSqlExceptionWrapper(), e.getTargetException()); } throw e.getTargetException(); } catch (Exception e) { exception = e; ! if (testException(e)) { ! // This is really a fatal one ! FatalSqlExceptionHelper.throwFatalSQLException(getConnectionPool().getDefinition().getFatalSqlExceptionWrapper(), e); } throw e; *************** *** 119,122 **** --- 112,118 ---- Revision history: $Log$ + Revision 1.22 2003/09/30 18:39:08 billhorsman + New test-before-use, test-after-use and fatal-sql-exception-wrapper-class properties. + Revision 1.21 2003/09/29 17:48:49 billhorsman New fatal-sql-exception-wrapper-class allows you to define what exception is used as a wrapper. This means that you |