private String action = "";
public boolean mediate(MessageContext synCtx) {
UserTransaction tx = null;
final SynapseLog synLog = getLog(synCtx);
if (synLog.isTraceOrDebugEnabled()) {
synLog.traceOrDebug("Start : Transaction mediator (" + action + ")");
if (synLog.isTraceTraceEnabled()) {
synLog.traceTrace("Message : " + synCtx.getEnvelope());
}
}
initContext(synCtx);
try {
tx = (UserTransaction) txContext.lookup(USER_TX_LOOKUP_STR);
} catch (NamingException e) {
handleException("Cloud not get the context name " + USER_TX_LOOKUP_STR, e, synCtx);
}
if (action.equals(ACTION_COMMIT)) {
try {
tx.commit();
} catch (Exception e) {
handleException("Unable to commit transaction", e, synCtx);
}
} else if (action.equals(ACTION_ROLLBACK)) {
try {
tx.rollback();
} catch (Exception e) {
handleException("Unable to rollback transaction", e, synCtx);
}
} else if (action.equals(ACTION_NEW)) {
int status = Status.STATUS_UNKNOWN;
try {
status = tx.getStatus();
} catch (Exception e) {
handleException("Unable to query transaction status", e, synCtx);
}
if (status != Status.STATUS_NO_TRANSACTION) {
throw new SynapseException("Require to begin a new transaction, " +
"but a transaction already exist");
}
try {
tx.begin();
} catch (Exception e) {
handleException("Unable to begin a new transaction", e, synCtx);
}
} else if (action.equals(ACTION_USE_EXISTING_OR_NEW)) {
int status = Status.STATUS_UNKNOWN;
try {
status = tx.getStatus();
} catch (Exception e) {
handleException("Unable to query transaction status", e, synCtx);
}
try {
if (status == Status.STATUS_NO_TRANSACTION) {
tx.begin();
}
} catch (Exception e) {
handleException("Unable to begin a new transaction", e, synCtx);
}
} else if (action.equals(ACTION_FAULT_IF_NO_TX)) {
int status = Status.STATUS_UNKNOWN;
try {
status = tx.getStatus();
} catch (Exception e) {
handleException("Unable to query transaction status", e, synCtx);
}
if (status != Status.STATUS_ACTIVE)