}
if (_resourceCount > 0) {
_status = Status.STATUS_PREPARING;
AbstractXALogStream xaLog = _transactionManager.getXALogStream();
boolean hasPrepare = false;
boolean allowSinglePhase = false;
for (int i = _resourceCount - 1; i >= 0; i--) {
XAResource resource = (XAResource) _resources[i];
if (i == 0 && (xaLog == null || !hasPrepare)) {
// server/1601
_resourceStates[0] |= RES_COMMIT;
allowSinglePhase = true;
break;
}
if ((_resourceStates[i] & RES_SHARED_RM) == 0) {
try {
int prepare = resource.prepare(_resourceXids[i]);
if (prepare == XAResource.XA_RDONLY) {
} else if (prepare == XAResource.XA_OK) {
hasPrepare = true;
_resourceStates[i] |= RES_COMMIT;
} else {
log.finer(this + " unexpected prepare result " + prepare);
rollbackInt();
}
} catch (XAException e) {
_transactionManager.addCommitResourceFail();
heuristicExn = heuristicException(heuristicExn, e);
rollbackInt();
throw new RollbackExceptionWrapper(L.l("all commits rolled back"),
heuristicExn);
}
}
}
if (hasPrepare && xaLog != null) {
_xaLog = xaLog;
xaLog.writeTMCommit(_xid);
}
_status = Status.STATUS_COMMITTING;
Exception exn = commitResources(allowSinglePhase);