TM相当于一个中间商,是没有涉及到任何数据库底层操作的。
io.seata.tm.api.TransactionalTemplate#beginTransaction
-->
io.seata.tm.api.DefaultGlobalTransaction#begin(int, java.lang.String)
-->
io.seata.tm.DefaultTransactionManager#begin
@Override
public String begin(String applicationId, String transactionServiceGroup, String name, int timeout)throws TransactionException {
GlobalBeginRequest request = new GlobalBeginRequest();
request.setTransactionName(name);
request.setTimeout(timeout);
GlobalBeginResponse response = (GlobalBeginResponse) syncCall(request);
if (response.getResultCode() == ResultCode.Failed) {
throw new TmTransactionException(TransactionExceptionCode.BeginFailed, response.getMsg());
}
return response.getXid();
}
io.seata.tm.api.TransactionalTemplate#commitTransaction
-->
io.seata.tm.DefaultTransactionManager#commit
@Override
public GlobalStatus commit(String xid) throws TransactionException {
GlobalCommitRequest globalCommit = new GlobalCommitRequest();
globalCommit.setXid(xid);
GlobalCommitResponse response = (GlobalCommitResponse) syncCall(globalCommit);
return response.getGlobalStatus();
}
io.seata.tm.api.TransactionalTemplate#rollbackTransaction
io.seata.tm.DefaultTransactionManager#rollback
@Override
public GlobalStatus rollback(String xid) throws TransactionException {
GlobalRollbackRequest globalRollback = new GlobalRollbackRequest();
globalRollback.setXid(xid);
GlobalRollbackResponse response = (GlobalRollbackResponse) syncCall(globalRollback);
return response.getGlobalStatus();
}