@SuppressWarnings("unchecked") public static <T extends Statement> T wrapInterceptor(final T delegate, final Class<? extends Statement> clazz) { InterceptorStatement<T> instance = new InterceptorStatement<T>(delegate); return (T) Proxy.newProxyInstance( instance.getClass().getClassLoader(), new Class[]{clazz}, instance); } }
@Override public Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable { try { try { return method.invoke(delegate, args); } catch (InvocationTargetException e) { throw e.getTargetException(); } } catch (SQLException e) { throw e; } catch (Exception e) { if (method.getName().startsWith("execute")) { try { handleExecException(e); } catch (Exception ex) { // We want to preserve the original exception, so let's log and discard here. log.debug("Unexpected exception handling unexpected exception from Statement execution. " + "This exception will be logged and discarded.", ex); } } throw e; } }
private static <T extends Statement> Object wrap(Class<T> clazz, Object ret) { return InterceptorStatement.wrapInterceptor(clazz.cast(ret), clazz); }
@SuppressWarnings("unchecked") public static <T extends Statement> T wrapInterceptor(final T delegate, final Class<? extends Statement> clazz) { InterceptorStatement<T> instance = new InterceptorStatement<T>(delegate); return (T) Proxy.newProxyInstance( instance.getClass().getClassLoader(), new Class[]{clazz}, instance); } }
private static <T extends Statement> Object wrap(Class<T> clazz, Object ret) { return InterceptorStatement.wrapInterceptor(clazz.cast(ret), clazz); }
@Override public Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable { try { try { return method.invoke(delegate, args); } catch (InvocationTargetException e) { throw e.getTargetException(); } } catch (SQLException e) { throw e; } catch (Exception e) { if (method.getName().startsWith("execute")) { try { handleExecException(e); } catch (Exception ex) { // We want to preserve the original exception, so let's log and discard here. log.debug("Unexpected exception handling unexpected exception from Statement execution. " + "This exception will be logged and discarded.", ex); } } throw e; } }