Return-Path:
Delivered-To: apmail-tomcat-dev-archive@www.apache.org
Received: (qmail 92001 invoked from network); 20 Nov 2009 21:40:05 -0000
Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3)
by minotaur.apache.org with SMTP; 20 Nov 2009 21:40:05 -0000
Received: (qmail 46183 invoked by uid 500); 20 Nov 2009 21:40:04 -0000
Delivered-To: apmail-tomcat-dev-archive@tomcat.apache.org
Received: (qmail 46083 invoked by uid 500); 20 Nov 2009 21:40:03 -0000
Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm
Precedence: bulk
List-Help:
List-Unsubscribe:
List-Post:
List-Id:
Reply-To: "Tomcat Developers List"
Delivered-To: mailing list dev@tomcat.apache.org
Received: (qmail 46053 invoked by uid 99); 20 Nov 2009 21:40:03 -0000
Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230)
by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Nov 2009 21:40:03 +0000
X-ASF-Spam-Status: No, hits=-2000.0 required=10.0
tests=ALL_TRUSTED
X-Spam-Check-By: apache.org
Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4)
by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Nov 2009 21:39:59 +0000
Received: by eris.apache.org (Postfix, from userid 65534)
id E14E523888FD; Fri, 20 Nov 2009 21:39:37 +0000 (UTC)
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: svn commit: r882723 - in /tomcat/trunk/modules/jdbc-pool: ./ doc/
java/org/apache/tomcat/jdbc/pool/ java/org/apache/tomcat/jdbc/pool/jmx/
Date: Fri, 20 Nov 2009 21:39:37 -0000
To: dev@tomcat.apache.org
From: fhanik@apache.org
X-Mailer: svnmailer-1.0.8
Message-Id: <20091120213937.E14E523888FD@eris.apache.org>
X-Virus-Checked: Checked by ClamAV on apache.org
Author: fhanik
Date: Fri Nov 20 21:39:36 2009
New Revision: 882723
URL: http://svn.apache.org/viewvc?rev=882723&view=rev
Log:
Add in DataSource supprot
Add in XA support
Modified:
tomcat/trunk/modules/jdbc-pool/.classpath
tomcat/trunk/modules/jdbc-pool/doc/jdbc-pool.xml
tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java
tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java
tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolConfiguration.java
tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java
tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ProxyConnection.java
tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java
Modified: tomcat/trunk/modules/jdbc-pool/.classpath
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/.classpath?rev=882723&r1=882722&r2=882723&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/.classpath (original)
+++ tomcat/trunk/modules/jdbc-pool/.classpath Fri Nov 20 21:39:36 2009
@@ -7,5 +7,6 @@
+
Modified: tomcat/trunk/modules/jdbc-pool/doc/jdbc-pool.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/doc/jdbc-pool.xml?rev=882723&r1=882722&r2=882723&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/doc/jdbc-pool.xml (original)
+++ tomcat/trunk/modules/jdbc-pool/doc/jdbc-pool.xml Fri Nov 20 21:39:36 2009
@@ -88,6 +88,9 @@
Get JMX notifications and log entries when connections are suspected for being abandoned. This is similar to
the removeAbandonedTimeout
but it doesn't take any action, only reports the information.
This is achieved using the suspectTimeout
attribute.
+ Connections can be retrieved from a java.sql.Driver
or a javax.sql.DataSource
+ This is achieved using the dataSource
and dataSourceJNDI
attributes.
+ XA connection support
@@ -401,6 +404,14 @@
logged and a JMX notification gets sent once.
+
+ (javax.sql.DataSource)
+
+
+
+ (String)
+
+
Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java?rev=882723&r1=882722&r2=882723&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java (original)
+++ tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java Fri Nov 20 21:39:36 2009
@@ -277,7 +277,7 @@
}
try {
- getProxyConstructor(con.getConnection() instanceof XAConnection);
+ getProxyConstructor(con.getXAConnection() != null);
//create the proxy
//TODO possible optimization, keep track if this connection was returned properly, and don't generate a new facade
Connection connection = (Connection)proxyClassConstructor.newInstance(new Object[] { handler });
Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java?rev=882723&r1=882722&r2=882723&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java (original)
+++ tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceFactory.java Fri Nov 20 21:39:36 2009
@@ -104,6 +104,10 @@
protected static final String PROP_USE_EQUALS = "useEquals";
protected static final String PROP_USE_CON_LOCK = "useLock";
+ protected static final String PROP_DATASOURCE= "dataSource";
+ protected static final String PROP_DATASOURCE_JNDI = "dataSourceJNDI";
+
+
public static final int UNKNOWN_TRANSACTIONISOLATION = -1;
public static final String OBJECT_NAME = "object_name";
@@ -147,7 +151,9 @@
OBJECT_NAME,
PROP_ABANDONWHENPERCENTAGEFULL,
PROP_MAXAGE,
- PROP_USE_CON_LOCK
+ PROP_USE_CON_LOCK,
+ PROP_DATASOURCE,
+ PROP_DATASOURCE_JNDI,
};
// -------------------------------------------------- ObjectFactory Methods
@@ -425,6 +431,16 @@
poolProperties.setUseLock(Boolean.parseBoolean(value));
}
+ value = properties.getProperty(PROP_DATASOURCE);
+ if (value != null) {
+ //this should never happen
+ log.error("Can't set dataSource property as a string, this must be a javax.sql.DataSource object.");
+ }
+
+ value = properties.getProperty(PROP_DATASOURCE_JNDI);
+ if (value != null) {
+ poolProperties.setDataSourceJNDI(value);
+ }
return poolProperties;
}
Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java?rev=882723&r1=882722&r2=882723&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java (original)
+++ tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java Fri Nov 20 21:39:36 2009
@@ -1011,4 +1011,33 @@
getPoolProperties().setName(name);
}
+ /**
+ * {@inheritDoc}
+ */
+ public void setDataSource(javax.sql.DataSource ds) {
+ getPoolProperties().setDataSource(ds);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public javax.sql.DataSource getDataSource() {
+ return getPoolProperties().getDataSource();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setDataSourceJNDI(String jndiDS) {
+ getPoolProperties().setDataSourceJNDI(jndiDS);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getDataSourceJNDI() {
+ return getPoolProperties().getDataSourceJNDI();
+ }
+
}
Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolConfiguration.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolConfiguration.java?rev=882723&r1=882722&r2=882723&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolConfiguration.java (original)
+++ tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolConfiguration.java Fri Nov 20 21:39:36 2009
@@ -717,5 +717,39 @@
*/
public int getSuspectTimeout();
+ /**
+ * Injects a datasource that will be used to retrieve/create connections.
+ * If a data source is set, the {@link PoolConfiguration#getUrl()} and {@link PoolConfiguration#getDriverClassName()} methods are ignored
+ * and not used by the pool. If the {@link PoolConfiguration#getUsername()} and {@link PoolConfiguration#getPassword()}
+ * values are set, the method {@link javax.sql.DataSource#getConnection(String, String)} method will be called instead of the
+ * {@link javax.sql.DataSource#getConnection()} method.
+ * If the data source implements {@link javax.sql.XADataSource} the methods
+ * {@link javax.sql.XADataSource#getXAConnection()} and {@link javax.sql.XADataSource#getXAConnection(String,String)}
+ * will be invoked.
+ * @param ds the {@link javax.sql.DataSource} to be used for creating connections to be pooled.
+ */
+ public void setDataSource(javax.sql.DataSource ds);
+
+ /**
+ * Returns a datasource, if one exists that is being used to create connections.
+ * This method will return null if the pool is using a {@link java.sql.Driver}
+ * @return the {@link javax.sql.DataSource} to be used for creating connections to be pooled or null if a Driver is used.
+ */
+ public javax.sql.DataSource getDataSource();
+
+ /**
+ * Configure the connection pool to use a DataSource according to {@link PoolConfiguration#setDataSource(javax.sql.DataSource)}
+ * But instead of injecting the object, specify the JNDI location.
+ * After a successful JNDI look, the {@link PoolConfiguration#getDataSource()} will not return null.
+ * @param jndiDS -the JNDI string @TODO specify the rules here.
+ */
+ public void setDataSourceJNDI(String jndiDS);
+
+ /**
+ * Returns the JNDI string configured for data source usage.
+ * @return
+ */
+ public String getDataSourceJNDI();
+
}
\ No newline at end of file
Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java?rev=882723&r1=882722&r2=882723&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java (original)
+++ tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java Fri Nov 20 21:39:36 2009
@@ -73,8 +73,10 @@
protected int abandonWhenPercentageFull = 0;
protected long maxAge = 0;
protected boolean useLock = false;
- private InterceptorDefinition[] interceptors = null;
+ protected InterceptorDefinition[] interceptors = null;
protected int suspectTimeout = 0;
+ protected javax.sql.DataSource dataSource = null;
+ protected String dataSourceJNDI = null;
/**
@@ -870,6 +872,36 @@
this.useLock = useLock;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setDataSource(javax.sql.DataSource ds) {
+ this.dataSource = ds;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public javax.sql.DataSource getDataSource() {
+ return dataSource;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setDataSourceJNDI(String jndiDS) {
+ this.dataSourceJNDI = jndiDS;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getDataSourceJNDI() {
+ return this.dataSourceJNDI;
+ }
+
public static Properties getProperties(String propText, Properties props) {
if (props==null) props = new Properties();
Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java?rev=882723&r1=882722&r2=882723&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java (original)
+++ tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java Fri Nov 20 21:39:36 2009
@@ -69,6 +69,11 @@
* The underlying database connection
*/
private volatile java.sql.Connection connection;
+
+ /**
+ * If using a XAConnection underneath.
+ */
+ private volatile javax.sql.XAConnection xaConnection;
/**
* When we track abandon traces, this string holds the thread dump
*/
@@ -142,6 +147,47 @@
log.debug("Unable to disconnect previous connection.", x);
} //catch
} //end if
+ if (poolProperties.getDataSource()==null && poolProperties.getDataSourceJNDI()!=null) {
+ //TODO lookup JNDI name
+ }
+
+ if (poolProperties.getDataSource()!=null) {
+ connectUsingDataSource();
+ } else {
+ connectUsingDriver();
+ }
+
+ //set up the default state, unless we expect the interceptor to do it
+ if (poolProperties.getJdbcInterceptors()==null || poolProperties.getJdbcInterceptors().indexOf(ConnectionState.class.getName())<0) {
+ if (poolProperties.getDefaultReadOnly()!=null) connection.setReadOnly(poolProperties.getDefaultReadOnly().booleanValue());
+ if (poolProperties.getDefaultAutoCommit()!=null) connection.setAutoCommit(poolProperties.getDefaultAutoCommit().booleanValue());
+ if (poolProperties.getDefaultCatalog()!=null) connection.setCatalog(poolProperties.getDefaultCatalog());
+ if (poolProperties.getDefaultTransactionIsolation()!=DataSourceFactory.UNKNOWN_TRANSACTIONISOLATION) connection.setTransactionIsolation(poolProperties.getDefaultTransactionIsolation());
+ }
+ this.discarded = false;
+ this.lastConnected = System.currentTimeMillis();
+ }
+
+ protected void connectUsingDataSource() throws SQLException {
+ if (poolProperties.getDataSource() instanceof javax.sql.XADataSource) {
+ javax.sql.XADataSource xds = (javax.sql.XADataSource)poolProperties.getDataSource();
+ if (poolProperties.getUsername()!=null && poolProperties.getPassword()!=null) {
+ xaConnection = xds.getXAConnection(poolProperties.getUsername(), poolProperties.getPassword());
+ connection = xaConnection.getConnection();
+ } else {
+ xaConnection = xds.getXAConnection();
+ connection = xaConnection.getConnection();
+ }
+ } else {
+ javax.sql.DataSource ds = poolProperties.getDataSource();
+ if (poolProperties.getUsername()!=null && poolProperties.getPassword()!=null) {
+ connection = ds.getConnection(poolProperties.getUsername(), poolProperties.getPassword());
+ } else {
+ connection = ds.getConnection();
+ }
+ }
+ }
+ protected void connectUsingDriver() throws SQLException {
java.sql.Driver driver = null;
try {
driver = (java.sql.Driver) Class.forName(poolProperties.getDriverClassName(),
@@ -180,16 +226,6 @@
if (connection==null) {
throw new SQLException("Driver:"+driver+" returned null for URL:"+driverURL);
}
-
- //set up the default state, unless we expect the interceptor to do it
- if (poolProperties.getJdbcInterceptors()==null || poolProperties.getJdbcInterceptors().indexOf(ConnectionState.class.getName())<0) {
- if (poolProperties.getDefaultReadOnly()!=null) connection.setReadOnly(poolProperties.getDefaultReadOnly().booleanValue());
- if (poolProperties.getDefaultAutoCommit()!=null) connection.setAutoCommit(poolProperties.getDefaultAutoCommit().booleanValue());
- if (poolProperties.getDefaultCatalog()!=null) connection.setCatalog(poolProperties.getDefaultCatalog());
- if (poolProperties.getDefaultTransactionIsolation()!=DataSourceFactory.UNKNOWN_TRANSACTIONISOLATION) connection.setTransactionIsolation(poolProperties.getDefaultTransactionIsolation());
- }
- this.discarded = false;
- this.lastConnected = System.currentTimeMillis();
}
/**
@@ -229,6 +265,7 @@
}
}
connection = null;
+ xaConnection = null;
lastConnected = -1;
if (finalize) parent.finalize(this);
}
@@ -502,6 +539,14 @@
return this.connection;
}
+ /**
+ * Returns the underlying XA connection
+ * @return the underlying XA connection as it was returned from the Datasource
+ */
+ public javax.sql.XAConnection getXAConnection() {
+ return this.xaConnection;
+ }
+
/**
* Returns the timestamp of when the connection was last connected to the database.
Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ProxyConnection.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ProxyConnection.java?rev=882723&r1=882722&r2=882723&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ProxyConnection.java (original)
+++ tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ProxyConnection.java Fri Nov 20 21:39:36 2009
@@ -19,6 +19,8 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.SQLException;
+
+import javax.sql.XAConnection;
/**
* A ProxyConnection object is the bottom most interceptor that wraps an object of type
* {@link PooledConnection}. The ProxyConnection intercepts three methods:
@@ -95,6 +97,17 @@
return this.toString();
} else if (compare(GETCONNECTION_VAL,method) && connection!=null) {
return connection.getConnection();
+ } else if (method.getClass().equals(XAConnection.class)) {
+ try {
+ return method.invoke(connection.getXAConnection(),args);
+ }catch (Throwable t) {
+ if (t instanceof InvocationTargetException) {
+ InvocationTargetException it = (InvocationTargetException)t;
+ throw it.getCause()!=null?it.getCause():it;
+ } else {
+ throw t;
+ }
+ }
}
if (isClosed()) throw new SQLException("Connection has already been closed.");
if (compare(UNWRAP_VAL,method)) {
Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java?rev=882723&r1=882722&r2=882723&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java (original)
+++ tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java Fri Nov 20 21:39:36 2009
@@ -570,5 +570,34 @@
public void setSuspectTimeout(int seconds) {
//no op
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setDataSource(javax.sql.DataSource ds) {
+ getPoolProperties().setDataSource(ds);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public javax.sql.DataSource getDataSource() {
+ return getPoolProperties().getDataSource();
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setDataSourceJNDI(String jndiDS) {
+ //noop
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getDataSourceJNDI() {
+ return getPoolProperties().getDataSourceJNDI();
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org