use of javax.transaction.xa.XAResource in project spring-boot by spring-projects.
the class DataSourceXAResourceRecoveryHelperTests method shouldFailToCreateConnectionAndNotGetXAResource.
@Test
public void shouldFailToCreateConnectionAndNotGetXAResource() throws SQLException {
given(this.xaDataSource.getXAConnection()).willThrow(new SQLException("Test exception"));
XAResource[] xaResources = this.recoveryHelper.getXAResources();
assertThat(xaResources.length).isEqualTo(0);
verify(this.xaDataSource, times(1)).getXAConnection();
verify(this.xaConnection, times(0)).getXAResource();
}
use of javax.transaction.xa.XAResource in project hazelcast by hazelcast.
the class HazelcastXATest method close.
private void close(boolean error, XAResource... xaResource) throws Exception {
int flag = XAResource.TMSUCCESS;
// get the current tx
Transaction tx = tm.getTransaction();
// closeConnection
if (error)
flag = XAResource.TMFAIL;
for (XAResource resource : xaResource) {
tx.delistResource(resource, flag);
}
if (error)
tm.rollback();
else
tm.commit();
}
use of javax.transaction.xa.XAResource in project aries by apache.
the class TransactionContextImpl method finish.
@Override
public void finish() {
if (!resources.isEmpty()) {
XAResource localResource = new LocalXAResourceImpl();
try {
currentTransaction.enlistResource(localResource);
} catch (Exception e) {
safeSetRollbackOnly();
recordFailure(e);
try {
localResource.rollback(null);
} catch (XAException e1) {
recordFailure(e1);
}
}
}
try {
TxListener listener = new TxListener();
try {
transactionManager.registerInterposedSynchronization(listener);
if (getRollbackOnly()) {
// GERONIMO-4449 says that we get no beforeCompletion
// callback for rollback :(
listener.beforeCompletion();
transactionManager.rollback();
} else {
transactionManager.commit();
}
} catch (Exception e) {
recordFailure(e);
}
} finally {
try {
transactionManager.resume(oldTran);
} catch (Exception e) {
recordFailure(e);
}
}
}
use of javax.transaction.xa.XAResource in project geode by apache.
the class JCAConnectionManagerImpl method allocateConnection.
/*
* allocates a ManagedConnection from the ConnectionPool or creates a new
* ManagedConnection. @param javax.resource.spi.ManagedConnectionFactory
*
* @param javax.resource.spi.ConnectionRequestInfo
*
* @throws ResourceException
*/
public Object allocateConnection(ManagedConnectionFactory mcf, ConnectionRequestInfo reqInfo) throws ResourceException {
if (!isActive) {
throw new ResourceException(LocalizedStrings.JCAConnectionManagerImpl_JCACONNECTIONMANAGERIMPLALLOCATECONNECTIONNO_VALID_CONNECTION_AVAILABLE.toLocalizedString());
}
ManagedConnection conn = null;
try {
conn = (ManagedConnection) mannPoolCache.getPooledConnectionFromPool();
} catch (PoolException ex) {
// ex.printStackTrace();
throw new ResourceException(LocalizedStrings.JCAConnectionManagerImpl_JCACONNECTIONMANAGERIMPL_ALLOCATECONNECTION_IN_GETTING_CONNECTION_FROM_POOL_DUE_TO_0.toLocalizedString(ex.getMessage()), ex);
}
// Transaction Manager.
try {
synchronized (this) {
if (transManager == null) {
transManager = JNDIInvoker.getTransactionManager();
}
}
Transaction txn = transManager.getTransaction();
if (txn != null) {
// Check if Data Source provides XATransaction
// if(configs.getTransactionType = "XATransaction")
XAResource xar = conn.getXAResource();
txn.enlistResource(xar);
// Asif :Add in the Map after successful registration of XAResource
xaResourcesMap.put(conn, xar);
// else throw a resource exception
}
} catch (RollbackException ex) {
throw new ResourceException(LocalizedStrings.JCAConnectionManagerImpl_JCACONNECTIONMANAGERIMPL_ALLOCATECONNECTION_IN_TRANSACTION_DUE_TO_0.toLocalizedString(ex.getMessage()), ex);
} catch (SystemException ex) {
throw new ResourceException(LocalizedStrings.JCAConnectionManagerImpl_JCACONNECTIONMANAGERIMPL_ALLOCATECONNECTION_SYSTEM_EXCEPTION_DUE_TO_0.toLocalizedString(ex.getMessage()), ex);
}
return conn.getConnection(subject, reqInfo);
}
use of javax.transaction.xa.XAResource in project jackrabbit by apache.
the class UserTransactionImpl method rollback.
/**
* @see javax.transaction.UserTransaction#rollback
*/
public void rollback() throws IllegalStateException, SecurityException, SystemException {
if (status != Status.STATUS_ACTIVE && status != Status.STATUS_MARKED_ROLLBACK) {
throw new IllegalStateException("Transaction not active");
}
try {
for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
XAResource resource = (XAResource) it.next();
XidImpl xid = (XidImpl) xaResources.get(resource);
resource.end(xid, XAResource.TMFAIL);
}
status = Status.STATUS_ROLLING_BACK;
for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
XAResource resource = (XAResource) it.next();
XidImpl xid = (XidImpl) xaResources.get(resource);
resource.rollback(xid);
}
status = Status.STATUS_ROLLEDBACK;
} catch (XAException e) {
SystemException se = new SystemException("Unable to rollback transaction: XA_ERR=" + e.errorCode);
se.initCause(e.getCause());
throw se;
}
}
Aggregations