Author: kfujino Date: Thu Mar 30 05:28:21 2017 New Revision: 1789433 URL: http://svn.apache.org/viewvc?rev=1789433&view=rev Log: Refactor the creating a constructor for a proxy class to reduce duplicate code.
Modified: tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/StatementFacade.java tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractCreateStatementInterceptor.java tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractQueryReport.java tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementDecoratorInterceptor.java tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml Modified: tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/StatementFacade.java URL: http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/StatementFacade.java?rev=1789433&r1=1789432&r2=1789433&view=diff ============================================================================== --- tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/StatementFacade.java (original) +++ tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/StatementFacade.java Thu Mar 30 05:28:21 2017 @@ -35,12 +35,6 @@ public class StatementFacade extends Abs private static final Log logger = LogFactory.getLog(StatementFacade.class); - /** - * the constructors that are used to create statement proxies - */ - protected static final Constructor<?>[] constructors - = new Constructor[AbstractCreateStatementInterceptor.STATEMENT_TYPE_COUNT]; - protected StatementFacade(JdbcInterceptor interceptor) { setUseEquals(interceptor.isUseEquals()); setNext(interceptor); @@ -83,25 +77,6 @@ public class StatementFacade extends Abs } /** - * Creates a constructor for a proxy class, if one doesn't already exist - * - * @param idx - * - the index of the constructor - * @param clazz - * - the interface that the proxy will implement - * @return - returns a constructor used to create new instances - * @throws NoSuchMethodException Constructor not found - */ - protected Constructor<?> getConstructor(int idx, Class<?> clazz) throws NoSuchMethodException { - if (constructors[idx] == null) { - Class<?> proxyClass = Proxy.getProxyClass(StatementFacade.class.getClassLoader(), - new Class[] { clazz }); - constructors[idx] = proxyClass.getConstructor(new Class[] { InvocationHandler.class }); - } - return constructors[idx]; - } - - /** * Class to measure query execute time. */ protected class StatementProxy implements InvocationHandler { Modified: tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractCreateStatementInterceptor.java URL: http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractCreateStatementInterceptor.java?rev=1789433&r1=1789432&r2=1789433&view=diff ============================================================================== --- tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractCreateStatementInterceptor.java (original) +++ tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractCreateStatementInterceptor.java Thu Mar 30 05:28:21 2017 @@ -16,7 +16,10 @@ */ package org.apache.tomcat.jdbc.pool.interceptor; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; +import java.lang.reflect.Proxy; import org.apache.tomcat.jdbc.pool.ConnectionPool; import org.apache.tomcat.jdbc.pool.JdbcInterceptor; @@ -46,6 +49,12 @@ public abstract class AbstractCreateSta protected static final String[] EXECUTE_TYPES = {EXECUTE, EXECUTE_QUERY, EXECUTE_UPDATE, EXECUTE_BATCH}; + /** + * the constructors that are used to create statement proxies + */ + protected static final Constructor<?>[] constructors = + new Constructor[AbstractCreateStatementInterceptor.STATEMENT_TYPE_COUNT]; + public AbstractCreateStatementInterceptor() { super(); } @@ -73,6 +82,25 @@ public abstract class AbstractCreateSta } /** + * Creates a constructor for a proxy class, if one doesn't already exist + * + * @param idx + * - the index of the constructor + * @param clazz + * - the interface that the proxy will implement + * @return - returns a constructor used to create new instances + * @throws NoSuchMethodException Constructor not found + */ + protected Constructor<?> getConstructor(int idx, Class<?> clazz) throws NoSuchMethodException { + if (constructors[idx] == null) { + Class<?> proxyClass = Proxy.getProxyClass(AbstractCreateStatementInterceptor.class.getClassLoader(), + new Class[] { clazz }); + constructors[idx] = proxyClass.getConstructor(new Class[] { InvocationHandler.class }); + } + return constructors[idx]; + } + + /** * This method will be invoked after a successful statement creation. This method can choose to return a wrapper * around the statement or return the statement itself. * If this method returns a wrapper then it should return a wrapper object that implements one of the following interfaces. Modified: tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractQueryReport.java URL: http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractQueryReport.java?rev=1789433&r1=1789432&r2=1789433&view=diff ============================================================================== --- tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractQueryReport.java (original) +++ tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractQueryReport.java Thu Mar 30 05:28:21 2017 @@ -21,7 +21,6 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.lang.reflect.Proxy; import java.sql.CallableStatement; import java.sql.PreparedStatement; import java.sql.SQLException; @@ -43,13 +42,6 @@ public abstract class AbstractQueryRepor */ protected long threshold = 1000; //don't report queries less than this - /** - * the constructors that are used to create statement proxies - */ - protected static final Constructor<?>[] constructors = - new Constructor[AbstractCreateStatementInterceptor.STATEMENT_TYPE_COUNT]; - - public AbstractQueryReport() { super(); } @@ -144,21 +136,6 @@ public abstract class AbstractQueryRepor } /** - * Creates a constructor for a proxy class, if one doesn't already exist - * @param idx - the index of the constructor - * @param clazz - the interface that the proxy will implement - * @return - returns a constructor used to create new instances - * @throws NoSuchMethodException Constructor not found - */ - protected Constructor<?> getConstructor(int idx, Class<?> clazz) throws NoSuchMethodException { - if (constructors[idx]==null) { - Class<?> proxyClass = Proxy.getProxyClass(SlowQueryReport.class.getClassLoader(), new Class[] {clazz}); - constructors[idx] = proxyClass.getConstructor(new Class[] { InvocationHandler.class }); - } - return constructors[idx]; - } - - /** * Creates a statement interceptor to monitor query response times */ @Override Modified: tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementDecoratorInterceptor.java URL: http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementDecoratorInterceptor.java?rev=1789433&r1=1789432&r2=1789433&view=diff ============================================================================== --- tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementDecoratorInterceptor.java (original) +++ tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementDecoratorInterceptor.java Thu Mar 30 05:28:21 2017 @@ -47,11 +47,6 @@ public class StatementDecoratorIntercept protected static final String[] RESULTSET_TYPES = {EXECUTE_QUERY, GET_GENERATED_KEYS, GET_RESULTSET}; /** - * the constructors that are used to create statement proxies - */ - protected static final Constructor<?>[] constructors = new Constructor[AbstractCreateStatementInterceptor.STATEMENT_TYPE_COUNT]; - - /** * the constructor to create the resultSet proxies */ protected static Constructor<?> resultSetConstructor = null; @@ -61,25 +56,6 @@ public class StatementDecoratorIntercept // nothing to do } - /** - * Creates a constructor for a proxy class, if one doesn't already exist - * - * @param idx - * - the index of the constructor - * @param clazz - * - the interface that the proxy will implement - * @return - returns a constructor used to create new instances - * @throws NoSuchMethodException Constructor not found - */ - protected Constructor<?> getConstructor(int idx, Class<?> clazz) throws NoSuchMethodException { - if (constructors[idx] == null) { - Class<?> proxyClass = Proxy.getProxyClass(StatementDecoratorInterceptor.class.getClassLoader(), - new Class[] { clazz }); - constructors[idx] = proxyClass.getConstructor(new Class[] { InvocationHandler.class }); - } - return constructors[idx]; - } - protected Constructor<?> getResultSetConstructor() throws NoSuchMethodException { if (resultSetConstructor == null) { Class<?> proxyClass = Proxy.getProxyClass(StatementDecoratorInterceptor.class.getClassLoader(), Modified: tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml?rev=1789433&r1=1789432&r2=1789433&view=diff ============================================================================== --- tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml Thu Mar 30 05:28:21 2017 @@ -69,6 +69,14 @@ </fix> </changelog> </subsection> + <subsection name="jdbc-pool"> + <changelog> + <scode> + Refactor the creating a constructor for a proxy class to reduce + duplicate code. (kfujino) + </scode> + </changelog> + </subsection> <subsection name="Other"> <changelog> <fix> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org