Search in sources :

Example 6 with BranchTransactionException

use of io.seata.core.exception.BranchTransactionException in project seata by seata.

the class AbstractCore method branchReport.

@Override
public void branchReport(BranchType branchType, String xid, long branchId, BranchStatus status, String applicationData) throws TransactionException {
    GlobalSession globalSession = assertGlobalSessionNotNull(xid, true);
    BranchSession branchSession = globalSession.getBranch(branchId);
    if (branchSession == null) {
        throw new BranchTransactionException(BranchTransactionNotExist, String.format("Could not found branch session xid = %s branchId = %s", xid, branchId));
    }
    globalSession.addSessionLifecycleListener(SessionHolder.getRootSessionManager());
    globalSession.changeBranchStatus(branchSession, status);
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("Report branch status successfully, xid = {}, branchId = {}", globalSession.getXid(), branchSession.getBranchId());
    }
}
Also used : GlobalSession(io.seata.server.session.GlobalSession) BranchSession(io.seata.server.session.BranchSession) BranchTransactionException(io.seata.core.exception.BranchTransactionException)

Example 7 with BranchTransactionException

use of io.seata.core.exception.BranchTransactionException in project XHuiCloud by sindaZeng.

the class AbstractCore method branchReport.

@Override
public void branchReport(BranchType branchType, String xid, long branchId, BranchStatus status, String applicationData) throws TransactionException {
    GlobalSession globalSession = assertGlobalSessionNotNull(xid, true);
    BranchSession branchSession = globalSession.getBranch(branchId);
    if (branchSession == null) {
        throw new BranchTransactionException(BranchTransactionNotExist, String.format("Could not found branch session xid = %s branchId = %s", xid, branchId));
    }
    globalSession.addSessionLifecycleListener(SessionHolder.getRootSessionManager());
    globalSession.changeBranchStatus(branchSession, status);
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("Report branch status successfully, xid = {}, branchId = {}", globalSession.getXid(), branchSession.getBranchId());
    }
}
Also used : GlobalSession(io.seata.server.session.GlobalSession) BranchSession(io.seata.server.session.BranchSession) BranchTransactionException(io.seata.core.exception.BranchTransactionException)

Example 8 with BranchTransactionException

use of io.seata.core.exception.BranchTransactionException in project XHuiCloud by sindaZeng.

the class AbstractCore method branchCommit.

@Override
public BranchStatus branchCommit(GlobalSession globalSession, BranchSession branchSession) throws TransactionException {
    try {
        BranchCommitRequest request = new BranchCommitRequest();
        request.setXid(branchSession.getXid());
        request.setBranchId(branchSession.getBranchId());
        request.setResourceId(branchSession.getResourceId());
        request.setApplicationData(branchSession.getApplicationData());
        request.setBranchType(branchSession.getBranchType());
        return branchCommitSend(request, globalSession, branchSession);
    } catch (IOException | TimeoutException e) {
        throw new BranchTransactionException(FailedToSendBranchCommitRequest, String.format("Send branch commit failed, xid = %s branchId = %s", branchSession.getXid(), branchSession.getBranchId()), e);
    }
}
Also used : IOException(java.io.IOException) BranchCommitRequest(io.seata.core.protocol.transaction.BranchCommitRequest) BranchTransactionException(io.seata.core.exception.BranchTransactionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 9 with BranchTransactionException

use of io.seata.core.exception.BranchTransactionException in project XHuiCloud by sindaZeng.

the class AbstractCore method branchRollback.

@Override
public BranchStatus branchRollback(GlobalSession globalSession, BranchSession branchSession) throws TransactionException {
    try {
        BranchRollbackRequest request = new BranchRollbackRequest();
        request.setXid(branchSession.getXid());
        request.setBranchId(branchSession.getBranchId());
        request.setResourceId(branchSession.getResourceId());
        request.setApplicationData(branchSession.getApplicationData());
        request.setBranchType(branchSession.getBranchType());
        return branchRollbackSend(request, globalSession, branchSession);
    } catch (IOException | TimeoutException e) {
        throw new BranchTransactionException(FailedToSendBranchRollbackRequest, String.format("Send branch rollback failed, xid = %s branchId = %s", branchSession.getXid(), branchSession.getBranchId()), e);
    }
}
Also used : BranchRollbackRequest(io.seata.core.protocol.transaction.BranchRollbackRequest) IOException(java.io.IOException) BranchTransactionException(io.seata.core.exception.BranchTransactionException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

BranchTransactionException (io.seata.core.exception.BranchTransactionException)9 BranchSession (io.seata.server.session.BranchSession)4 GlobalSession (io.seata.server.session.GlobalSession)4 IOException (java.io.IOException)4 TimeoutException (java.util.concurrent.TimeoutException)4 BranchCommitRequest (io.seata.core.protocol.transaction.BranchCommitRequest)2 BranchRollbackRequest (io.seata.core.protocol.transaction.BranchRollbackRequest)2 FailedToSendBranchCommitRequest (io.seata.core.exception.TransactionExceptionCode.FailedToSendBranchCommitRequest)1 FailedToSendBranchRollbackRequest (io.seata.core.exception.TransactionExceptionCode.FailedToSendBranchRollbackRequest)1 TableMeta (io.seata.rm.datasource.sql.struct.TableMeta)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 SQLIntegrityConstraintViolationException (java.sql.SQLIntegrityConstraintViolationException)1