From d0b9c491c3132832e2c07f48430abad54e5cacd2 Mon Sep 17 00:00:00 2001 From: fhanik Date: Mon, 24 Nov 2008 20:33:17 +0000 Subject: [PATCH] implement useEquals for the connection pool itself, does not apply to interceptors, they can manage that on their own git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@720280 13f79535-47bb-0310-9956-ffa450edef68 --- modules/jdbc-pool/doc/jdbc-pool.xml | 6 +++++- .../java/org/apache/tomcat/jdbc/pool/ConnectionPool.java | 2 +- .../java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java | 10 +++++++++- .../java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java | 4 ++++ .../java/org/apache/tomcat/jdbc/pool/PoolProperties.java | 11 +++++++++++ .../java/org/apache/tomcat/jdbc/pool/ProxyConnection.java | 9 +++++---- 6 files changed, 35 insertions(+), 7 deletions(-) diff --git a/modules/jdbc-pool/doc/jdbc-pool.xml b/modules/jdbc-pool/doc/jdbc-pool.xml index 9b67fa4a4..40ec6b34d 100644 --- a/modules/jdbc-pool/doc/jdbc-pool.xml +++ b/modules/jdbc-pool/doc/jdbc-pool.xml @@ -324,7 +324,11 @@ implementation for the list of the idle connections. The default value is false.

- + +

(boolean) Set to true if you wish the ProxyConnection class to use String.equals instead of + == when comparing method names. This property does not apply to added interceptors as those are configured individually. + The default value is false. +

diff --git a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java index c345ab910..bcb6cc50f 100644 --- a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java +++ b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java @@ -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--) { diff --git a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java index 0d2753e5e..d319d3ad3 100644 --- a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java +++ b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java @@ -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); diff --git a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java index 78b266341..c5bb1fc12 100644 --- a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java +++ b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java @@ -316,5 +316,9 @@ public class DataSourceProxy { throw new RuntimeException(x); } } + + public void setUseEquals(boolean useEquals) { + this.getPoolProperties().setUseEquals(useEquals); + } } diff --git a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java index 5ce697002..57a0d1bf8 100644 --- a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java +++ b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java @@ -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 properties = new ArrayList(); @@ -465,4 +468,12 @@ public class PoolProperties { } } + public boolean isUseEquals() { + return useEquals; + } + + public void setUseEquals(boolean useEquals) { + this.useEquals = useEquals; + } + } diff --git a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ProxyConnection.java b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ProxyConnection.java index 5c7236738..8d14279b4 100644 --- a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ProxyConnection.java +++ b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ProxyConnection.java @@ -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."); -- 2.11.0