}
}
private int prepareTransaction() throws Throwable {
final SubordinateTransaction subordinateTransaction = this.transactionsRepository.getImportedTransaction(this.xidTransactionID);
if (subordinateTransaction == null) {
if (EjbLogger.EJB3_INVOCATION_LOGGER.isDebugEnabled()) {
//this happens if no ejb invocations where made within the TX
EjbLogger.EJB3_INVOCATION_LOGGER.debug("Not preparing transaction " + this.xidTransactionID + " as is was not found on the server");
}
return XAResource.XA_OK;
}
// first associate the tx on this thread, by resuming the tx
this.resumeTransaction(subordinateTransaction);
try {
// now "prepare"
// Courtesy: com.arjuna.ats.internal.jta.transaction.arjunacore.jca.XATerminatorImple
int result = subordinateTransaction.doPrepare();
switch (result) {
case TwoPhaseOutcome.PREPARE_READONLY:
// TODO: Would it be fine to not remove the xid? (Need to understand how the subsequent
// flow works)
SubordinationManager.getTransactionImporter().removeImportedTransaction(this.xidTransactionID.getXid());
return XAResource.XA_RDONLY;
case TwoPhaseOutcome.PREPARE_OK:
return XAResource.XA_OK;
case TwoPhaseOutcome.PREPARE_NOTOK:
// the JCA API spec limits what we can do in terms of reporting
// problems.
// try to use the exception code and cause to provide info
// whilst
// remaining API compliant. JBTM-427.
Exception initCause = null;
int xaExceptionCode = XAException.XA_RBROLLBACK;
try {
subordinateTransaction.doRollback();
} catch (HeuristicCommitException e) {
initCause = e;
xaExceptionCode = XAException.XAER_RMERR;
} catch (HeuristicMixedException e) {
initCause = e;