From af895f98f35ef7823c82dcb7c3d89dc7b26d9b31 Mon Sep 17 00:00:00 2001 From: fhanik Date: Tue, 24 Mar 2009 10:55:21 +0000 Subject: [PATCH] Implement delegate methods that will let us expose all this under Tomcat JMX since Tomcat uses dynamic reflection to figure out what to expose git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@757718 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tomcat/jdbc/pool/DataSource.java | 309 ++++++++++++++++++++- .../apache/tomcat/jdbc/pool/DataSourceProxy.java | 9 +- 2 files changed, 310 insertions(+), 8 deletions(-) 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 7e6d5c083..717667817 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,6 +16,9 @@ */ package org.apache.tomcat.jdbc.pool; +import java.sql.SQLException; +import java.util.Properties; + /** * A DataSource that can be instantiated through IoC and implements the DataSource interface @@ -23,7 +26,7 @@ package org.apache.tomcat.jdbc.pool; * @author Filip Hanik * @version 1.0 */ -public class DataSource extends DataSourceProxy implements javax.sql.DataSource { +public class DataSource extends DataSourceProxy implements javax.sql.DataSource, org.apache.tomcat.jdbc.pool.jmx.ConnectionPoolMBean { public DataSource() { super(); @@ -32,5 +35,309 @@ public class DataSource extends DataSourceProxy implements javax.sql.DataSource public DataSource(PoolProperties poolProperties) { super(poolProperties); } + +//=============================================================================== +// Expose JMX attributes through Tomcat's dynamic reflection +//=============================================================================== + public void checkAbandoned() { + try { + createPool().checkAbandoned(); + }catch (SQLException x) { + throw new RuntimeException(x); + } + } + + public void checkIdle() { + try { + createPool().checkIdle(); + }catch (SQLException x) { + throw new RuntimeException(x); + } + } + + public int getActive() { + try { + return createPool().getActive(); + }catch (SQLException x) { + throw new RuntimeException(x); + } + } + + public String getConnectionProperties() { + try { + return createPool().getPoolProperties().getConnectionProperties(); + }catch (SQLException x) { + throw new RuntimeException(x); + } + } + + public Properties getDbProperties() { + try { + return createPool().getPoolProperties().getDbProperties(); + }catch (SQLException x) { + throw new RuntimeException(x); + } + } + + public String getDefaultCatalog() { + try { + return createPool().getPoolProperties().getDefaultCatalog(); + }catch (SQLException x) { + throw new RuntimeException(x); + } + } + + public int getDefaultTransactionIsolation() { + try { + return createPool().getPoolProperties().getDefaultTransactionIsolation(); + }catch (SQLException x) { + throw new RuntimeException(x); + } + } + + public String getDriverClassName() { + try { + return createPool().getPoolProperties().getDriverClassName(); + }catch (SQLException x) { + throw new RuntimeException(x); + } + } + + public int getIdle() { + try { + return createPool().getIdle(); + }catch (SQLException x) { + throw new RuntimeException(x); + } + } + + public int getInitialSize() { + try { + return createPool().getPoolProperties().getInitialSize(); + }catch (SQLException x) { + throw new RuntimeException(x); + } + } + + public String getInitSQL() { + try { + return createPool().getPoolProperties().getInitSQL(); + }catch (SQLException x) { + throw new RuntimeException(x); + } + } + + public String getJdbcInterceptors() { + try { + return createPool().getPoolProperties().getJdbcInterceptors(); + }catch (SQLException x) { + throw new RuntimeException(x); + } + } + + public int getMaxActive() { + try { + return createPool().getPoolProperties().getMaxActive(); + }catch (SQLException x) { + throw new RuntimeException(x); + } + } + + public int getMaxIdle() { + try { + return createPool().getPoolProperties().getMaxIdle(); + }catch (SQLException x) { + throw new RuntimeException(x); + } + } + + public int getMaxWait() { + try { + return createPool().getPoolProperties().getMaxWait(); + }catch (SQLException x) { + throw new RuntimeException(x); + } + } + + public int getMinEvictableIdleTimeMillis() { + try { + return createPool().getPoolProperties().getMinEvictableIdleTimeMillis(); + }catch (SQLException x) { + throw new RuntimeException(x); + } + } + + public int getMinIdle() { + try { + return createPool().getPoolProperties().getMinIdle(); + }catch (SQLException x) { + throw new RuntimeException(x); + } + } + + public String getName() { + try { + return createPool().getName(); + }catch (SQLException x) { + throw new RuntimeException(x); + } + } + + public int getNumTestsPerEvictionRun() { + try { + return createPool().getPoolProperties().getNumTestsPerEvictionRun(); + }catch (SQLException x) { + throw new RuntimeException(x); + } + } + + public String getPassword() { + return "Password not available as DataSource/JMX operation."; + } + + public int getRemoveAbandonedTimeout() { + try { + return createPool().getPoolProperties().getRemoveAbandonedTimeout(); + }catch (SQLException x) { + throw new RuntimeException(x); + } + } + + 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 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/DataSourceProxy.java b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java index 9323e8639..78146bb45 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 @@ -27,13 +27,8 @@ import org.apache.juli.logging.LogFactory; /** * - *

Title: Uber Pool

- * - *

Description: A simple, yet efficient and powerful connection pool

- * - *

Copyright: Copyright (c) 2008 Filip Hanik

- * - *

+ * 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. * * @author Filip Hanik * @version 1.0 -- 2.11.0