Refactor interceptor instantiation a bit
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 11 Dec 2008 05:17:19 +0000 (05:17 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 11 Dec 2008 05:17:19 +0000 (05:17 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@725584 13f79535-47bb-0310-9956-ffa450edef68

modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java

index d9240a2..b74dfee 100644 (file)
@@ -202,11 +202,10 @@ public class ConnectionPool {
             PoolProperties.InterceptorDefinition[] proxies = getPoolProperties().getJdbcInterceptorsAsArray();
             for (int i=proxies.length-1; i>=0; i--) {
                 try {
-                    JdbcInterceptor interceptor =
-                        (JdbcInterceptor) Class.forName(proxies[i].getClassName(), true, Thread.currentThread().getContextClassLoader()).newInstance(); //should this be the class loader?
+                    JdbcInterceptor interceptor = proxies[i].getInterceptorClass().newInstance();
                     interceptor.setProperties(proxies[i].getProperties());
                     interceptor.setNext(handler);
-                    interceptor.reset(this, con); //initialize
+                    interceptor.reset(this, con);
                     handler = interceptor;
                 }catch(Exception x) {
                     SQLException sx = new SQLException("Unable to instantiate interceptor chain.");
index c3953cf..7c04f8a 100644 (file)
@@ -431,7 +431,7 @@ public class PoolProperties {
     public static class InterceptorDefinition {
         protected String className;
         protected List<InterceptorProperty> properties = new ArrayList<InterceptorProperty>();
-
+        protected volatile Class clazz = null;
         public InterceptorDefinition(String className) {
             this.className = className;
         }
@@ -451,6 +451,13 @@ public class PoolProperties {
         public List<InterceptorProperty> getProperties() {
             return properties;
         }
+        
+        public Class<? extends JdbcInterceptor> getInterceptorClass() throws ClassNotFoundException {
+            if (clazz==null) {
+                clazz = Class.forName(getClassName(), true, JdbcInterceptor.class.getClassLoader());
+            }
+            return clazz;
+        }
     } 
     
     public static class InterceptorProperty {