implement useEquals for the connection pool itself, does not apply to interceptors...
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 24 Nov 2008 20:33:17 +0000 (20:33 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 24 Nov 2008 20:33:17 +0000 (20:33 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@720280 13f79535-47bb-0310-9956-ffa450edef68

modules/jdbc-pool/doc/jdbc-pool.xml
modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java
modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java
modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java
modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ProxyConnection.java

index 9b67fa4..40ec6b3 100644 (file)
          implementation for the list of the idle connections. The default value is <code>false</code>.
       </p>
     </attribute>
-
+    <attribute name="useEquals" required="false">
+      <p>(boolean) Set to true if you wish the <code>ProxyConnection</code> class to use <code>String.equals</code> instead of 
+         <code>==</code> when comparing method names. This property does not apply to added interceptors as those are configured individually.
+         The default value is <code>false</code>.
+      </p>   
   </attributes>  
   </subsection>
 </section>
index c345ab9..bcb6cc5 100644 (file)
@@ -131,7 +131,7 @@ public class ConnectionPool {
         JdbcInterceptor handler = con.getHandler();
         if (handler==null) {
             //build the proxy handler
-            handler = new ProxyConnection(this,con);
+            handler = new ProxyConnection(this,con,getPoolProperties().isUseEquals());
             //set up the interceptor chain
             PoolProperties.InterceptorDefinition[] proxies = getPoolProperties().getJdbcInterceptorsAsArray();
             for (int i=proxies.length-1; i>=0; i--) {
index 0d2753e..d319d3a 100644 (file)
@@ -102,6 +102,8 @@ public class DataSourceFactory implements ObjectFactory {
     protected final static String PROP_JMX_ENABLED = "jmxEnabled";
     protected final static String PROP_FAIR_QUEUE = "fairQueue";
     
+    protected static final String PROP_USE_EQUALS = "useEquals";
+    
     public static final int UNKNOWN_TRANSACTIONISOLATION = -1;
 
 
@@ -138,7 +140,8 @@ public class DataSourceFactory implements ObjectFactory {
         PROP_INITSQL,
         PROP_INTERCEPTORS,
         PROP_JMX_ENABLED,
-        PROP_FAIR_QUEUE
+        PROP_FAIR_QUEUE,
+        PROP_USE_EQUALS
     };
 
     // -------------------------------------------------- ObjectFactory Methods
@@ -389,6 +392,11 @@ public class DataSourceFactory implements ObjectFactory {
             dataSource.getPoolProperties().setFairQueue(Boolean.parseBoolean(value));
         }
         
+        value = properties.getProperty(PROP_USE_EQUALS);
+        if (value != null) {
+            dataSource.getPoolProperties().setUseEquals(Boolean.parseBoolean(value));
+        }
+        
 
         // Return the configured DataSource instance
         DataSource ds = getDataSource(dataSource);
index 78b2663..c5bb1fc 100644 (file)
@@ -316,5 +316,9 @@ public class DataSourceProxy  {
             throw new RuntimeException(x);
         }
     }
+    
+    public void setUseEquals(boolean useEquals) {
+        this.getPoolProperties().setUseEquals(useEquals);
+    }
 
 }
index 5ce6970..57a0d1b 100644 (file)
@@ -63,6 +63,7 @@ public class PoolProperties {
     protected boolean testOnConnect =false;
     private String jdbcInterceptors=null;
     private boolean fairQueue = false;
+    private boolean useEquals = false;
 
     private InterceptorDefinition[] interceptors = null;
     
@@ -425,6 +426,8 @@ public class PoolProperties {
         return result;
     }
     
+    
+    
     public static class InterceptorDefinition {
         protected String className;
         protected List<InterceptorProperty> properties = new ArrayList<InterceptorProperty>();
@@ -465,4 +468,12 @@ public class PoolProperties {
         }
     }
 
+    public boolean isUseEquals() {
+        return useEquals;
+    }
+
+    public void setUseEquals(boolean useEquals) {
+        this.useEquals = useEquals;
+    }
+
 }
index 5c72367..8d14279 100644 (file)
@@ -44,9 +44,10 @@ public class ProxyConnection extends JdbcInterceptor {
         this.pool = pool;
     }
 
-    protected ProxyConnection(ConnectionPool parent, PooledConnection con) throws SQLException {
+    protected ProxyConnection(ConnectionPool parent, PooledConnection con, boolean useEquals) throws SQLException {
         pool = parent;
         connection = con;
+        setUseEquals(useEquals);
     }
 
     public void reset(ConnectionPool parent, PooledConnection con) {
@@ -68,16 +69,16 @@ public class ProxyConnection extends JdbcInterceptor {
     }
 
     public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
-        if (ISCLOSED_VAL==method.getName()) {
+        if (compare(ISCLOSED_VAL,method)) {
             return isClosed();
         }
-        if (CLOSE_VAL==method.getName()) {
+        if (compare(CLOSE_VAL,method)) {
             if (isClosed()) return null; //noop for already closed.
             PooledConnection poolc = this.connection;
             this.connection = null;
             pool.returnConnection(poolc);
             return null;
-        } else if (TOSTRING_VAL==method.getName()) {
+        } else if (compare(TOSTRING_VAL,method)) {
             return this.toString();
         }
         if (isClosed()) throw new SQLException("Connection has already been closed.");