Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the user to provide a reference to an XADataSource #758

Merged
merged 1 commit into from Jan 7, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -1,15 +1,15 @@
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<entry key="ObjectStoreEnvironmentBean.objectStoreType">com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore</entry>
<entry key="ObjectStoreEnvironmentBean.jdbcAccess">com.arjuna.ats.internal.arjuna.objectstore.jdbc.accessors.DynamicDataSourceJDBCAccess;ClassName=org.h2.jdbcx.JdbcDataSource;URL=jdbc:h2:target/h2/JBTMDB;User=sa;Password=sa</entry>
<entry key="ObjectStoreEnvironmentBean.jdbcAccess">com.arjuna.ats.internal.arjuna.objectstore.jdbc.accessors.DynamicDataSourceJDBCAccess;ClassName=org.h2.jdbcx.JdbcDataSource;URL=jdbc:h2:./h2/JBTMDB;User=sa;Password=sa</entry>
<entry key="ObjectStoreEnvironmentBean.tablePrefix">Action</entry>
<entry key="ObjectStoreEnvironmentBean.dropTable">true</entry>
<entry key="ObjectStoreEnvironmentBean.stateStore.objectStoreType">com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore</entry>
<entry key="ObjectStoreEnvironmentBean.stateStore.jdbcAccess">com.arjuna.ats.internal.arjuna.objectstore.jdbc.accessors.DynamicDataSourceJDBCAccess;ClassName=org.h2.jdbcx.JdbcDataSource;URL=jdbc:h2:target/h2/JBTMDB;User=sa;Password=sa</entry>
<entry key="ObjectStoreEnvironmentBean.stateStore.jdbcAccess">com.arjuna.ats.internal.arjuna.objectstore.jdbc.accessors.DynamicDataSourceJDBCAccess;ClassName=org.h2.jdbcx.JdbcDataSource;URL=jdbc:h2:./h2/JBTMDB;User=sa;Password=sa</entry>
<entry key="ObjectStoreEnvironmentBean.stateStore.tablePrefix">stateStore</entry>
<entry key="ObjectStoreEnvironmentBean.stateStore.dropTable">true</entry>
<entry key="ObjectStoreEnvironmentBean.communicationStore.objectStoreType">com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore</entry>
<entry key="ObjectStoreEnvironmentBean.communicationStore.jdbcAccess">com.arjuna.ats.internal.arjuna.objectstore.jdbc.accessors.DynamicDataSourceJDBCAccess;ClassName=org.h2.jdbcx.JdbcDataSource;URL=jdbc:h2:target/h2/JBTMDB;User=sa;Password=sa</entry>
<entry key="ObjectStoreEnvironmentBean.communicationStore.jdbcAccess">com.arjuna.ats.internal.arjuna.objectstore.jdbc.accessors.DynamicDataSourceJDBCAccess;ClassName=org.h2.jdbcx.JdbcDataSource;URL=jdbc:h2:./h2/JBTMDB;User=sa;Password=sa</entry>
<entry key="ObjectStoreEnvironmentBean.communicationStore.tablePrefix">Communication</entry>
<entry key="ObjectStoreEnvironmentBean.communicationStore.dropTable">true</entry>
</properties>
@@ -51,6 +51,7 @@
import java.util.concurrent.Executor;

import javax.sql.XAConnection;
import javax.sql.XADataSource;
import javax.transaction.RollbackException;
import javax.transaction.Status;
import javax.transaction.SystemException;
@@ -94,22 +95,29 @@ public ConnectionImple(String dbName, Properties info) throws SQLException
String user = null;
String passwd = null;
String dynamic = null;
Object xaDataSource = null;

if (info != null)
{
user = info.getProperty(TransactionalDriver.userName);
passwd = info.getProperty(TransactionalDriver.password);
dynamic = info.getProperty(TransactionalDriver.dynamicClass);
xaDataSource = info.get(TransactionalDriver.XADataSource);
}

