You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by kf...@apache.org on 2017/03/30 05:31:22 UTC
svn commit: r1789435 - in /tomcat/tc7.0.x/trunk:
modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/
modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/
webapps/docs/
Author: kfujino
Date: Thu Mar 30 05:31:22 2017
New Revision: 1789435
URL: http://svn.apache.org/viewvc?rev=1789435&view=rev
Log:
Refactor the creating a constructor for a proxy class to reduce duplicate code.
Modified:
tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/StatementFacade.java
tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractCreateStatementInterceptor.java
tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractQueryReport.java
tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementDecoratorInterceptor.java
tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
Modified: tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/StatementFacade.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/StatementFacade.java?rev=1789435&r1=1789434&r2=1789435&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/StatementFacade.java (original)
+++ tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/StatementFacade.java Thu Mar 30 05:31:22 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/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractCreateStatementInterceptor.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractCreateStatementInterceptor.java?rev=1789435&r1=1789434&r2=1789435&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractCreateStatementInterceptor.java (original)
+++ tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractCreateStatementInterceptor.java Thu Mar 30 05:31:22 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;
@@ -47,6 +50,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();
}
@@ -74,6 +83,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/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractQueryReport.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractQueryReport.java?rev=1789435&r1=1789434&r2=1789435&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractQueryReport.java (original)
+++ tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractQueryReport.java Thu Mar 30 05:31:22 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;
@@ -44,13 +43,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();
}
@@ -145,21 +137,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
- */
- 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/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementDecoratorInterceptor.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementDecoratorInterceptor.java?rev=1789435&r1=1789434&r2=1789435&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementDecoratorInterceptor.java (original)
+++ tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementDecoratorInterceptor.java Thu Mar 30 05:31:22 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
- */
- 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/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1789435&r1=1789434&r2=1789435&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Thu Mar 30 05:31:22 2017
@@ -75,6 +75,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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org