From b47d1dc10528bdc945192e1e0c55b4a3bf94677d Mon Sep 17 00:00:00 2001 From: Brett Wooldridge Date: Mon, 13 Oct 2014 12:09:17 +0900 Subject: [PATCH] Remove redundant code. --- .../hikari/proxy/JavassistProxyFactory.java | 40 +++++++------------ .../hikari/proxy/JavassistProxyFactory.java | 40 +++++++------------ 2 files changed, 28 insertions(+), 52 deletions(-) diff --git a/hikaricp-java6/src/main/java/com/zaxxer/hikari/proxy/JavassistProxyFactory.java b/hikaricp-java6/src/main/java/com/zaxxer/hikari/proxy/JavassistProxyFactory.java index 69e021eb..dc3dd4f5 100644 --- a/hikaricp-java6/src/main/java/com/zaxxer/hikari/proxy/JavassistProxyFactory.java +++ b/hikaricp-java6/src/main/java/com/zaxxer/hikari/proxy/JavassistProxyFactory.java @@ -31,8 +31,6 @@ import javassist.LoaderClassPath; import javassist.Modifier; import javassist.NotFoundException; -import org.slf4j.LoggerFactory; - import com.zaxxer.hikari.util.ClassLoaderUtils; /** @@ -56,8 +54,7 @@ public final class JavassistProxyFactory proxyFactoryFactory.modifyProxyFactory(); } catch (Exception e) { - LoggerFactory.getLogger(JavassistProxyFactory.class).error("Fatal exception during proxy generation", e); - throw new RuntimeException(e); + throw new RuntimeException("Fatal exception during proxy generation", e); } finally { Thread.currentThread().setContextClassLoader(contextClassLoader); @@ -73,29 +70,24 @@ public final class JavassistProxyFactory // no-op } - private JavassistProxyFactory() + private JavassistProxyFactory() throws Exception { classPool = new ClassPool(); classPool.importPackage("java.sql"); classPool.appendClassPath(new LoaderClassPath(this.getClass().getClassLoader())); - try { - // Connection is special, it has a checkClosed() call at the beginning - String methodBody = "{ checkClosed(); try { return delegate.method($$); } catch (SQLException e) { throw checkException(e); } }"; - generateProxyClass(Connection.class, ConnectionProxy.class, methodBody); - - // Cast is not needed for these - methodBody = "{ try { return delegate.method($$); } catch (SQLException e) { throw checkException(e); } }"; - generateProxyClass(Statement.class, StatementProxy.class, methodBody); - - // For these we have to cast the delegate - methodBody = "{ try { return ((cast) delegate).method($$); } catch (SQLException e) { throw checkException(e); } }"; - generateProxyClass(PreparedStatement.class, PreparedStatementProxy.class, methodBody); - generateProxyClass(CallableStatement.class, CallableStatementProxy.class, methodBody); - } - catch (Exception e) { - throw new RuntimeException(e); - } + // Connection is special, it has a checkClosed() call at the beginning + String methodBody = "{ checkClosed(); try { return delegate.method($$); } catch (SQLException e) { throw checkException(e); } }"; + generateProxyClass(Connection.class, ConnectionProxy.class, methodBody); + + // Cast is not needed for these + methodBody = "{ try { return delegate.method($$); } catch (SQLException e) { throw checkException(e); } }"; + generateProxyClass(Statement.class, StatementProxy.class, methodBody); + + // For these we have to cast the delegate + methodBody = "{ try { return ((cast) delegate).method($$); } catch (SQLException e) { throw checkException(e); } }"; + generateProxyClass(PreparedStatement.class, PreparedStatementProxy.class, methodBody); + generateProxyClass(CallableStatement.class, CallableStatementProxy.class, methodBody); } private void modifyProxyFactory() throws Exception @@ -185,10 +177,6 @@ public final class JavassistProxyFactory } } - if (Boolean.getBoolean("com.zaxxer.hikari.debug")) { - targetCt.debugWriteFile(System.getProperty("java.io.tmpdir")); - } - return targetCt.toClass(classPool.getClassLoader(), getClass().getProtectionDomain()); } diff --git a/hikaricp/src/main/java/com/zaxxer/hikari/proxy/JavassistProxyFactory.java b/hikaricp/src/main/java/com/zaxxer/hikari/proxy/JavassistProxyFactory.java index 8ea576ca..b7d9097e 100644 --- a/hikaricp/src/main/java/com/zaxxer/hikari/proxy/JavassistProxyFactory.java +++ b/hikaricp/src/main/java/com/zaxxer/hikari/proxy/JavassistProxyFactory.java @@ -31,8 +31,6 @@ import javassist.LoaderClassPath; import javassist.Modifier; import javassist.NotFoundException; -import org.slf4j.LoggerFactory; - import com.zaxxer.hikari.util.ClassLoaderUtils; /** @@ -56,8 +54,7 @@ public final class JavassistProxyFactory proxyFactoryFactory.modifyProxyFactory(); } catch (Exception e) { - LoggerFactory.getLogger(JavassistProxyFactory.class).error("Fatal exception during proxy generation", e); - throw new RuntimeException(e); + throw new RuntimeException("Fatal exception during proxy generation", e); } finally { Thread.currentThread().setContextClassLoader(contextClassLoader); @@ -73,29 +70,24 @@ public final class JavassistProxyFactory // no-op } - private JavassistProxyFactory() + private JavassistProxyFactory() throws Exception { classPool = new ClassPool(); classPool.importPackage("java.sql"); classPool.appendClassPath(new LoaderClassPath(this.getClass().getClassLoader())); - try { - // Connection is special, it has a checkClosed() call at the beginning - String methodBody = "{ checkClosed(); try { return delegate.method($$); } catch (SQLException e) { throw checkException(e); } }"; - generateProxyClass(Connection.class, ConnectionProxy.class, methodBody); - - // Cast is not needed for these - methodBody = "{ try { return delegate.method($$); } catch (SQLException e) { throw checkException(e); } }"; - generateProxyClass(Statement.class, StatementProxy.class, methodBody); - - // For these we have to cast the delegate - methodBody = "{ try { return ((cast) delegate).method($$); } catch (SQLException e) { throw checkException(e); } }"; - generateProxyClass(PreparedStatement.class, PreparedStatementProxy.class, methodBody); - generateProxyClass(CallableStatement.class, CallableStatementProxy.class, methodBody); - } - catch (Exception e) { - throw new RuntimeException(e); - } + // Connection is special, it has a checkClosed() call at the beginning + String methodBody = "{ checkClosed(); try { return delegate.method($$); } catch (SQLException e) { throw checkException(e); } }"; + generateProxyClass(Connection.class, ConnectionProxy.class, methodBody); + + // Cast is not needed for these + methodBody = "{ try { return delegate.method($$); } catch (SQLException e) { throw checkException(e); } }"; + generateProxyClass(Statement.class, StatementProxy.class, methodBody); + + // For these we have to cast the delegate + methodBody = "{ try { return ((cast) delegate).method($$); } catch (SQLException e) { throw checkException(e); } }"; + generateProxyClass(PreparedStatement.class, PreparedStatementProxy.class, methodBody); + generateProxyClass(CallableStatement.class, CallableStatementProxy.class, methodBody); } private void modifyProxyFactory() throws Exception @@ -186,10 +178,6 @@ public final class JavassistProxyFactory } } - if (Boolean.getBoolean("com.zaxxer.hikari.debug")) { - targetCt.debugWriteFile(System.getProperty("java.io.tmpdir")); - } - return targetCt.toClass(classPool.getClassLoader(), getClass().getProtectionDomain()); }