state = State.PREPARING;
ProfileParticipantDetailImpl detail = null;
for (Iterator<TransactionParticipant> iter = participants.iterator();
iter.hasNext(); )
{
TransactionParticipant participant = iter.next();
if (detailMap != null) {
detail = detailMap.get(participant.getTypeName());
startTime = System.currentTimeMillis();
}
try {
if (iter.hasNext() || disablePrepareAndCommitOpt) {
boolean readOnly = participant.prepare(this);
if (detail != null) {
detail.setPrepared(System.currentTimeMillis() -
startTime, readOnly);
}
if (readOnly) {
iter.remove();
if (detail != null) {
collectorHandle.addParticipant(detail);
}
}
if (logger.isLoggable(Level.FINEST)) {
logger.log(Level.FINEST,
"prepare {0} participant:{1} returns {2}",
this, getParticipantInfo(participant),
readOnly);
}
} else {
participant.prepareAndCommit(this);
if (detail != null) {
detail.
setCommittedDirectly(System.currentTimeMillis() -
startTime);
collectorHandle.addParticipant(detail);
}
iter.remove();
if (logger.isLoggable(Level.FINEST)) {
logger.log(
Level.FINEST,
"prepareAndCommit {0} participant:{1} returns",
this, getParticipantInfo(participant));
}
}
} catch (Exception e) {
if (logger.isLoggable(Level.FINEST)) {
logger.logThrow(
Level.FINEST, e, "{0} {1} participant:{1} throws",
iter.hasNext() ? "prepare" : "prepareAndCommit",
this, getParticipantInfo(participant));
}
if (state != State.ABORTED) {
abort(e);
}
throw e;
}
if (state == State.ABORTED) {
throw new TransactionAbortedException(
"Transaction has been aborted: " + abortCause, abortCause);
}
}
state = State.COMMITTING;
for (TransactionParticipant participant : participants) {
if (logger.isLoggable(Level.FINEST)) {
logger.log(Level.FINEST, "commit {0} participant:{1}",
this, getParticipantInfo(participant));
}
if (detailMap != null) {
detail = detailMap.get(participant.getTypeName());
startTime = System.currentTimeMillis();
}
try {
participant.commit(this);
if (detail != null) {
detail.setCommitted(System.currentTimeMillis() -
startTime);
collectorHandle.addParticipant(detail);
}