Thread: [Proxool-cvs] proxool/src/java/org/logicalcobwebs/proxool FatalRuntimeException.java,NONE,1.1 FatalS
UNMAINTAINED!
Brought to you by:
billhorsman
Update of /cvsroot/proxool/proxool/src/java/org/logicalcobwebs/proxool In directory sc8-pr-cvs1:/tmp/cvs-serv27085 Modified Files: ConnectionPoolDefinition.java ConnectionPoolDefinitionIF.java Added Files: FatalRuntimeException.java FatalSqlExceptionHelper.java Log Message: New fatal-sql-exception-wrapper-class allows you to define what exception is used as a wrapper. This means that you can make it a RuntimeException if you need to. --- NEW FILE: FatalRuntimeException.java --- /* * This software is released under the Apache Software Licence. See * package.html for details. The latest version is available at * http://proxool.sourceforge.net */ package org.logicalcobwebs.proxool; /** * A type of SQLException that has been defined as fatal. It contains * the {@link #getCause original} plain Exception * just in case you need it. * @version $Revision: 1.1 $, $Date: 2003/09/29 17:48:08 $ * @author billhorsman * @author $Author: billhorsman $ (current maintainer) * @see ConnectionPoolDefinitionIF#getFatalSqlExceptions */ public class FatalRuntimeException extends RuntimeException { /** * @see #getCause */ private Exception cause; public FatalRuntimeException(Exception cause) { super(cause.getMessage()); this.cause = cause; } /** * @see Throwable#getCause */ public Throwable getCause() { return cause; } } --- NEW FILE: FatalSqlExceptionHelper.java --- package org.logicalcobwebs.proxool; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.sql.SQLException; /* * Copyright 2002, Findexa AS (http://www.findexa.no) * * This software is the proprietary information of Findexa AS. * Use is subject to license terms. */ class FatalSqlExceptionHelper { /** * Throws a wrapped SQLException if a wrapper is defined * @param className the classname of the wrapping exception (must be either a RuntimeException or * an SQLException). If null, then the original exception is rethrown. * @param originalException the orginal exception * @throws ProxoolException if there is an unexpected error with wrapping the exception * @throws SQLException either the original exception, or a wrapped version of it * @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; try { clazz = Class.forName(className); } catch (ClassNotFoundException e) { throw new ProxoolException("Couldn't find class " + className); } if (SQLException.class.isAssignableFrom(clazz)) { // That's OK } else if (RuntimeException.class.isAssignableFrom(clazz)) { // That's OK } else { throw new ProxoolException("Couldn't wrap up using " + clazz.getName() + " because it isn't either a RuntimeException or an SQLException"); } Constructor toUse = null; Object[] args = null; String argDescription = ""; Constructor[] constructors = clazz.getConstructors(); for (int i = 0; i < constructors.length; i++) { Constructor constructor = constructors[i]; Class[] parameterTypes = constructor.getParameterTypes(); if (toUse == null && parameterTypes.length == 0) { toUse = constructor; } if (parameterTypes.length == 1 && Exception.class.isAssignableFrom(parameterTypes[0])) { toUse = constructor; args = new Object[]{originalException}; argDescription = "Exception"; break; } } try { Object exceptionToThrow = toUse.newInstance(args); if (exceptionToThrow instanceof RuntimeException) { throw (RuntimeException) exceptionToThrow; } else if (exceptionToThrow instanceof SQLException) { throw (SQLException) exceptionToThrow; } else { throw new ProxoolException("Couldn't throw " + clazz.getName() + " because it isn't either a RuntimeException or an SQLException"); } } catch (InstantiationException e) { throw new ProxoolException("Couldn't create " + clazz.getName() + "(" + argDescription + ")", e); } catch (IllegalAccessException e) { throw new ProxoolException("Couldn't create " + clazz.getName() + "(" + argDescription + ")", e); } catch (InvocationTargetException e) { throw new ProxoolException("Couldn't create " + clazz.getName() + "(" + argDescription + ")", e); } } else { throw originalException; } } } Index: ConnectionPoolDefinition.java =================================================================== RCS file: /cvsroot/proxool/proxool/src/java/org/logicalcobwebs/proxool/ConnectionPoolDefinition.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** ConnectionPoolDefinition.java 5 Sep 2003 16:59:42 -0000 1.22 --- ConnectionPoolDefinition.java 29 Sep 2003 17:48:08 -0000 1.23 *************** *** 105,109 **** private String fatalSqlExceptionsAsString; ! private boolean wrapFatalSqlExceptions = false; private String houseKeepingTestSql; --- 105,109 ---- private String fatalSqlExceptionsAsString; ! private String fatalSqlExceptionWrapper = null; private String houseKeepingTestSql; *************** *** 363,372 **** } } ! } else if (key.equals(ProxoolConstants.WRAP_FATAL_SQL_EXCEPTIONS_PROPERTY)) { ! final boolean valueAsBoolean = Boolean.valueOf(value).booleanValue(); ! if (valueAsBoolean != wrapFatalSqlExceptions) { changed = true; if (!pretend) { ! setWrapFatalSqlExceptions(valueAsBoolean); } } --- 363,371 ---- } } ! } else if (key.equals(ProxoolConstants.FATAL_SQL_EXCEPTION_WRAPPER_CLASS_PROPERTY)) { ! if (isChanged(fatalSqlExceptionWrapper, value)) { changed = true; if (!pretend) { ! setFatalSqlExceptionWrapper(value); } } *************** *** 407,411 **** * @see #setAnyProperty */ ! private boolean setLoggingProperty(String key, String value, boolean pretend) throws ProxoolException { boolean changed = false; if (key.equals(ProxoolConstants.DEBUG_LEVEL_PROPERTY)) { --- 406,410 ---- * @see #setAnyProperty */ ! private boolean setLoggingProperty(String key, String value, boolean pretend) { boolean changed = false; if (key.equals(ProxoolConstants.DEBUG_LEVEL_PROPERTY)) { *************** *** 451,455 **** * @see #setAnyProperty */ ! private boolean setJndiProperty(String key, String value, boolean pretend) throws ProxoolException { boolean changed = false; if (key.equals(ProxoolConstants.JNDI_NAME_PROPERTY)) { --- 450,454 ---- * @see #setAnyProperty */ ! private boolean setJndiProperty(String key, String value, boolean pretend) { boolean changed = false; if (key.equals(ProxoolConstants.JNDI_NAME_PROPERTY)) { *************** *** 910,924 **** /** ! * @see ConnectionPoolDefinitionIF#isWrapFatalSqlExceptions */ ! public boolean isWrapFatalSqlExceptions() { ! return wrapFatalSqlExceptions; } /** ! * @see ConnectionPoolDefinitionIF#isWrapFatalSqlExceptions */ ! public void setWrapFatalSqlExceptions(boolean wrapFatalSqlExceptions) { ! this.wrapFatalSqlExceptions = wrapFatalSqlExceptions; } --- 909,933 ---- /** ! * @see ConnectionPoolDefinitionIF#getFatalSqlExceptionWrapper */ ! public String getFatalSqlExceptionWrapper() { ! return fatalSqlExceptionWrapper; } /** ! * @see ConnectionPoolDefinitionIF#getFatalSqlExceptionWrapper */ ! public void setFatalSqlExceptionWrapper(String fatalSqlExceptionWrapper) throws ProxoolException { ! ! // Test it out. That's the best way. ! try { ! FatalSqlExceptionHelper.throwFatalSQLException(fatalSqlExceptionWrapper, new SQLException("Test")); ! } catch (SQLException e) { ! // That's OK, we were expecting one of these ! } catch (RuntimeException e) { ! // That's OK, we were expecting one of these ! } ! ! this.fatalSqlExceptionWrapper = fatalSqlExceptionWrapper; } *************** *** 1055,1058 **** --- 1064,1071 ---- Revision history: $Log$ + 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 + can make it a RuntimeException if you need to. + Revision 1.22 2003/09/05 16:59:42 billhorsman Added wrap-fatal-sql-exceptions property Index: ConnectionPoolDefinitionIF.java =================================================================== RCS file: /cvsroot/proxool/proxool/src/java/org/logicalcobwebs/proxool/ConnectionPoolDefinitionIF.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** ConnectionPoolDefinitionIF.java 5 Sep 2003 16:59:42 -0000 1.18 --- ConnectionPoolDefinitionIF.java 29 Sep 2003 17:48:08 -0000 1.19 *************** *** 229,239 **** /** ! * If true then if a fatal SQLException is detected then it will be wrapped up ! * in a {@link FatalSQLException} and that will be thrown instead. ! * Range: true, false ! * Default: false (original exception is thrown) ! * @return whether fatal SQLExceptions are wrapped up */ ! boolean isWrapFatalSqlExceptions(); /** --- 229,240 ---- /** ! * If this is not-null then any fatal SQLException is wrapped up inside ! * an instance of this class. If null, then the original exception is ! * thrown. ! * Range: any valid class name that is a subclass of SQLException or RuntimeException ! * Default: null (original exception is thrown) ! * @return the class name to use for fatal SQL exceptions */ ! String getFatalSqlExceptionWrapper(); /** *************** *** 278,281 **** --- 279,286 ---- Revision history: $Log$ + 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 + can make it a RuntimeException if you need to. + Revision 1.18 2003/09/05 16:59:42 billhorsman Added wrap-fatal-sql-exceptions property |