From 56e97a8e3c5a31313943514d70ad65ef51a513b8 Mon Sep 17 00:00:00 2001 From: Brett Wooldridge Date: Fri, 17 Jan 2014 09:58:39 +0900 Subject: [PATCH] =?UTF-8?q?No=20need=20to=20wrap=20methods=20that=20do=20n?= =?UTF-8?q?ot=20throw=20SQLException=20with=20our=20own=20try=E2=80=A6catc?= =?UTF-8?q?h=20checkException()=20logic.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hikari/proxy/JavassistProxyFactory.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/zaxxer/hikari/proxy/JavassistProxyFactory.java b/src/main/java/com/zaxxer/hikari/proxy/JavassistProxyFactory.java index 0d811408..5598a551 100644 --- a/src/main/java/com/zaxxer/hikari/proxy/JavassistProxyFactory.java +++ b/src/main/java/com/zaxxer/hikari/proxy/JavassistProxyFactory.java @@ -30,6 +30,7 @@ import javassist.CtMethod; import javassist.CtNewMethod; import javassist.LoaderClassPath; import javassist.Modifier; +import javassist.NotFoundException; import org.slf4j.LoggerFactory; @@ -186,7 +187,16 @@ public final class JavassistProxyFactory CtMethod method = CtNewMethod.copy(intfMethod, targetCt, null); // Generate a method that simply invokes the same method on the delegate - String modifiedBody = methodBody.replace("method", method.getName()); + String modifiedBody; + if (isThrowsSqlException(intfMethod)) + { + modifiedBody = methodBody.replace("method", method.getName()); + } + else + { + modifiedBody = "return ((cast) delegate).method($$);".replace("method", method.getName()).replace("cast", primaryInterface.getName()); + } + if (method.getReturnType() == CtClass.voidType) { modifiedBody = modifiedBody.replace("return", ""); @@ -204,4 +214,24 @@ public final class JavassistProxyFactory return targetCt.toClass(classPool.getClassLoader(), null); } + + private boolean isThrowsSqlException(CtMethod method) + { + try + { + for (CtClass clazz : method.getExceptionTypes()) + { + if (clazz.getSimpleName().equals("SQLException")) + { + return true; + } + } + } + catch (NotFoundException e) + { + // fall thru + } + + return false; + } }