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 @@
<classpathentry kind="var"
path="TOMCAT_LIBS_BASE/tomcat6-deps/dbcp/tomcat-dbcp.jar"
sourcepath="/TOMCAT_LIBS_BASE/tomcat6-deps/dbcp/src/java"/>
<classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib"
path="/development/tomcat/trunk/trunk/modules/jdbc-pool/includes/h2/bin/h2-1.1.115.jar"/>
+ <classpathentry kind="lib"
path="/development/tomcat/trunk/trunk/modules/jdbc-pool/includes/mysql-connector-java-5.1.7-bin.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
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 @@
<li>Get JMX notifications and log entries when connections are suspected
for being abandoned. This is similar to
the <code>removeAbandonedTimeout</code> but it doesn't take any
action, only reports the information.
This is achieved using the <code>suspectTimeout</code>
attribute.</li>
+ <li>Connections can be retrieved from a <code>java.sql.Driver</code> or
a <code>javax.sql.DataSource</code>
+ This is achieved using the <code>dataSource</code> and
<code>dataSourceJNDI</code> attributes.</li>
+ <li>XA connection support</li>
</ol>
</p>
@@ -401,6 +404,14 @@
logged and a JMX notification gets sent once.
</p>
</attribute>
+ <attribute name="dataSource" required="false">
+ <p>(javax.sql.DataSource)
+ </p>
+ </attribute>
+ <attribute name="dataSourceJNDI" required="false">
+ <p>(String)
+ </p>
+ </attribute>
</attributes>
</subsection>
</section>
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: [email protected]
For additional commands, e-mail: [email protected]