You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ps...@apache.org on 2009/10/25 19:19:38 UTC
svn commit: r829623 - in /commons/proper/dbcp/trunk:
src/java/org/apache/commons/dbcp/managed/BasicManagedDataSource.java
xdocs/changes.xml
Author: psteitz
Date: Sun Oct 25 18:19:37 2009
New Revision: 829623
URL: http://svn.apache.org/viewvc?rev=829623&view=rev
Log:
Made XADataSource configurable in BasicManagedDataSource.
JIRA: DBCP-289
Reported and patched by Marc Kannegießer.
Modified:
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/managed/BasicManagedDataSource.java
commons/proper/dbcp/trunk/xdocs/changes.xml
Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/managed/BasicManagedDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/managed/BasicManagedDataSource.java?rev=829623&r1=829622&r2=829623&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/managed/BasicManagedDataSource.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/managed/BasicManagedDataSource.java Sun Oct 25 18:19:37 2009
@@ -52,9 +52,38 @@
* @version $Revision$
*/
public class BasicManagedDataSource extends BasicDataSource {
+ /** Transaction Registry */
protected TransactionRegistry transactionRegistry;
+ /** Transaction Manager */
protected TransactionManager transactionManager;
+ /** XA datasource class name */
protected String xaDataSource;
+ /** XA datasource instance */
+ private XADataSource xaDataSourceInstance;
+
+ /**
+ * Gets the XADataSource instance used by the XAConnectionFactory.
+ *
+ * @return the XADataSource
+ */
+ public synchronized XADataSource getXaDataSourceInstance() {
+ return xaDataSourceInstance;
+ }
+
+ /**
+ * <p>Sets the XADataSource instance used by the XAConnectionFactory.</p>
+ * <p>
+ * Note: this method currently has no effect once the pool has been
+ * initialized. The pool is initialized the first time one of the
+ * following methods is invoked: <code>getConnection, setLogwriter,
+ * setLoginTimeout, getLoginTimeout, getLogWriter.</code></p>
+ *
+ * @param xaDataSourceInstance XADataSource instance
+ */
+ public synchronized void setXaDataSourceInstance(XADataSource xaDataSourceInstance) {
+ this.xaDataSourceInstance = xaDataSourceInstance;
+ xaDataSource = xaDataSourceInstance == null ? null : xaDataSourceInstance.getClass().getName();
+ }
/**
* Gets the required transaction manager property.
@@ -101,30 +130,30 @@
return xaConnectionFactory;
}
- // Load the XA data source class
- Class xaDataSourceClass = null;
- try {
- xaDataSourceClass = Class.forName(xaDataSource);
- } catch (Throwable t) {
- String message = "Cannot load XA data source class '" + xaDataSource + "'";
- logWriter.println(message);
- t.printStackTrace(logWriter);
- throw new SQLException(message, t);
- }
-
- // Create the xa data source instance
- XADataSource xaDataSource = null;
- try {
- xaDataSource = (XADataSource) xaDataSourceClass.newInstance();
- } catch (Throwable t) {
- String message = "Cannot create XA data source of class '" + xaDataSource + "'";
- logWriter.println(message);
- t.printStackTrace(logWriter);
- throw new SQLException(message, t);
+ // Create the XADataSource instance using the configured class name if it has not been set
+ if (xaDataSourceInstance == null) {
+ Class xaDataSourceClass = null;
+ try {
+ xaDataSourceClass = Class.forName(xaDataSource);
+ } catch (Throwable t) {
+ String message = "Cannot load XA data source class '" + xaDataSource + "'";
+ logWriter.println(message);
+ t.printStackTrace(logWriter);
+ throw new SQLException(message, t);
+ }
+
+ try {
+ xaDataSourceInstance = (XADataSource) xaDataSourceClass.newInstance();
+ } catch (Throwable t) {
+ String message = "Cannot create XA data source of class '" + xaDataSource + "'";
+ logWriter.println(message);
+ t.printStackTrace(logWriter);
+ throw new SQLException(message, t);
+ }
}
// finally, create the XAConectionFactory using the XA data source
- XAConnectionFactory xaConnectionFactory = new DataSourceXAConnectionFactory(getTransactionManager(), xaDataSource, username, password);
+ XAConnectionFactory xaConnectionFactory = new DataSourceXAConnectionFactory(getTransactionManager(), xaDataSourceInstance, username, password);
transactionRegistry = xaConnectionFactory.getTransactionRegistry();
return xaConnectionFactory;
}
Modified: commons/proper/dbcp/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/xdocs/changes.xml?rev=829623&r1=829622&r2=829623&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/xdocs/changes.xml (original)
+++ commons/proper/dbcp/trunk/xdocs/changes.xml Sun Oct 25 18:19:37 2009
@@ -42,6 +42,9 @@
new features as well as bug fixes and instrumentation. Some bug fixes
will change semantics (e.g. connection close will become idempotent).
The minimum JDK level will be increased to 1.4">
+ <action dev="psteitz" type="update" issue="DBCP-289" due-to="Marc KannegieÃer">
+ Made XADataSource configurable in BasicManagedDataSource.
+ </action>
<action dev="psteitz" type="fix" issue="DBCP-294" due-to="Philippe Mouawad">
Added PoolableManagedConnection and PoolableManagedConnectionFactory so that
pooled managed connections can unregister themselves from transaction registries,