switch (status) {
case STATUS_ACTIVE:// This is the normal case - do nothing
break;
case STATUS_MARKED_ROLLBACK: {
// Tx was marked for rollback by the user, error
error = new ExceptionFactory().txMarkedForRollbackException();
break;
}
default:// Tx in some other state, error
throw new ExceptionFactory().invalidStateException(status);
}
// Call beforeCompletion callback.
if (error == null) {
try {
debug("TxImpl - invoking beforeCompletion");
int i;
int j;
for (i = 0, j = listeners.size(); i < j; i++) {
((Synchronization)listeners.elementAt(i)).beforeCompletion();
}
} catch (Exception ex) {
error = ex;
status = STATUS_ROLLING_BACK;
debug("TxImpl - error in beforeCompletion: " + ex);
}
}
// Now if we didn't get any errors then commit the connection
if ((error == null) && (status == STATUS_ACTIVE)) {
try {
commitConnection();
} catch (Exception ex) {
error = ex;
}
} else {
try {
rollbackConnection();
} catch (Exception ex) {
error = ex;
}
}
// Whether we were successful or not, call afterCompletion and clean up
invokeAfterCompletion();
cleanup();
// Throw any error that may have occurred at any point in the commit
if (error != null) {
throw new ExceptionFactory().newSystemException(error);
}
}