From 539ca5f606926998a2194794fc36367589b8b6bc Mon Sep 17 00:00:00 2001
From: fhanik
Date: Mon, 13 Jul 2009 22:18:17 +0000
Subject: [PATCH] Add tons of javadoc Remove the finalizers, they behave way
differently in the new JDK, so let the programmer be responsible for closures
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@793732 13f79535-47bb-0310-9956-ffa450edef68
---
modules/jdbc-pool/.classpath | 2 +-
modules/jdbc-pool/build.properties.default | 6 +-
modules/jdbc-pool/build.xml | 25 +-
modules/jdbc-pool/doc/jdbc-pool.xml | 14 +-
.../apache/tomcat/jdbc/pool/ConnectionPool.java | 20 +-
.../org/apache/tomcat/jdbc/pool/DataSource.java | 439 +-------------
.../apache/tomcat/jdbc/pool/DataSourceFactory.java | 12 +-
.../apache/tomcat/jdbc/pool/DataSourceProxy.java | 652 ++++++++++++++++++++-
.../apache/tomcat/jdbc/pool/FairBlockingQueue.java | 51 +-
.../apache/tomcat/jdbc/pool/PoolProperties.java | 358 ++++++++++-
.../apache/tomcat/jdbc/pool/PooledConnection.java | 8 +-
.../jdbc/pool/interceptor/ConnectionState.java | 4 +-
.../tomcat/jdbc/pool/jmx/ConnectionPool.java | 416 ++++++++++---
.../tomcat/jdbc/pool/jmx/ConnectionPoolMBean.java | 75 +--
.../apache/tomcat/jdbc/test/CreateTestTable.java | 6 +
.../apache/tomcat/jdbc/test/DefaultProperties.java | 2 -
.../apache/tomcat/jdbc/test/DefaultTestCase.java | 9 +-
.../tomcat/jdbc/test/SimplePOJOAsyncExample.java | 3 +-
.../apache/tomcat/jdbc/test/SimplePOJOExample.java | 3 +-
19 files changed, 1460 insertions(+), 645 deletions(-)
diff --git a/modules/jdbc-pool/.classpath b/modules/jdbc-pool/.classpath
index d6095470a..a0b71e1d0 100644
--- a/modules/jdbc-pool/.classpath
+++ b/modules/jdbc-pool/.classpath
@@ -8,6 +8,6 @@
-
+
diff --git a/modules/jdbc-pool/build.properties.default b/modules/jdbc-pool/build.properties.default
index 1c5d9f461..d9becb742 100644
--- a/modules/jdbc-pool/build.properties.default
+++ b/modules/jdbc-pool/build.properties.default
@@ -48,7 +48,7 @@ testdb.username=root
testdb.password=password
# H2
-testdb.url=jdbc:h2:~/.h2/test;QUERY_TIMEOUT=0;DB_CLOSE_ON_EXIT=FALSE
+testdb.url=jdbc:h2:~/.h2/test;QUERY_TIMEOUT=0;DB_CLOSE_ON_EXIT=TRUE;LOCK_TIMEOUT=50000;DEFAULT_LOCK_TIMEOUT=50000
testdb.driverClassName=org.h2.Driver
testdb.validationQuery=SELECT 1
@@ -97,5 +97,5 @@ derby.loc=http://archive.apache.org/dist/db/derby/db-derby-10.5.1.1/db-derby-10.
derby.jar=${derby.home}/lib/derby.jar
h2.home=${base.path}/h2
-h2.loc=http://www.h2database.com/h2-2009-06-01.zip
-h2.jar=${h2.home}/bin/h2-1.1.114.jar
+h2.loc=http://www.h2database.com/h2-2009-06-27.zip
+h2.jar=${h2.home}/bin/h2-1.1.115.jar
diff --git a/modules/jdbc-pool/build.xml b/modules/jdbc-pool/build.xml
index b8a89847c..8f100749a 100644
--- a/modules/jdbc-pool/build.xml
+++ b/modules/jdbc-pool/build.xml
@@ -86,6 +86,7 @@
+
Creating test table for test purposes.
+
@@ -405,7 +407,7 @@
-
+
Performance and fairness tests.
@@ -445,5 +447,26 @@
+
+
+ Testing:${test}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/modules/jdbc-pool/doc/jdbc-pool.xml b/modules/jdbc-pool/doc/jdbc-pool.xml
index c0a720a24..0bdef8277 100644
--- a/modules/jdbc-pool/doc/jdbc-pool.xml
+++ b/modules/jdbc-pool/doc/jdbc-pool.xml
@@ -227,8 +227,10 @@
(boolean) The indication of whether objects will be validated before being borrowed from the pool.
- If the object fails to validate, it will be dropped from the pool, and we will attempt to borrow another.
- NOTE - for a true value to have any effect, the validationQuery parameter must be set to a non-null string.
+ If the object fails to validate, it will be dropped from the pool, and we will attempt to borrow another.
+ NOTE - for a true value to have any effect, the validationQuery parameter must be set to a non-null string.
+ Default value is false
+ In order to have a more efficient validation, see validationInterval
Default value is false
@@ -275,7 +277,8 @@
(boolean) Property not used. Access can be achieved by calling unwrap on the pooled connection.
- see javax.sql.DataSource interface, or call getConnection through reflection.
+ see javax.sql.DataSource interface, or call getConnection through reflection or
+ or cast the object as javax.sql.PooledConnection
@@ -415,8 +418,9 @@
Abstract base class for all interceptors, can not be instantiated.
- (String as boolean) A custom query to be run when a connection is first created.
- The default value is false.
+
(String as boolean) Set to true if you wish the interceptor 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 53a765cfc..34a6c7226 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
@@ -75,7 +75,7 @@ public class ConnectionPool {
* All the information about the connection pool
* These are the properties the pool got instantiated with
*/
- private PoolProperties poolProperties;
+ private PoolConfiguration poolProperties;
/**
* Contains all the connections that are in use
@@ -129,7 +129,7 @@ public class ConnectionPool {
* @param prop PoolProperties - all the properties for this connection pool
* @throws SQLException
*/
- public ConnectionPool(PoolProperties prop) throws SQLException {
+ public ConnectionPool(PoolConfiguration prop) throws SQLException {
//setup quick access variables and pools
init(prop);
}
@@ -188,7 +188,7 @@ public class ConnectionPool {
* @return PoolProperties
*
*/
- public PoolProperties getPoolProperties() {
+ public PoolConfiguration getPoolProperties() {
return this.poolProperties;
}
@@ -312,12 +312,12 @@ public class ConnectionPool {
*/
@Override
protected void finalize() throws Throwable {
- Runnable closer = new Runnable() {
- public void run() {
- close(true);
- }
- };
- this.cancellator.execute(closer);
+// Runnable closer = new Runnable() {
+// public void run() {
+// close(true);
+// }
+// };
+// this.cancellator.execute(closer);
}
/**
@@ -373,7 +373,7 @@ public class ConnectionPool {
* @param properties PoolProperties - properties used to initialize the pool with
* @throws SQLException if initialization fails
*/
- protected void init(PoolProperties properties) throws SQLException {
+ protected void init(PoolConfiguration properties) throws SQLException {
poolProperties = properties;
//make space for 10 extra in case we flow over a bit
busy = new ArrayBlockingQueue(properties.getMaxActive(),false);
diff --git a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSource.java b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSource.java
index dd818596c..c2050205e 100644
--- a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSource.java
+++ b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSource.java
@@ -16,7 +16,6 @@
*/
package org.apache.tomcat.jdbc.pool;
-import java.io.PrintWriter;
import java.lang.management.ManagementFactory;
import java.sql.SQLException;
import java.util.Hashtable;
@@ -28,27 +27,35 @@ import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
-import org.apache.tomcat.jdbc.pool.jmx.ConnectionPoolMBean;
+import org.apache.tomcat.jdbc.pool.PoolProperties.InterceptorDefinition;
/**
* A DataSource that can be instantiated through IoC and implements the DataSource interface
- * since the DataSourceProxy is used as a generic proxy
+ * since the DataSourceProxy is used as a generic proxy.
+ * The DataSource simply wraps a {@link ConnectionPool} in order to provide a standard interface to the user.
* @author Filip Hanik
* @version 1.0
*/
public class DataSource extends DataSourceProxy implements MBeanRegistration,javax.sql.DataSource, org.apache.tomcat.jdbc.pool.jmx.ConnectionPoolMBean {
+ /**
+ * Constructor for reflection only. A default set of pool properties will be created.
+ */
public DataSource() {
super();
}
-
- public DataSource(PoolProperties poolProperties) {
+
+ /**
+ * Constructs a DataSource object wrapping a connection
+ * @param poolProperties
+ */
+ public DataSource(PoolConfiguration poolProperties) {
super(poolProperties);
}
//===============================================================================
-// Register the actual pool itself under the tomcat.jdbc domain
+// JMX Operations - Register the actual pool itself under the tomcat.jdbc domain
//===============================================================================
protected volatile ObjectName oname = null;
@@ -122,6 +129,9 @@ public class DataSource extends DataSourceProxy implements MBeanRegistration,jav
}
}
+ /**
+ *
+ */
protected void unregisterJmx() {
try {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
@@ -132,422 +142,5 @@ public class DataSource extends DataSourceProxy implements MBeanRegistration,jav
}
}
-//===============================================================================
-// Expose JMX attributes through Tomcat's dynamic reflection
-//===============================================================================
- /**
- * Forces an abandon check on the connection pool.
- * If connections that have been abandoned exists, they will be closed during this run
- */
- public void checkAbandoned() {
- try {
- createPool().checkAbandoned();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- /**
- * Forces a check for downsizing the idle connections
- */
- public void checkIdle() {
- try {
- createPool().checkIdle();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- /**
- * @return number of connections in use by the application
- */
- public int getActive() {
- try {
- return createPool().getActive();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- /**
- * @return number of connections in use by the application
- * {@link DataSource#getActive()}
- */
- public int getNumActive() {
- return getActive();
- }
-
- /**
- * @return number of threads waiting for a connection
- */
- public int getWaitCount() {
- try {
- return createPool().getWaitCount();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- /**
- * NOT USED ANYWHERE
- * @return nothing
- */
- public String getConnectionProperties() {
- try {
- return createPool().getPoolProperties().getConnectionProperties();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- /**
- * @return connection properties passed into the JDBC Driver upon connect
- */
- public Properties getDbProperties() {
- try {
- return createPool().getPoolProperties().getDbProperties();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- /**
- * @return the configured default catalog
- */
- public String getDefaultCatalog() {
- try {
- return createPool().getPoolProperties().getDefaultCatalog();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- /**
- * @return the configured default isolation level
- */
- public int getDefaultTransactionIsolation() {
- try {
- return createPool().getPoolProperties().getDefaultTransactionIsolation();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- /**
- * @return the configured driver class name
- */
- public String getDriverClassName() {
- try {
- return createPool().getPoolProperties().getDriverClassName();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- /**
- * @return the number of established but idle connections
- */
- public int getIdle() {
- try {
- return createPool().getIdle();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- /**
- * {@link #getIdle()}
- */
- public int getNumIdle() {
- return getIdle();
- }
-
- /**
- * @return the configured number of initial connections
- */
- public int getInitialSize() {
- try {
- return createPool().getPoolProperties().getInitialSize();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- /**
- * @return the configured initialization SQL
- */
- public String getInitSQL() {
- try {
- return createPool().getPoolProperties().getInitSQL();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- /**
- * @return the configuration string for interceptors
- */
- public String getJdbcInterceptors() {
- try {
- return createPool().getPoolProperties().getJdbcInterceptors();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- /**
- * @return the configured number of maximum allowed connections
- */
- public int getMaxActive() {
- try {
- return createPool().getPoolProperties().getMaxActive();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- /**
- * @return the configured number of maximum idle connections
- */
- public int getMaxIdle() {
- try {
- return createPool().getPoolProperties().getMaxIdle();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- /**
- * @return the configured maximum wait time in milliseconds if a connection is not available
- */
- public int getMaxWait() {
- try {
- return createPool().getPoolProperties().getMaxWait();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- /**
- * @return the configured idle time, before a connection that is idle can be released
- */
- public int getMinEvictableIdleTimeMillis() {
- try {
- return createPool().getPoolProperties().getMinEvictableIdleTimeMillis();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- /**
- * @return the configured minimum amount of idle connections
- */
- public int getMinIdle() {
- try {
- return createPool().getPoolProperties().getMinIdle();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- /**
- * @return the configured maxAge for a connection.
- * A connection that has been established for longer than this configured value in milliseconds
- * will be closed upon a return
- */
- public long getMaxAge() {
- try {
- return createPool().getPoolProperties().getMaxAge();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- /**
- * @return the name of the pool
- */
- public String getName() {
- try {
- return createPool().getName();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- /**
- * @return the configured value - not used in this implementation
- */
- public int getNumTestsPerEvictionRun() {
- try {
- return createPool().getPoolProperties().getNumTestsPerEvictionRun();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- /**
- * @return DOES NOT RETURN THE PASSWORD, IT WOULD SHOW UP IN JMX
- */
- public String getPassword() {
- return "Password not available as DataSource/JMX operation.";
- }
-
- /**
- * @return the configured remove abandoned timeout in seconds
- */
- public int getRemoveAbandonedTimeout() {
- try {
- return createPool().getPoolProperties().getRemoveAbandonedTimeout();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- /**
- * @return the current size of the pool
- */
- public int getSize() {
- try {
- return createPool().getSize();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- public int getTimeBetweenEvictionRunsMillis() {
- try {
- return createPool().getPoolProperties().getTimeBetweenEvictionRunsMillis();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- public String getUrl() {
- try {
- return createPool().getPoolProperties().getUrl();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- public String getUsername() {
- try {
- return createPool().getPoolProperties().getUsername();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- public long getValidationInterval() {
- try {
- return createPool().getPoolProperties().getValidationInterval();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- public String getValidationQuery() {
- try {
- return createPool().getPoolProperties().getValidationQuery();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- public boolean isAccessToUnderlyingConnectionAllowed() {
- try {
- return createPool().getPoolProperties().isAccessToUnderlyingConnectionAllowed();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- public boolean isDefaultAutoCommit() {
- try {
- return createPool().getPoolProperties().isDefaultAutoCommit();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- public boolean isDefaultReadOnly() {
- try {
- return createPool().getPoolProperties().isDefaultReadOnly();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- public boolean isLogAbandoned() {
- try {
- return createPool().getPoolProperties().isLogAbandoned();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- public boolean isPoolSweeperEnabled() {
- try {
- return createPool().getPoolProperties().isPoolSweeperEnabled();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- public boolean isRemoveAbandoned() {
- try {
- return createPool().getPoolProperties().isRemoveAbandoned();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- public int getAbandonWhenPercentageFull() {
- try {
- return createPool().getPoolProperties().getAbandonWhenPercentageFull();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- public boolean isTestOnBorrow() {
- try {
- return createPool().getPoolProperties().isTestOnBorrow();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- public boolean isTestOnConnect() {
- try {
- return createPool().getPoolProperties().isTestOnConnect();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- public boolean isTestOnReturn() {
- try {
- return createPool().getPoolProperties().isTestOnReturn();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- public boolean isTestWhileIdle() {
- try {
- return createPool().getPoolProperties().isTestWhileIdle();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
-
- public void testIdle() {
- try {
- createPool().testAllIdle();
- }catch (SQLException x) {
- throw new RuntimeException(x);
- }
- }
}
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 30f4fc4d7..25eb9edee 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
@@ -210,8 +210,8 @@ public class DataSourceFactory implements ObjectFactory {
return createDataSource(properties);
}
- public static PoolProperties parsePoolProperties(Properties properties) throws IOException{
- PoolProperties poolProperties = new PoolProperties();
+ public static PoolConfiguration parsePoolProperties(Properties properties) throws IOException{
+ PoolConfiguration poolProperties = new PoolProperties();
String value = null;
value = properties.getProperty(PROP_DEFAULTAUTOCOMMIT);
@@ -442,7 +442,7 @@ public class DataSourceFactory implements ObjectFactory {
* @throws Exception if an error occurs creating the data source
*/
public static DataSource createDataSource(Properties properties) throws Exception {
- PoolProperties poolProperties = DataSourceFactory.parsePoolProperties(properties);
+ PoolConfiguration poolProperties = DataSourceFactory.parsePoolProperties(properties);
org.apache.tomcat.jdbc.pool.DataSource dataSource = new org.apache.tomcat.jdbc.pool.DataSource(poolProperties);
//initialize the pool itself
@@ -466,11 +466,7 @@ public class DataSourceFactory implements ObjectFactory {
* @throws Exception
*/
static protected Properties getProperties(String propText) throws IOException {
- Properties p = new Properties();
- if (propText != null) {
- p.load(new ByteArrayInputStream(propText.replace(';', '\n').getBytes()));
- }
- return p;
+ return PoolProperties.getProperties(propText,null);
}
protected static class DataSourceHandler implements InvocationHandler {
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 e8d761595..9c90fdb97 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
@@ -20,6 +20,7 @@ import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Iterator;
+import java.util.Properties;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
@@ -27,28 +28,34 @@ import java.util.concurrent.TimeUnit;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
+import org.apache.tomcat.jdbc.pool.PoolProperties.InterceptorDefinition;
/**
*
* The DataSource proxy lets us implements methods that don't exist in the current
* compiler JDK but might be methods that are part of a future JDK DataSource interface.
+ *
+ * It's a trick to work around compiler issues when implementing interfaces. For example,
+ * I could put in Java 6 methods of javax.sql.DataSource here, and compile it with JDK 1.5
+ * and still be able to run under Java 6 without getting NoSuchMethodException.
*
* @author Filip Hanik
* @version 1.0
*/
-public class DataSourceProxy {
+public class DataSourceProxy implements PoolConfiguration {
protected static Log log = LogFactory.getLog(DataSourceProxy.class);
protected volatile ConnectionPool pool = null;
- protected PoolProperties poolProperties = null;
+ protected PoolConfiguration poolProperties = null;
public DataSourceProxy() {
this(new PoolProperties());
}
- public DataSourceProxy(PoolProperties poolProperties) {
+ public DataSourceProxy(PoolConfiguration poolProperties) {
+ if (poolProperties == null) throw new NullPointerException("PoolConfiguration can not be null.");
this.poolProperties = poolProperties;
}
@@ -72,7 +79,7 @@ public class DataSourceProxy {
return getConnection();
}
- public PoolProperties getPoolProperties() {
+ public PoolConfiguration getPoolProperties() {
return poolProperties;
}
@@ -130,13 +137,7 @@ public class DataSourceProxy {
return pool;
}
- public String getPoolName() {
- return pool.getName();
- }
-
-
-
public void close() {
close(false);
}
@@ -155,14 +156,14 @@ public class DataSourceProxy {
}
protected void finalize() throws Throwable {
- //terminate the pool?
- ThreadPoolExecutor closer = new ThreadPoolExecutor(0,1,1000,TimeUnit.MILLISECONDS,new LinkedBlockingQueue());
- final Runnable r = new Runnable() {
- public void run(){
- close(true);
- }
- };
- closer.execute(r);
+// //terminate the pool?
+// ThreadPoolExecutor closer = new ThreadPoolExecutor(0,1,1000,TimeUnit.MILLISECONDS,new LinkedBlockingQueue());
+// final Runnable r = new Runnable() {
+// public void run(){
+// close(true);
+// }
+// };
+// closer.execute(r);
}
public int getPoolSize() throws SQLException{
@@ -174,135 +175,265 @@ public class DataSourceProxy {
public String toString() {
return super.toString()+"{"+getPoolProperties()+"}";
}
+
+
+
/*-----------------------------------------------------------------------*/
// PROPERTIES WHEN NOT USED WITH FACTORY
/*------------------------------------------------------------------------*/
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getPoolName() {
+ return pool.getName();
+ }
- public void setPoolProperties(PoolProperties poolProperties) {
+ public void setPoolProperties(PoolConfiguration poolProperties) {
this.poolProperties = poolProperties;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setDriverClassName(String driverClassName) {
this.poolProperties.setDriverClassName(driverClassName);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setInitialSize(int initialSize) {
this.poolProperties.setInitialSize(initialSize);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setInitSQL(String initSQL) {
this.poolProperties.setInitSQL(initSQL);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setLogAbandoned(boolean logAbandoned) {
this.poolProperties.setLogAbandoned(logAbandoned);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setMaxActive(int maxActive) {
this.poolProperties.setMaxActive(maxActive);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setMaxIdle(int maxIdle) {
this.poolProperties.setMaxIdle(maxIdle);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setMaxWait(int maxWait) {
this.poolProperties.setMaxWait(maxWait);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) {
this.poolProperties.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setMinIdle(int minIdle) {
this.poolProperties.setMinIdle(minIdle);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
this.poolProperties.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setPassword(String password) {
this.poolProperties.setPassword(password);
this.poolProperties.getDbProperties().setProperty("password",this.poolProperties.getPassword());
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setRemoveAbandoned(boolean removeAbandoned) {
this.poolProperties.setRemoveAbandoned(removeAbandoned);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setRemoveAbandonedTimeout(int removeAbandonedTimeout) {
this.poolProperties.setRemoveAbandonedTimeout(removeAbandonedTimeout);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setTestOnBorrow(boolean testOnBorrow) {
this.poolProperties.setTestOnBorrow(testOnBorrow);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setTestOnConnect(boolean testOnConnect) {
this.poolProperties.setTestOnConnect(testOnConnect);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setTestOnReturn(boolean testOnReturn) {
this.poolProperties.setTestOnReturn(testOnReturn);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setTestWhileIdle(boolean testWhileIdle) {
this.poolProperties.setTestWhileIdle(testWhileIdle);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis) {
this.poolProperties.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setUrl(String url) {
this.poolProperties.setUrl(url);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setUsername(String username) {
this.poolProperties.setUsername(username);
this.poolProperties.getDbProperties().setProperty("user",getPoolProperties().getUsername());
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setValidationInterval(long validationInterval) {
this.poolProperties.setValidationInterval(validationInterval);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setValidationQuery(String validationQuery) {
this.poolProperties.setValidationQuery(validationQuery);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setJdbcInterceptors(String interceptors) {
this.getPoolProperties().setJdbcInterceptors(interceptors);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setJmxEnabled(boolean enabled) {
this.getPoolProperties().setJmxEnabled(enabled);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setFairQueue(boolean fairQueue) {
this.getPoolProperties().setFairQueue(fairQueue);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setUseLock(boolean useLock) {
this.getPoolProperties().setUseLock(useLock);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setDefaultCatalog(String catalog) {
this.getPoolProperties().setDefaultCatalog(catalog);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setDefaultAutoCommit(Boolean autocommit) {
this.getPoolProperties().setDefaultAutoCommit(autocommit);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setDefaultTransactionIsolation(int defaultTransactionIsolation) {
this.getPoolProperties().setDefaultTransactionIsolation(defaultTransactionIsolation);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setConnectionProperties(String properties) {
try {
java.util.Properties prop = DataSourceFactory
@@ -320,6 +451,10 @@ public class DataSourceProxy {
}
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setUseEquals(boolean useEquals) {
this.getPoolProperties().setUseEquals(useEquals);
}
@@ -332,13 +467,16 @@ public class DataSourceProxy {
return null;
}
+
/**
+ * no-op
* {@link javax.sql.DataSource#setLogWriter(PrintWriter)}
*/
public void setLogWriter(PrintWriter out) throws SQLException {
}
/**
+ * no-op
* {@link javax.sql.DataSource#getLoginTimeout}
*/
public int getLoginTimeout() {
@@ -360,7 +498,483 @@ public class DataSourceProxy {
}
}
+
+ //===============================================================================
+// Expose JMX attributes through Tomcat's dynamic reflection
+//===============================================================================
+ /**
+ * If the pool has not been created, it will be created during this call.
+ * @return the number of established but idle connections
+ */
+ public int getIdle() {
+ try {
+ return createPool().getIdle();
+ }catch (SQLException x) {
+ throw new RuntimeException(x);
+ }
+ }
+
+ /**
+ * {@link #getIdle()}
+ */
+ public int getNumIdle() {
+ return getIdle();
+ }
+
+ /**
+ * Forces an abandon check on the connection pool.
+ * If connections that have been abandoned exists, they will be closed during this run
+ */
+ public void checkAbandoned() {
+ try {
+ createPool().checkAbandoned();
+ }catch (SQLException x) {
+ throw new RuntimeException(x);
+ }
+ }
+
+ /**
+ * Forces a check for resizing of the idle connections
+ */
+ public void checkIdle() {
+ try {
+ createPool().checkIdle();
+ }catch (SQLException x) {
+ throw new RuntimeException(x);
+ }
+ }
+
+ /**
+ * @return number of connections in use by the application
+ */
+ public int getActive() {
+ try {
+ return createPool().getActive();
+ }catch (SQLException x) {
+ throw new RuntimeException(x);
+ }
+ }
+
+ /**
+ * @return number of connections in use by the application
+ * {@link DataSource#getActive()}
+ */
+ public int getNumActive() {
+ return getActive();
+ }
+
+ /**
+ * @return number of threads waiting for a connection
+ */
+ public int getWaitCount() {
+ try {
+ return createPool().getWaitCount();
+ }catch (SQLException x) {
+ throw new RuntimeException(x);
+ }
+ }
+
+ /**
+ * @return the current size of the pool
+ */
+ public int getSize() {
+ try {
+ return createPool().getSize();
+ }catch (SQLException x) {
+ throw new RuntimeException(x);
+ }
+ }
+
+ /**
+ * Performs a validation on idle connections
+ */
+ public void testIdle() {
+ try {
+ createPool().testAllIdle();
+ }catch (SQLException x) {
+ throw new RuntimeException(x);
+ }
+ }
+ //=========================================================
+ // PROPERTIES / CONFIGURATION
+ //=========================================================
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getConnectionProperties() {
+ return getPoolProperties().getConnectionProperties();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Properties getDbProperties() {
+ return getPoolProperties().getDbProperties();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getDefaultCatalog() {
+ return getPoolProperties().getDefaultCatalog();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getDefaultTransactionIsolation() {
+ return getPoolProperties().getDefaultTransactionIsolation();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getDriverClassName() {
+ return getPoolProperties().getDriverClassName();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getInitialSize() {
+ return getPoolProperties().getInitialSize();
+ }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getInitSQL() {
+ return getPoolProperties().getInitSQL();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getJdbcInterceptors() {
+ return getPoolProperties().getJdbcInterceptors();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getMaxActive() {
+ return getPoolProperties().getMaxActive();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getMaxIdle() {
+ return getPoolProperties().getMaxIdle();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getMaxWait() {
+ return getPoolProperties().getMaxWait();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getMinEvictableIdleTimeMillis() {
+ return getPoolProperties().getMinEvictableIdleTimeMillis();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getMinIdle() {
+ return getPoolProperties().getMinIdle();
+ }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public long getMaxAge() {
+ return getPoolProperties().getMaxAge();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getName() {
+ return getName();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getNumTestsPerEvictionRun() {
+ return getPoolProperties().getNumTestsPerEvictionRun();
+ }
+
+ /**
+ * @return DOES NOT RETURN THE PASSWORD, IT WOULD SHOW UP IN JMX
+ */
+ public String getPassword() {
+ return "Password not available as DataSource/JMX operation.";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getRemoveAbandonedTimeout() {
+ return getPoolProperties().getRemoveAbandonedTimeout();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getTimeBetweenEvictionRunsMillis() {
+ return getPoolProperties().getTimeBetweenEvictionRunsMillis();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getUrl() {
+ return getPoolProperties().getUrl();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getUsername() {
+ return getPoolProperties().getUsername();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public long getValidationInterval() {
+ return getPoolProperties().getValidationInterval();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getValidationQuery() {
+ return getPoolProperties().getValidationQuery();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isAccessToUnderlyingConnectionAllowed() {
+ return getPoolProperties().isAccessToUnderlyingConnectionAllowed();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Boolean isDefaultAutoCommit() {
+ return getPoolProperties().isDefaultAutoCommit();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Boolean isDefaultReadOnly() {
+ return getPoolProperties().isDefaultReadOnly();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isLogAbandoned() {
+ return getPoolProperties().isLogAbandoned();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isPoolSweeperEnabled() {
+ return getPoolProperties().isPoolSweeperEnabled();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isRemoveAbandoned() {
+ return getPoolProperties().isRemoveAbandoned();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getAbandonWhenPercentageFull() {
+ return getPoolProperties().getAbandonWhenPercentageFull();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isTestOnBorrow() {
+ return getPoolProperties().isTestOnBorrow();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isTestOnConnect() {
+ return getPoolProperties().isTestOnConnect();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isTestOnReturn() {
+ return getPoolProperties().isTestOnReturn();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isTestWhileIdle() {
+ return getPoolProperties().isTestWhileIdle();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Boolean getDefaultAutoCommit() {
+ return getPoolProperties().getDefaultAutoCommit();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Boolean getDefaultReadOnly() {
+ return getPoolProperties().getDefaultReadOnly();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public InterceptorDefinition[] getJdbcInterceptorsAsArray() {
+ return getPoolProperties().getJdbcInterceptorsAsArray();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean getUseLock() {
+ return getPoolProperties().getUseLock();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isFairQueue() {
+ return getPoolProperties().isFairQueue();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isJmxEnabled() {
+ return getPoolProperties().isJmxEnabled();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isUseEquals() {
+ return getPoolProperties().isUseEquals();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setAbandonWhenPercentageFull(int percentage) {
+ getPoolProperties().setAbandonWhenPercentageFull(percentage);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setAccessToUnderlyingConnectionAllowed(boolean accessToUnderlyingConnectionAllowed) {
+ getPoolProperties().setAccessToUnderlyingConnectionAllowed(accessToUnderlyingConnectionAllowed);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setDbProperties(Properties dbProperties) {
+ getPoolProperties().setDbProperties(dbProperties);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setDefaultReadOnly(Boolean defaultReadOnly) {
+ getPoolProperties().setDefaultReadOnly(defaultReadOnly);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setMaxAge(long maxAge) {
+ getPoolProperties().setMaxAge(maxAge);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setName(String name) {
+ getPoolProperties().setName(name);
+ }
}
diff --git a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/FairBlockingQueue.java b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/FairBlockingQueue.java
index 67f83e5f3..74a3ca2f2 100644
--- a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/FairBlockingQueue.java
+++ b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/FairBlockingQueue.java
@@ -32,17 +32,36 @@ import java.util.concurrent.locks.ReentrantLock;
*
* A simple implementation of a blocking queue with fairness waiting.
* invocations to method poll(...) will get handed out in the order they were received.
+ * Locking is fine grained, a shared lock is only used during the first level of contention, waiting is done in a
+ * lock per thread basis so that order is guaranteed once the thread goes into a suspended monitor state.
+ *
+ * Not all of the methods of the {@link java.util.concurrent.BlockingQueue} are implemented.
* @author Filip Hanik
*
*/
public class FairBlockingQueue implements BlockingQueue {
- ReentrantLock lock = new ReentrantLock(false);
+
+ /**
+ * Phase one entry lock in order to give out
+ * per-thread-locks for the waiting phase we have
+ * a phase one lock during the contention period.
+ */
+ final ReentrantLock lock = new ReentrantLock(false);
- LinkedList items = null;
+ /**
+ * All the objects in the pool are stored in a simple linked list
+ */
+ final LinkedList items;
- LinkedList> waiters = null;
+ /**
+ * All threads waiting for an object are stored in a linked list
+ */
+ final LinkedList> waiters;
+ /**
+ * Creates a new fair blocking queue.
+ */
public FairBlockingQueue() {
items = new LinkedList();
waiters = new LinkedList>();
@@ -52,27 +71,37 @@ public class FairBlockingQueue implements BlockingQueue {
// USED BY CONPOOL IMPLEMENTATION
//------------------------------------------------------------------
/**
+ * Will always return true, queue is unbounded.
* {@inheritDoc}
*/
public boolean offer(E e) {
+ //during the offer, we will grab the main lock
final ReentrantLock lock = this.lock;
lock.lock();
ExchangeCountDownLatch c = null;
try {
+ //check to see if threads are waiting for an object
if (waiters.size() > 0) {
+ //if threads are waiting grab the latch for that thread
c = waiters.poll();
+ //give the object to the thread instead of adding it to the pool
c.setItem(e);
} else {
+ //we always add first, so that the most recently used object will be given out
items.addFirst(e);
}
} finally {
lock.unlock();
}
+ //if we exchanged an object with another thread, wake it up.
if (c!=null) c.countDown();
+ //we have an unbounded queue, so always return true
return true;
}
/**
+ * Will never timeout, as it invokes the {@link #offer(Object)} method.
+ * Once a lock has been acquired, the
* {@inheritDoc}
*/
public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException {
@@ -80,26 +109,37 @@ public class FairBlockingQueue implements BlockingQueue {
}
/**
+ * Fair retrieval of an object in the queue.
+ * Objects are returned in the order the threads requested them.
* {@inheritDoc}
*/
public E poll(long timeout, TimeUnit unit) throws InterruptedException {
E result = null;
final ReentrantLock lock = this.lock;
boolean error = true;
+ //acquire the global lock until we know what to do
lock.lock();
try {
+ //check to see if we have objects
result = items.poll();
if (result==null && timeout>0) {
+ //the queue is empty we will wait for an object
ExchangeCountDownLatch c = new ExchangeCountDownLatch(1);
+ //add to the bottom of the wait list
waiters.addLast(c);
+ //unlock the global lock
lock.unlock();
+ //wait for the specified timeout
if (!c.await(timeout, unit)) {
+ //if we timed out, remove ourselves from the waitlist
lock.lock();
waiters.remove(c);
lock.unlock();
}
+ //return the item we received, can be null if we timed out
result = c.getItem();
} else {
+ //we have an object, release
lock.unlock();
}
error = false;
@@ -119,16 +159,21 @@ public class FairBlockingQueue implements BlockingQueue {
Future result = null;
final ReentrantLock lock = this.lock;
boolean error = true;
+ //grab the global lock
lock.lock();
try {
+ //check to see if we have objects in the queue
E item = items.poll();
if (item==null) {
+ //queue is empty, add ourselves as waiters
ExchangeCountDownLatch c = new ExchangeCountDownLatch(1);
waiters.addLast(c);
lock.unlock();
+ //return a future that will wait for the object
result = new ItemFuture(c);
} else {
lock.unlock();
+ //return a future with the item
result = new ItemFuture(item);
}
error = false;
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 cd01c5c10..a43461e8a 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
@@ -17,6 +17,8 @@
package org.apache.tomcat.jdbc.pool;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
@@ -30,8 +32,7 @@ import org.apache.juli.logging.LogFactory;
* @author Filip Hanik
*
*/
-public class PoolProperties {
- public static final String PKG_PREFIX = "org.apache.tomcat.jdbc.pool.interceptor.";
+public class PoolProperties implements PoolConfiguration {
protected static Log log = LogFactory.getLog(PoolProperties.class);
protected static AtomicInteger poolCounter = new AtomicInteger(0);
@@ -55,11 +56,10 @@ public class PoolProperties {
protected int timeBetweenEvictionRunsMillis = 5000;
protected int numTestsPerEvictionRun;
protected int minEvictableIdleTimeMillis = 60000;
- protected boolean accessToUnderlyingConnectionAllowed;
+ protected final boolean accessToUnderlyingConnectionAllowed = true;
protected boolean removeAbandoned = false;
protected int removeAbandonedTimeout = 60;
protected boolean logAbandoned = false;
- protected int loginTimeout = 10000;
protected String name = "Tomcat Connection Pool["+(poolCounter.addAndGet(1))+"-"+System.identityHashCode(PoolProperties.class)+"]";
protected String password;
protected String username;
@@ -75,156 +75,300 @@ public class PoolProperties {
protected boolean useLock = false;
private InterceptorDefinition[] interceptors = null;
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setAbandonWhenPercentageFull(int percentage) {
if (percentage<0) abandonWhenPercentageFull = 0;
else if (percentage>100) abandonWhenPercentageFull = 100;
else abandonWhenPercentageFull = percentage;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public int getAbandonWhenPercentageFull() {
return abandonWhenPercentageFull;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public boolean isFairQueue() {
return fairQueue;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setFairQueue(boolean fairQueue) {
this.fairQueue = fairQueue;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public boolean isAccessToUnderlyingConnectionAllowed() {
return accessToUnderlyingConnectionAllowed;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public String getConnectionProperties() {
return connectionProperties;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public Properties getDbProperties() {
return dbProperties;
}
- public boolean isDefaultAutoCommit() {
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Boolean isDefaultAutoCommit() {
return defaultAutoCommit;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public String getDefaultCatalog() {
return defaultCatalog;
}
- public boolean isDefaultReadOnly() {
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Boolean isDefaultReadOnly() {
return defaultReadOnly;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public int getDefaultTransactionIsolation() {
return defaultTransactionIsolation;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public String getDriverClassName() {
return driverClassName;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public int getInitialSize() {
return initialSize;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public boolean isLogAbandoned() {
return logAbandoned;
}
- public int getLoginTimeout() {
- return loginTimeout;
- }
-
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public int getMaxActive() {
return maxActive;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public int getMaxIdle() {
return maxIdle;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public int getMaxWait() {
return maxWait;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public int getMinEvictableIdleTimeMillis() {
return minEvictableIdleTimeMillis;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public int getMinIdle() {
return minIdle;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public String getName() {
return name;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public int getNumTestsPerEvictionRun() {
return numTestsPerEvictionRun;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public String getPassword() {
return password;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public String getPoolName() {
return getName();
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public boolean isRemoveAbandoned() {
return removeAbandoned;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public int getRemoveAbandonedTimeout() {
return removeAbandonedTimeout;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public boolean isTestOnBorrow() {
return testOnBorrow;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public boolean isTestOnReturn() {
return testOnReturn;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public boolean isTestWhileIdle() {
return testWhileIdle;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public int getTimeBetweenEvictionRunsMillis() {
return timeBetweenEvictionRunsMillis;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public String getUrl() {
return url;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public String getUsername() {
return username;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public String getValidationQuery() {
return validationQuery;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public long getValidationInterval() {
return validationInterval;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public String getInitSQL() {
return initSQL;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public boolean isTestOnConnect() {
return testOnConnect;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public String getJdbcInterceptors() {
return jdbcInterceptors;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public InterceptorDefinition[] getJdbcInterceptorsAsArray() {
if (interceptors == null) {
if (jdbcInterceptors==null) {
@@ -256,133 +400,251 @@ public class PoolProperties {
return interceptors;
}
- public void setAccessToUnderlyingConnectionAllowed(boolean
- accessToUnderlyingConnectionAllowed) {
- this.accessToUnderlyingConnectionAllowed =
- accessToUnderlyingConnectionAllowed;
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setAccessToUnderlyingConnectionAllowed(boolean accessToUnderlyingConnectionAllowed) {
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setConnectionProperties(String connectionProperties) {
this.connectionProperties = connectionProperties;
+ getProperties(connectionProperties, getDbProperties());
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setDbProperties(Properties dbProperties) {
this.dbProperties = dbProperties;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setDefaultAutoCommit(Boolean defaultAutoCommit) {
this.defaultAutoCommit = defaultAutoCommit;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setDefaultCatalog(String defaultCatalog) {
this.defaultCatalog = defaultCatalog;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setDefaultReadOnly(Boolean defaultReadOnly) {
this.defaultReadOnly = defaultReadOnly;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setDefaultTransactionIsolation(int defaultTransactionIsolation) {
this.defaultTransactionIsolation = defaultTransactionIsolation;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setDriverClassName(String driverClassName) {
this.driverClassName = driverClassName;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setInitialSize(int initialSize) {
this.initialSize = initialSize;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setLogAbandoned(boolean logAbandoned) {
this.logAbandoned = logAbandoned;
}
- public void setLoginTimeout(int loginTimeout) {
- this.loginTimeout = loginTimeout;
- }
-
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setMaxActive(int maxActive) {
this.maxActive = maxActive;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setMaxIdle(int maxIdle) {
this.maxIdle = maxIdle;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setMaxWait(int maxWait) {
this.maxWait = maxWait;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) {
this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setMinIdle(int minIdle) {
this.minIdle = minIdle;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setName(String name) {
this.name = name;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
this.numTestsPerEvictionRun = numTestsPerEvictionRun;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setPassword(String password) {
this.password = password;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setRemoveAbandoned(boolean removeAbandoned) {
this.removeAbandoned = removeAbandoned;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setRemoveAbandonedTimeout(int removeAbandonedTimeout) {
this.removeAbandonedTimeout = removeAbandonedTimeout;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setTestOnBorrow(boolean testOnBorrow) {
this.testOnBorrow = testOnBorrow;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setTestWhileIdle(boolean testWhileIdle) {
this.testWhileIdle = testWhileIdle;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setTestOnReturn(boolean testOnReturn) {
this.testOnReturn = testOnReturn;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setTimeBetweenEvictionRunsMillis(int
timeBetweenEvictionRunsMillis) {
this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setUrl(String url) {
this.url = url;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setUsername(String username) {
this.username = username;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setValidationInterval(long validationInterval) {
this.validationInterval = validationInterval;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setValidationQuery(String validationQuery) {
this.validationQuery = validationQuery;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setInitSQL(String initSQL) {
this.initSQL = initSQL;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setTestOnConnect(boolean testOnConnect) {
this.testOnConnect = testOnConnect;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setJdbcInterceptors(String jdbcInterceptors) {
this.jdbcInterceptors = jdbcInterceptors;
this.interceptors = null;
@@ -422,22 +684,42 @@ public class PoolProperties {
return poolCounter.get();
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public boolean isJmxEnabled() {
return jmxEnabled;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setJmxEnabled(boolean jmxEnabled) {
this.jmxEnabled = jmxEnabled;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public Boolean getDefaultAutoCommit() {
return defaultAutoCommit;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public Boolean getDefaultReadOnly() {
return defaultReadOnly;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public boolean isPoolSweeperEnabled() {
boolean result = getTimeBetweenEvictionRunsMillis()>0;
result = result && (isRemoveAbandoned() && getRemoveAbandonedTimeout()>0);
@@ -475,9 +757,9 @@ public class PoolProperties {
if (clazz==null) {
if (getClassName().indexOf(".")<0) {
if (log.isDebugEnabled()) {
- log.debug("Loading interceptor class:"+PoolProperties.PKG_PREFIX+getClassName());
+ log.debug("Loading interceptor class:"+PoolConfiguration.PKG_PREFIX+getClassName());
}
- clazz = Class.forName(PoolProperties.PKG_PREFIX+getClassName(), true, this.getClass().getClassLoader());
+ clazz = Class.forName(PoolConfiguration.PKG_PREFIX+getClassName(), true, this.getClass().getClassLoader());
} else {
if (log.isDebugEnabled()) {
log.debug("Loading interceptor class:"+getClassName());
@@ -516,30 +798,64 @@ public class PoolProperties {
}
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public boolean isUseEquals() {
return useEquals;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setUseEquals(boolean useEquals) {
this.useEquals = useEquals;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public long getMaxAge() {
return maxAge;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setMaxAge(long maxAge) {
this.maxAge = maxAge;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public boolean getUseLock() {
return useLock;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void setUseLock(boolean useLock) {
this.useLock = useLock;
}
-
+ public static Properties getProperties(String propText, Properties props) {
+ if (props==null) props = new Properties();
+ if (propText != null) {
+ try {
+ props.load(new ByteArrayInputStream(propText.replace(';', '\n').getBytes()));
+ }catch (IOException x) {
+ throw new RuntimeException(x);
+ }
+ }
+ return props;
+ }
}
diff --git a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
index 111c97495..9e26c4dc2 100644
--- a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
+++ b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
@@ -65,7 +65,7 @@ public class PooledConnection {
/**
* The properties for the connection pool
*/
- protected PoolProperties poolProperties;
+ protected PoolConfiguration poolProperties;
/**
* The underlying database connection
*/
@@ -112,7 +112,7 @@ public class PooledConnection {
private AtomicBoolean released = new AtomicBoolean(false);
- public PooledConnection(PoolProperties prop, ConnectionPool parent) {
+ public PooledConnection(PoolConfiguration prop, ConnectionPool parent) {
instanceCount = counter.addAndGet(1);
poolProperties = prop;
this.parent = parent;
@@ -341,7 +341,7 @@ public class PooledConnection {
this.lastValidated = lastValidated;
}
- public void setPoolProperties(PoolProperties poolProperties) {
+ public void setPoolProperties(PoolConfiguration poolProperties) {
this.poolProperties = poolProperties;
}
@@ -357,7 +357,7 @@ public class PooledConnection {
return lastValidated;
}
- public PoolProperties getPoolProperties() {
+ public PoolConfiguration getPoolProperties() {
return poolProperties;
}
diff --git a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/ConnectionState.java b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/ConnectionState.java
index 0daa29550..991bf9418 100644
--- a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/ConnectionState.java
+++ b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/ConnectionState.java
@@ -24,7 +24,7 @@ import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.jdbc.pool.ConnectionPool;
import org.apache.tomcat.jdbc.pool.DataSourceFactory;
import org.apache.tomcat.jdbc.pool.JdbcInterceptor;
-import org.apache.tomcat.jdbc.pool.PoolProperties;
+import org.apache.tomcat.jdbc.pool.PoolConfiguration;
import org.apache.tomcat.jdbc.pool.PooledConnection;
/**
@@ -46,7 +46,7 @@ public class ConnectionState extends JdbcInterceptor {
public void reset(ConnectionPool parent, PooledConnection con) {
- PoolProperties poolProperties = parent.getPoolProperties();
+ PoolConfiguration poolProperties = parent.getPoolProperties();
if (poolProperties.getDefaultReadOnly()!=null) {
try {
if (readOnly==null || readOnly.booleanValue()!=poolProperties.getDefaultReadOnly().booleanValue()) {
diff --git a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java
index 25be605b0..6459f459b 100644
--- a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java
+++ b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java
@@ -29,6 +29,8 @@ import javax.management.NotificationListener;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
+import org.apache.tomcat.jdbc.pool.PoolConfiguration;
+import org.apache.tomcat.jdbc.pool.PoolProperties.InterceptorDefinition;
public class ConnectionPool extends NotificationBroadcasterSupport implements ConnectionPoolMBean {
/**
@@ -59,6 +61,10 @@ public class ConnectionPool extends NotificationBroadcasterSupport implements Co
return pool;
}
+ public PoolConfiguration getPoolProperties() {
+ return pool.getPoolProperties();
+ }
+
//=================================================================
// NOTIFICATION INFO
//=================================================================
@@ -140,10 +146,6 @@ public class ConnectionPool extends NotificationBroadcasterSupport implements Co
return pool.getActive();
}
- public boolean isPoolSweeperEnabled() {
- return pool.getPoolProperties().isPoolSweeperEnabled();
- }
-
public int getNumIdle() {
return getIdle();
}
@@ -151,6 +153,10 @@ public class ConnectionPool extends NotificationBroadcasterSupport implements Co
public int getNumActive() {
return getActive();
}
+
+ public int getWaitCount() {
+ return pool.getWaitCount();
+ }
//=================================================================
// POOL OPERATIONS
@@ -169,110 +175,384 @@ public class ConnectionPool extends NotificationBroadcasterSupport implements Co
//=================================================================
// POOL PROPERTIES
//=================================================================
- public Properties getDbProperties() {
- return null; //pool.getPoolProperties().getDbProperties();
- }
- public String getUrl() {
- return pool.getPoolProperties().getUrl();
- }
- public String getDriverClassName() {
- return pool.getPoolProperties().getDriverClassName();
+ //=========================================================
+ // PROPERTIES / CONFIGURATION
+ //=========================================================
+
+
+
+ public String getConnectionProperties() {
+ return getPoolProperties().getConnectionProperties();
}
- public boolean isDefaultAutoCommit() {
- return pool.getPoolProperties().isDefaultAutoCommit();
+
+ public Properties getDbProperties() {
+ return getPoolProperties().getDbProperties();
}
- public boolean isDefaultReadOnly() {
- return pool.getPoolProperties().isDefaultReadOnly();
+
+ public String getDefaultCatalog() {
+ return getPoolProperties().getDefaultCatalog();
}
+
public int getDefaultTransactionIsolation() {
- return pool.getPoolProperties().getDefaultTransactionIsolation();
- }
- public String getConnectionProperties() {
- return pool.getPoolProperties().getConnectionProperties();
+ return getPoolProperties().getDefaultTransactionIsolation();
}
- public String getDefaultCatalog() {
- return pool.getPoolProperties().getDefaultCatalog();
+
+ public String getDriverClassName() {
+ return getPoolProperties().getDriverClassName();
}
+
+
public int getInitialSize() {
- return pool.getPoolProperties().getInitialSize();
+ return getPoolProperties().getInitialSize();
+ }
+
+ public String getInitSQL() {
+ return getPoolProperties().getInitSQL();
+ }
+
+ public String getJdbcInterceptors() {
+ return getPoolProperties().getJdbcInterceptors();
}
+
public int getMaxActive() {
- return pool.getPoolProperties().getMaxActive();
+ return getPoolProperties().getMaxActive();
}
+
public int getMaxIdle() {
- return pool.getPoolProperties().getMaxIdle();
+ return getPoolProperties().getMaxIdle();
}
+
+ public int getMaxWait() {
+ return getPoolProperties().getMaxWait();
+ }
+
+ public int getMinEvictableIdleTimeMillis() {
+ return getPoolProperties().getMinEvictableIdleTimeMillis();
+ }
+
public int getMinIdle() {
- return pool.getPoolProperties().getMinIdle();
+ return getPoolProperties().getMinIdle();
}
- public int getMaxWait() {
- return pool.getPoolProperties().getMaxWait();
+
+ public long getMaxAge() {
+ return getPoolProperties().getMaxAge();
+ }
+
+ public String getName() {
+ return getName();
+ }
+
+ public int getNumTestsPerEvictionRun() {
+ return getPoolProperties().getNumTestsPerEvictionRun();
}
+
+ /**
+ * @return DOES NOT RETURN THE PASSWORD, IT WOULD SHOW UP IN JMX
+ */
+ public String getPassword() {
+ return "Password not available as DataSource/JMX operation.";
+ }
+
+ public int getRemoveAbandonedTimeout() {
+ return getPoolProperties().getRemoveAbandonedTimeout();
+ }
+
+
+ public int getTimeBetweenEvictionRunsMillis() {
+ return getPoolProperties().getTimeBetweenEvictionRunsMillis();
+ }
+
+ public String getUrl() {
+ return getPoolProperties().getUrl();
+ }
+
+ public String getUsername() {
+ return getPoolProperties().getUsername();
+ }
+
+ public long getValidationInterval() {
+ return getPoolProperties().getValidationInterval();
+ }
+
public String getValidationQuery() {
- return pool.getPoolProperties().getValidationQuery();
+ return getPoolProperties().getValidationQuery();
+ }
+
+ public boolean isAccessToUnderlyingConnectionAllowed() {
+ return getPoolProperties().isAccessToUnderlyingConnectionAllowed();
+ }
+
+ public Boolean isDefaultAutoCommit() {
+ return getPoolProperties().isDefaultAutoCommit();
+ }
+
+ public Boolean isDefaultReadOnly() {
+ return getPoolProperties().isDefaultReadOnly();
}
+
+ public boolean isLogAbandoned() {
+ return getPoolProperties().isLogAbandoned();
+ }
+
+ public boolean isPoolSweeperEnabled() {
+ return getPoolProperties().isPoolSweeperEnabled();
+ }
+
+ public boolean isRemoveAbandoned() {
+ return getPoolProperties().isRemoveAbandoned();
+ }
+
+ public int getAbandonWhenPercentageFull() {
+ return getPoolProperties().getAbandonWhenPercentageFull();
+ }
+
public boolean isTestOnBorrow() {
- return pool.getPoolProperties().isTestOnBorrow();
+ return getPoolProperties().isTestOnBorrow();
}
+
+ public boolean isTestOnConnect() {
+ return getPoolProperties().isTestOnConnect();
+ }
+
public boolean isTestOnReturn() {
- return pool.getPoolProperties().isTestOnReturn();
+ return getPoolProperties().isTestOnReturn();
}
+
public boolean isTestWhileIdle() {
- return pool.getPoolProperties().isTestWhileIdle();
+ return getPoolProperties().isTestWhileIdle();
}
- public int getTimeBetweenEvictionRunsMillis() {
- return pool.getPoolProperties().getTimeBetweenEvictionRunsMillis();
+
+
+ public Boolean getDefaultAutoCommit() {
+ return getPoolProperties().getDefaultAutoCommit();
}
- public int getNumTestsPerEvictionRun() {
- return pool.getPoolProperties().getNumTestsPerEvictionRun();
+
+ public Boolean getDefaultReadOnly() {
+ return getPoolProperties().getDefaultReadOnly();
}
- public int getMinEvictableIdleTimeMillis() {
- return pool.getPoolProperties().getMinEvictableIdleTimeMillis();
+
+ public InterceptorDefinition[] getJdbcInterceptorsAsArray() {
+ return getPoolProperties().getJdbcInterceptorsAsArray();
}
- public boolean isAccessToUnderlyingConnectionAllowed() {
- return pool.getPoolProperties().isAccessToUnderlyingConnectionAllowed();
+
+ public boolean getUseLock() {
+ return getPoolProperties().getUseLock();
}
- public boolean isRemoveAbandoned() {
- return pool.getPoolProperties().isRemoveAbandoned();
+
+ public boolean isFairQueue() {
+ return getPoolProperties().isFairQueue();
}
- public int getRemoveAbandonedTimeout() {
- return pool.getPoolProperties().getRemoveAbandonedTimeout();
+
+ public boolean isJmxEnabled() {
+ return getPoolProperties().isJmxEnabled();
}
- public boolean isLogAbandoned() {
- return pool.getPoolProperties().isLogAbandoned();
+
+ public boolean isUseEquals() {
+ return getPoolProperties().isUseEquals();
}
- public int getLoginTimeout() {
- return pool.getPoolProperties().getLoginTimeout();
+
+ public void setAbandonWhenPercentageFull(int percentage) {
+ getPoolProperties().setAbandonWhenPercentageFull(percentage);
}
- public String getName() {
- return pool.getPoolProperties().getName();
+
+ public void setAccessToUnderlyingConnectionAllowed(boolean accessToUnderlyingConnectionAllowed) {
+ getPoolProperties().setAccessToUnderlyingConnectionAllowed(accessToUnderlyingConnectionAllowed);
}
- public String getPassword() {
- return "";
+
+ public void setDbProperties(Properties dbProperties) {
+ getPoolProperties().setDbProperties(dbProperties);
}
- public String getUsername() {
- return pool.getPoolProperties().getUsername();
+
+ public void setDefaultReadOnly(Boolean defaultReadOnly) {
+ getPoolProperties().setDefaultReadOnly(defaultReadOnly);
}
- public long getValidationInterval() {
- return pool.getPoolProperties().getValidationInterval();
+
+ public void setMaxAge(long maxAge) {
+ getPoolProperties().setMaxAge(maxAge);
}
- public String getInitSQL() {
- return pool.getPoolProperties().getInitSQL();
+
+ public void setName(String name) {
+ getPoolProperties().setName(name);
}
- public boolean isTestOnConnect() {
- return pool.getPoolProperties().isTestOnConnect();
+
+ public String getPoolName() {
+ return getPoolProperties().getName();
}
- public String getJdbcInterceptors() {
- return pool.getPoolProperties().getJdbcInterceptors();
+
+
+ public void setConnectionProperties(String connectionProperties) {
+ getPoolProperties().setConnectionProperties(connectionProperties);
+
}
- public int getWaitCount() {
- return pool.getWaitCount();
+
+ public void setDefaultAutoCommit(Boolean defaultAutoCommit) {
+ getPoolProperties().setDefaultAutoCommit(defaultAutoCommit);
}
- public int getAbandonWhenPercentageFull() {
- return pool.getPoolProperties().getAbandonWhenPercentageFull();
+
+ public void setDefaultCatalog(String defaultCatalog) {
+ getPoolProperties().setDefaultCatalog(defaultCatalog);
}
- public long getMaxAge() {
- return pool.getPoolProperties().getMaxAge();
+
+ public void setDefaultTransactionIsolation(int defaultTransactionIsolation) {
+ getPoolProperties().setDefaultTransactionIsolation(defaultTransactionIsolation);
+ }
+
+ public void setDriverClassName(String driverClassName) {
+ getPoolProperties().setDriverClassName(driverClassName);
+ }
+
+ public void setFairQueue(boolean fairQueue) {
+ getPoolProperties().setFairQueue(fairQueue);
+ }
+
+ @Override
+ public void setInitialSize(int initialSize) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setInitSQL(String initSQL) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setJdbcInterceptors(String jdbcInterceptors) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setJmxEnabled(boolean jmxEnabled) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setLogAbandoned(boolean logAbandoned) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setMaxActive(int maxActive) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setMaxIdle(int maxIdle) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setMaxWait(int maxWait) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setMinIdle(int minIdle) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setPassword(String password) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setRemoveAbandoned(boolean removeAbandoned) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setRemoveAbandonedTimeout(int removeAbandonedTimeout) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setTestOnBorrow(boolean testOnBorrow) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setTestOnConnect(boolean testOnConnect) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setTestOnReturn(boolean testOnReturn) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setTestWhileIdle(boolean testWhileIdle) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setUrl(String url) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setUseEquals(boolean useEquals) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setUseLock(boolean useLock) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setUsername(String username) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setValidationInterval(long validationInterval) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setValidationQuery(String validationQuery) {
+ // TODO Auto-generated method stub
+
}
}
diff --git a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPoolMBean.java b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPoolMBean.java
index eaf257dc5..8d5092eec 100644
--- a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPoolMBean.java
+++ b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPoolMBean.java
@@ -17,7 +17,9 @@ package org.apache.tomcat.jdbc.pool.jmx;
import java.util.Properties;
-public interface ConnectionPoolMBean {
+import org.apache.tomcat.jdbc.pool.PoolConfiguration;
+
+public interface ConnectionPoolMBean extends PoolConfiguration {
//=================================================================
// POOL STATS
@@ -51,75 +53,4 @@ public interface ConnectionPoolMBean {
//=================================================================
- //=================================================================
- // POOL PROPERTIES
- //=================================================================
- public Properties getDbProperties();
-
- public String getUrl();
-
- public String getDriverClassName();
-
- public boolean isDefaultAutoCommit();
-
- public boolean isDefaultReadOnly();
-
- public int getDefaultTransactionIsolation();
-
- public String getConnectionProperties();
-
- public String getDefaultCatalog();
-
- public int getInitialSize();
-
- public int getMaxActive();
-
- public int getMaxIdle();
-
- public int getMinIdle();
-
- public int getMaxWait();
-
- public String getValidationQuery();
-
- public boolean isTestOnBorrow();
-
- public boolean isTestOnReturn();
-
- public boolean isTestWhileIdle();
-
- public int getTimeBetweenEvictionRunsMillis();
-
- public int getNumTestsPerEvictionRun();
-
- public int getMinEvictableIdleTimeMillis();
-
- public boolean isAccessToUnderlyingConnectionAllowed();
-
- public boolean isRemoveAbandoned();
-
- public int getRemoveAbandonedTimeout();
-
- public boolean isLogAbandoned();
-
- public int getLoginTimeout();
-
- public String getName();
-
- public String getPassword();
-
- public String getUsername();
-
- public long getValidationInterval();
-
- public String getInitSQL();
-
- public boolean isTestOnConnect();
-
- public String getJdbcInterceptors();
-
- public int getAbandonWhenPercentageFull();
-
- public long getMaxAge();
-
}
diff --git a/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/CreateTestTable.java b/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/CreateTestTable.java
index cb2890832..30e0c04c6 100644
--- a/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/CreateTestTable.java
+++ b/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/CreateTestTable.java
@@ -23,6 +23,8 @@ import java.sql.Statement;
import java.util.Random;
import java.sql.ResultSet;
+import org.apache.tomcat.jdbc.pool.interceptor.ResetAbandonedTimer;
+
public class CreateTestTable extends DefaultTestCase {
public static volatile boolean recreate = Boolean.getBoolean("recreate");
@@ -59,6 +61,9 @@ public class CreateTestTable extends DefaultTestCase {
}
public void testPopulateData() throws Exception {
+ init();
+ datasource.setJdbcInterceptors(ResetAbandonedTimer.class.getName());
+ System.out.println("FILIP Using URL:"+this.datasource.getUrl());
String insert = "insert into test values (?,?,?,?,?)";
this.init();
this.datasource.setRemoveAbandoned(false);
@@ -90,6 +95,7 @@ public class CreateTestTable extends DefaultTestCase {
ps.executeBatch();
ps.close();
ps = con.prepareStatement(insert);
+ ps.setQueryTimeout(0);
}
}
diff --git a/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/DefaultProperties.java b/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/DefaultProperties.java
index 3158edb74..235b55590 100644
--- a/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/DefaultProperties.java
+++ b/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/DefaultProperties.java
@@ -62,11 +62,9 @@ public class DefaultProperties extends PoolProperties {
timeBetweenEvictionRunsMillis = 5000;
numTestsPerEvictionRun = 0;
minEvictableIdleTimeMillis = 1000;
- accessToUnderlyingConnectionAllowed = false;
removeAbandoned = true;
removeAbandonedTimeout = 5000;
logAbandoned = true;
- loginTimeout = 0;
validationInterval = 0; //always validate
initSQL = null;
testOnConnect = false;;
diff --git a/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/DefaultTestCase.java b/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/DefaultTestCase.java
index 67e5e5606..90df561e6 100644
--- a/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/DefaultTestCase.java
+++ b/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/DefaultTestCase.java
@@ -25,6 +25,8 @@ import org.apache.tomcat.dbcp.dbcp.BasicDataSource;
import org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory;
import junit.framework.TestCase;
+
+import org.apache.tomcat.jdbc.pool.PoolConfiguration;
import org.apache.tomcat.jdbc.pool.PoolProperties;
import org.apache.tomcat.jdbc.pool.DataSourceProxy;
@@ -45,10 +47,15 @@ public class DefaultTestCase extends TestCase {
public DefaultTestCase(String name) {
super(name);
}
+
+ @Override
+ public void setUp() throws Exception {
+ init();
+ }
public org.apache.tomcat.jdbc.pool.DataSource createDefaultDataSource() {
org.apache.tomcat.jdbc.pool.DataSource datasource = null;
- PoolProperties p = new DefaultProperties();
+ PoolConfiguration p = new DefaultProperties();
p.setJmxEnabled(false);
p.setTestWhileIdle(false);
p.setTestOnBorrow(false);
diff --git a/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/SimplePOJOAsyncExample.java b/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/SimplePOJOAsyncExample.java
index 455f9a262..c3cd07100 100644
--- a/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/SimplePOJOAsyncExample.java
+++ b/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/SimplePOJOAsyncExample.java
@@ -21,12 +21,13 @@ import java.sql.Statement;
import java.util.concurrent.Future;
import org.apache.tomcat.jdbc.pool.DataSource;
+import org.apache.tomcat.jdbc.pool.PoolConfiguration;
import org.apache.tomcat.jdbc.pool.PoolProperties;
public class SimplePOJOAsyncExample {
public static void main(String[] args) throws Exception {
- PoolProperties p = new PoolProperties();
+ PoolConfiguration p = new PoolProperties();
p.setFairQueue(true);
p.setUrl("jdbc:mysql://localhost:3306/mysql?autoReconnect=true");
p.setDriverClassName("com.mysql.jdbc.Driver");
diff --git a/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/SimplePOJOExample.java b/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/SimplePOJOExample.java
index 832f74515..50368574b 100644
--- a/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/SimplePOJOExample.java
+++ b/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/SimplePOJOExample.java
@@ -21,12 +21,13 @@ import java.sql.ResultSet;
import java.sql.Statement;
import org.apache.tomcat.jdbc.pool.DataSource;
+import org.apache.tomcat.jdbc.pool.PoolConfiguration;
import org.apache.tomcat.jdbc.pool.PoolProperties;
public class SimplePOJOExample {
public static void main(String[] args) throws Exception {
- PoolProperties p = new PoolProperties();
+ PoolConfiguration p = new PoolProperties();
p.setUrl("jdbc:mysql://localhost:3306/mysql?autoReconnect=true");
p.setDriverClassName("com.mysql.jdbc.Driver");
p.setUsername("root");
--
2.11.0