use of com.arjuna.ats.internal.jdbc.drivers.modifiers.ConnectionModifier in project narayana by jbosstm.
the class ConnectionImple method registerDatabase.
/**
* Whenever a JDBC call is invoked on us we get an XAResource and try to
* register it with the transaction. If the same thread causes this to
* happen many times within the same transaction then we will currently
* attempt to get and register many redundant XAResources for it. The JTA
* implementation will detect this and ignore all but the first for each
* thread. However, a further optimisation would be to trap such calls here
* and not do a registration at all. This would require the connection
* object to be informed whenever a transaction completes so that it could
* flush its cache of XAResources though.
*/
protected final synchronized void registerDatabase() throws SQLException {
if (jdbcLogger.logger.isTraceEnabled()) {
jdbcLogger.logger.trace("ConnectionImple.registerDatabase ()");
}
boolean needsClose = _theConnection == null;
Connection theConnection = getConnection();
if (theConnection != null) {
XAResource xares = null;
try {
javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
javax.transaction.Transaction tx = tm.getTransaction();
if (tx == null) {
return;
}
if (!_transactionalDriverXAConnectionConnection.setTransaction(tx))
throw new SQLException(jdbcLogger.i18NLogger.get_alreadyassociated());
Object[] params;
if (_theModifier != null)
params = new Object[2];
else
params = new Object[1];
params[com.arjuna.ats.jta.transaction.Transaction.XACONNECTION] = _transactionalDriverXAConnectionConnection;
if (_theModifier != null)
params[com.arjuna.ats.jta.transaction.Transaction.XAMODIFIER] = (XAModifier) _theModifier;
/*
* Use our extended version of enlistResource.
*/
xares = _transactionalDriverXAConnectionConnection.getResource();
if (!((com.arjuna.ats.jta.transaction.Transaction) tx).enlistResource(xares, params)) {
try {
tx.setRollbackOnly();
} catch (Exception e) {
jdbcLogger.i18NLogger.warn_rollbackerror("ConnectionImple.registerDatabase");
SQLException sqlException = new SQLException(e.toString());
sqlException.initCause(e);
throw sqlException;
}
throw new SQLException("ConnectionImple.registerDatabase - " + jdbcLogger.i18NLogger.get_enlistfailed());
} else {
getModifier();
if (_theModifier == null) {
jdbcLogger.i18NLogger.info_closingconnectionnull(_theConnection.toString());
// no indication about connections, so assume close immediately
/*
* Don't return just yet. Drop through bottom of these clauses and
* close _theConnection and _recoveryConnection.
*
* delayClose is false at this point.
*
* JBTM-789.
*/
} else {
if (((ConnectionModifier) _theModifier).supportsMultipleConnections()) {
/*
* We can't close the connection until the transaction has
* terminated, so register a Synchronization here.
*/
jdbcLogger.i18NLogger.debug_closingconnection(_theConnection.toString());
jtaPropertyManager.getJTAEnvironmentBean().getTransactionSynchronizationRegistry().registerInterposedSynchronization(new ConnectionSynchronization(this));
}
}
}
} catch (RollbackException e1) {
SQLException sqlException = new SQLException("ConnectionImple.registerDatabase - " + e1);
sqlException.initCause(e1);
throw sqlException;
} catch (SystemException e2) {
SQLException sqlException = new SQLException("ConnectionImple.registerDatabase - " + e2);
sqlException.initCause(e2);
throw sqlException;
} catch (SQLException e3) {
throw e3;
} catch (Exception e4) {
SQLException sqlException = new SQLException(e4.toString());
sqlException.initCause(e4);
throw sqlException;
}
}
}
Aggregations