if ((dynamic == null) || (dynamic.equals("")))
if (xaDataSource != null)
{
_recoveryConnection = new IndirectRecoverableConnection(dbName,
_transactionalDriverXAConnectionConnection = new ProvidedXADataSourceConnection(dbName, user,
passwd, (XADataSource) xaDataSource, this);
}
else if ((dynamic == null) || (dynamic.equals("")))
{
_transactionalDriverXAConnectionConnection = new IndirectRecoverableConnection(dbName,
user, passwd, this);
}
else
{
_recoveryConnection = new DirectRecoverableConnection(dbName, user,
_transactionalDriverXAConnectionConnection = new DirectRecoverableConnection(dbName, user,
passwd, dynamic, this);
}

@@ -124,25 +132,30 @@ public ConnectionImple(String dbName, Properties info) throws SQLException
public ConnectionImple(String dbName, String user, String passwd)
throws SQLException
{
this(dbName, user, passwd, null);
this(dbName, user, passwd, null, null);
}

public ConnectionImple(String dbName, String user, String passwd,
String dynamic) throws SQLException
String dynamic, Object xaDataSource) throws SQLException
{
if (jdbcLogger.logger.isTraceEnabled()) {
jdbcLogger.logger.trace("ConnectionImple.ConnectionImple ( " + dbName + ", " + user
+ ", " + passwd + ", " + dynamic + " )");
}

if ((dynamic == null) || (dynamic.equals("")))
if (xaDataSource != null)
{
_transactionalDriverXAConnectionConnection = new ProvidedXADataSourceConnection(dbName, user,
passwd, (XADataSource) xaDataSource, this);
}
else if ((dynamic == null) || (dynamic.equals("")))
{
_recoveryConnection = new IndirectRecoverableConnection(dbName,
_transactionalDriverXAConnectionConnection = new IndirectRecoverableConnection(dbName,
user, passwd, this);
}
else
{
_recoveryConnection = new DirectRecoverableConnection(dbName, user,
_transactionalDriverXAConnectionConnection = new DirectRecoverableConnection(dbName, user,
passwd, dynamic, this);
}

@@ -290,7 +303,7 @@ public void close() throws SQLException
* can't.
*/

if (!_recoveryConnection.inuse())
if (!_transactionalDriverXAConnectionConnection.inuse())
{
ConnectionManager.remove(this); // finalize?
}
@@ -313,9 +326,9 @@ public void close() throws SQLException

if (tx != null)
{
if (_recoveryConnection.validTransaction(tx))
if (_transactionalDriverXAConnectionConnection.validTransaction(tx))
{
XAResource xares = _recoveryConnection.getResource();
XAResource xares = _transactionalDriverXAConnectionConnection.getResource();

if (!tx.delistResource(xares, XAResource.TMSUCCESS))
throw new SQLException(
@@ -355,7 +368,7 @@ public void close() throws SQLException

if (delayClose)
{
tx.registerSynchronization(new ConnectionSynchronization(_theConnection, _recoveryConnection));
tx.registerSynchronization(new ConnectionSynchronization(_theConnection, _transactionalDriverXAConnectionConnection));

_theConnection = null;
}
@@ -367,7 +380,7 @@ public void close() throws SQLException
if (!delayClose) // close now
{
if (_theModifier != null)
_recoveryConnection.closeCloseCurrentConnection();
_transactionalDriverXAConnectionConnection.closeCloseCurrentConnection();


if (_theConnection != null && !_theConnection.isClosed())
@@ -421,7 +434,7 @@ public DatabaseMetaData getMetaData() throws SQLException

public void setReadOnly(boolean ro) throws SQLException
{
if (!_recoveryConnection.inuse())
if (!_transactionalDriverXAConnectionConnection.inuse())
{
getConnection().setReadOnly(ro);
}
@@ -486,7 +499,11 @@ public void clearWarnings() throws SQLException

public final RecoverableXAConnection recoveryConnection()
{
return _recoveryConnection;
if (_transactionalDriverXAConnectionConnection instanceof RecoverableXAConnection) {
return (RecoverableXAConnection) _transactionalDriverXAConnectionConnection;
} else {
return null;
}
}

/*
@@ -825,7 +842,7 @@ protected final XAResource getXAResource()
{
try
{
return _recoveryConnection.getResource();
return _transactionalDriverXAConnectionConnection.getResource();
}
catch (Exception e)
{
@@ -860,7 +877,7 @@ final void reset()
if (_theConnection != null && !_theConnection.isClosed())
return _theConnection;

XAConnection xaConn = _recoveryConnection.getConnection();
XAConnection xaConn = _transactionalDriverXAConnectionConnection.getConnection();

if (xaConn != null)
{
@@ -897,7 +914,7 @@ final void reset()

final ConnectionControl connectionControl()
{
return (ConnectionControl) _recoveryConnection;
return (ConnectionControl) _transactionalDriverXAConnectionConnection;
}

protected final boolean transactionRunning() throws SQLException
@@ -959,7 +976,7 @@ protected final synchronized void registerDatabase() throws SQLException
* Already enlisted with this transaction?
*/

if (!_recoveryConnection.setTransaction(tx))
if (!_transactionalDriverXAConnectionConnection.setTransaction(tx))
throw new SQLException( jdbcLogger.i18NLogger.get_alreadyassociated() );

Object[] params;
@@ -969,7 +986,7 @@ protected final synchronized void registerDatabase() throws SQLException
else
params = new Object[1];

params[com.arjuna.ats.jta.transaction.Transaction.XACONNECTION] = _recoveryConnection;
params[com.arjuna.ats.jta.transaction.Transaction.XACONNECTION] = _transactionalDriverXAConnectionConnection;

if (_theModifier != null)
params[com.arjuna.ats.jta.transaction.Transaction.XAMODIFIER] = (XAModifier) _theModifier;
@@ -978,7 +995,7 @@ protected final synchronized void registerDatabase() throws SQLException
* Use our extended version of enlistResource.
*/

xares = _recoveryConnection.getResource();
xares = _transactionalDriverXAConnectionConnection.getResource();

if (!((com.arjuna.ats.jta.transaction.Transaction) tx)
.enlistResource(xares, params))
@@ -1057,7 +1074,7 @@ protected final void checkTransaction() throws SQLException
* Now check that we are not already associated with a transaction.
*/

if (!_recoveryConnection.validTransaction(tx))
if (!_transactionalDriverXAConnectionConnection.validTransaction(tx))
throw new SQLException(
jdbcLogger.i18NLogger.get_alreadyassociatedcheck());
}
@@ -1087,7 +1104,7 @@ private final void getModifier()

_theModifier = ModifierFactory.getModifier(name, major, minor);

((ConnectionControl) _recoveryConnection)
((ConnectionControl) _transactionalDriverXAConnectionConnection)
.setModifier((ConnectionModifier) _theModifier);
}
catch (Exception ex)
@@ -1097,7 +1114,7 @@ private final void getModifier()
}
}

private RecoverableXAConnection _recoveryConnection;
private TransactionalDriverXAConnection _transactionalDriverXAConnectionConnection;

private java.lang.Object _theModifier;

@@ -34,6 +34,7 @@
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;

@@ -67,8 +68,10 @@ public static synchronized Connection create (String dbUrl, Properties info) thr

if (poolingEnabled)
{
for (ConnectionImple conn : _connections)
Iterator<ConnectionImple> iterator = _connections.iterator();
while (iterator.hasNext())
{
ConnectionImple conn = iterator.next();
ConnectionControl connControl = conn.connectionControl();
TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
Transaction tx1, tx2 = null;
@@ -116,7 +119,7 @@ public static synchronized Connection create (String dbUrl, Properties info) thr
// no longer being used by a transaction, so let's discard. JBTM-764

if (tx1 == null)
remove(conn);
iterator.remove();
}
}
}
@@ -47,7 +47,7 @@
public class ConnectionSynchronization implements Synchronization
{

public ConnectionSynchronization (Connection conn, RecoverableXAConnection rxac)
public ConnectionSynchronization (Connection conn, TransactionalDriverXAConnection rxac)
{
_theConnection = conn;
_recoveryConnection = rxac;
@@ -76,6 +76,6 @@ public void beforeCompletion()
}

private Connection _theConnection = null;
private RecoverableXAConnection _recoveryConnection;
private TransactionalDriverXAConnection _recoveryConnection;
}

@@ -55,7 +55,7 @@
* @since JTS 2.0.
*/

public class DirectRecoverableConnection implements RecoverableXAConnection, ConnectionControl
public class DirectRecoverableConnection implements RecoverableXAConnection, ConnectionControl, TransactionalDriverXAConnection
{

public DirectRecoverableConnection () throws SQLException
@@ -60,7 +60,7 @@
* @since JTS 2.0.
*/

public class IndirectRecoverableConnection implements RecoverableXAConnection, ConnectionControl
public class IndirectRecoverableConnection implements RecoverableXAConnection, ConnectionControl, TransactionalDriverXAConnection
{

public IndirectRecoverableConnection () throws SQLException
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.