From 96578be6fdc607bce01e8aed8454681110cc3337 Mon Sep 17 00:00:00 2001 From: Brett Wooldridge Date: Tue, 15 Oct 2013 16:56:43 +0900 Subject: [PATCH] Remove cglib --- pom.xml | 5 - .../com/zaxxer/hikari/CglibProxyFactory.java | 240 ------------------ 2 files changed, 245 deletions(-) delete mode 100644 src/main/java/com/zaxxer/hikari/CglibProxyFactory.java diff --git a/pom.xml b/pom.xml index 296be18b..f8c89872 100644 --- a/pom.xml +++ b/pom.xml @@ -30,11 +30,6 @@ 1.9.5 test - - cglib - cglib - 2.2.2 - org.slf4j slf4j-simple diff --git a/src/main/java/com/zaxxer/hikari/CglibProxyFactory.java b/src/main/java/com/zaxxer/hikari/CglibProxyFactory.java deleted file mode 100644 index 6f7bd39d..00000000 --- a/src/main/java/com/zaxxer/hikari/CglibProxyFactory.java +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Copyright (C) 2013 Brett Wooldridge - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.zaxxer.hikari; - -import java.lang.reflect.Method; -import java.sql.CallableStatement; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.Statement; -import java.util.Map; -import java.util.Set; - -import net.sf.cglib.proxy.Callback; -import net.sf.cglib.proxy.CallbackFilter; -import net.sf.cglib.proxy.Enhancer; -import net.sf.cglib.proxy.Factory; -import net.sf.cglib.proxy.LazyLoader; -import net.sf.cglib.proxy.MethodInterceptor; -import net.sf.cglib.proxy.MethodProxy; - -/** - * This class generates JDBC proxy classes using CGLIB bytecode generated - * implementations. This factory's proxies are more efficient than JdbcJavaProxyFactory - * but less efficient than JdbcJavassistProxyFactory. - * - * @author Brett Wooldridge - */ -public class CglibProxyFactory implements ProxyFactory { - - private Class proxyConnectionClass; - private Class proxyStatementClass; - private Class proxyCallableStatementClass; - private Class proxyPreparedStatementClass; - private Class proxyResultSetClass; - - CglibProxyFactory() { - proxyConnectionClass = createProxyConnectionClass(); - proxyStatementClass = createProxyStatementClass(); - proxyCallableStatementClass = createProxyCallableStatementClass(); - proxyPreparedStatementClass = createProxyPreparedStatementClass(); - proxyResultSetClass = createProxyResultSetClass(); - } - - /** {@inheritDoc} */ - public Connection getProxyConnection(HikariPool parentPool, Connection connection) { - ConnectionProxy methodInterceptor = new ConnectionProxy(parentPool, connection); - Interceptor interceptor = new Interceptor(methodInterceptor); - FastDispatcher fastDispatcher = new FastDispatcher(connection); - - try { - Connection connectionCglibProxy = proxyConnectionClass.newInstance(); - ((Factory) connectionCglibProxy).setCallbacks(new Callback[] { fastDispatcher, interceptor }); - return connectionCglibProxy; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - /** {@inheritDoc} */ - public Statement getProxyStatement(ConnectionProxy ConnectionProxy, Statement statement) { - StatementProxy methodInterceptor = new StatementProxy(ConnectionProxy, statement); - Interceptor interceptor = new Interceptor(methodInterceptor); - FastDispatcher fastDispatcher = new FastDispatcher(statement); - - try { - Statement statementCglibProxy = proxyStatementClass.newInstance(); - ((Factory) statementCglibProxy).setCallbacks(new Callback[] { fastDispatcher, interceptor }); - return statementCglibProxy; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - /** {@inheritDoc} */ - public CallableStatement getProxyCallableStatement(ConnectionProxy ConnectionProxy, CallableStatement statement) { - CallableStatementProxy methodInterceptor = new CallableStatementProxy(ConnectionProxy, statement); - Interceptor interceptor = new Interceptor(methodInterceptor); - FastDispatcher fastDispatcher = new FastDispatcher(statement); - - try { - CallableStatement statementCglibProxy = proxyCallableStatementClass.newInstance(); - ((Factory) statementCglibProxy).setCallbacks(new Callback[] { fastDispatcher, interceptor }); - return statementCglibProxy; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - /** {@inheritDoc} */ - public PreparedStatement getProxyPreparedStatement(ConnectionProxy ConnectionProxy, PreparedStatement statement) { - PreparedStatementProxy methodInterceptor = new PreparedStatementProxy(ConnectionProxy, statement); - Interceptor interceptor = new Interceptor(methodInterceptor); - FastDispatcher fastDispatcher = new FastDispatcher(statement); - - try { - PreparedStatement statementCglibProxy = proxyPreparedStatementClass.newInstance(); - ((Factory) statementCglibProxy).setCallbacks(new Callback[] { fastDispatcher, interceptor }); - return statementCglibProxy; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - /** {@inheritDoc} */ - public ResultSet getProxyResultSet(Statement statement, ResultSet resultSet) { - ResultSetProxy methodInterceptor = new ResultSetProxy(statement, resultSet); - Interceptor interceptor = new Interceptor(methodInterceptor); - FastDispatcher fastDispatcher = new FastDispatcher(resultSet); - - try { - ResultSet resultSetCglibProxy = proxyResultSetClass.newInstance(); - ((Factory) resultSetCglibProxy).setCallbacks(new Callback[] { fastDispatcher, interceptor }); - return resultSetCglibProxy; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - // --------------------------------------------------------------- - // Generate CGLIB Proxy Classes - // --------------------------------------------------------------- - - @SuppressWarnings("unchecked") - private Class createProxyConnectionClass() { - Set> interfaces = ClassLoaderUtils.getAllInterfaces(Connection.class); - interfaces.add(IHikariConnectionProxy.class); - - Enhancer enhancer = new Enhancer(); - enhancer.setInterfaces(interfaces.toArray(new Class[0])); - enhancer.setCallbackTypes(new Class[] {FastDispatcher.class, Interceptor.class} ); - enhancer.setCallbackFilter(new InterceptorFilter(new ConnectionProxy())); - return enhancer.createClass(); - } - - @SuppressWarnings("unchecked") - private Class createProxyPreparedStatementClass() { - Set> interfaces = ClassLoaderUtils.getAllInterfaces(PreparedStatement.class); - - Enhancer enhancer = new Enhancer(); - enhancer.setInterfaces(interfaces.toArray(new Class[0])); - enhancer.setCallbackTypes(new Class[] {FastDispatcher.class, Interceptor.class} ); - enhancer.setCallbackFilter(new InterceptorFilter(new PreparedStatementProxy())); - return enhancer.createClass(); - } - - @SuppressWarnings("unchecked") - private Class createProxyStatementClass() { - Set> interfaces = ClassLoaderUtils.getAllInterfaces(Statement.class); - - Enhancer enhancer = new Enhancer(); - enhancer.setInterfaces(interfaces.toArray(new Class[0])); - enhancer.setCallbackTypes(new Class[] {FastDispatcher.class, Interceptor.class} ); - enhancer.setCallbackFilter(new InterceptorFilter(new StatementProxy())); - return enhancer.createClass(); - } - - @SuppressWarnings("unchecked") - private Class createProxyCallableStatementClass() { - Set> interfaces = ClassLoaderUtils.getAllInterfaces(CallableStatement.class); - - Enhancer enhancer = new Enhancer(); - enhancer.setInterfaces(interfaces.toArray(new Class[0])); - enhancer.setCallbackTypes(new Class[] {FastDispatcher.class, Interceptor.class} ); - enhancer.setCallbackFilter(new InterceptorFilter(new CallableStatementProxy())); - return enhancer.createClass(); - } - - @SuppressWarnings("unchecked") - private Class createProxyResultSetClass() { - Set> interfaces = ClassLoaderUtils.getAllInterfaces(ResultSet.class); - - Enhancer enhancer = new Enhancer(); - enhancer.setInterfaces(interfaces.toArray(new Class[0])); - enhancer.setCallbackTypes(new Class[] {FastDispatcher.class, Interceptor.class} ); - enhancer.setCallbackFilter(new InterceptorFilter(new ResultSetProxy())); - return enhancer.createClass(); - } - - // --------------------------------------------------------------- - // CGLIB Classes - // --------------------------------------------------------------- - - static class FastDispatcher implements LazyLoader { - private Object delegate; - - public FastDispatcher(Object delegate) { - this.delegate = delegate; - } - - public Object loadObject() throws Exception { - return delegate; - } - } - - static class Interceptor implements MethodInterceptor { - private HikariProxyBase interceptor; - - public Interceptor(HikariProxyBase interceptor) { - this.interceptor = interceptor; - } - - public Object intercept(Object enhanced, Method method, Object[] args, MethodProxy fastProxy) throws Throwable { - interceptor.proxy = enhanced; - return interceptor.invoke(interceptor, method, args); - } - } - - static class InterceptorFilter implements CallbackFilter { - private Map methodMap; - - public InterceptorFilter(HikariProxyBase proxyClass) { - methodMap = proxyClass.getMethodMap(); - } - - public int accept(Method method) { - if (methodMap.containsKey(HikariProxyBase.getMethodKey(method))) { - // Use the Interceptor - return 1; - } - - // Use the FastDispatcher - return 0; - } - } -} \ No newline at end of file