Search in sources :

Example 11 with GlobalTransactionDO

use of io.seata.core.store.GlobalTransactionDO in project seata by seata.

the class DataBaseTransactionStoreManager method readSession.

/**
 * Read session global session.
 *
 * @param xid the xid
 * @param withBranchSessions the withBranchSessions
 * @return the global session
 */
@Override
public GlobalSession readSession(String xid, boolean withBranchSessions) {
    // global transaction
    GlobalTransactionDO globalTransactionDO = logStore.queryGlobalTransactionDO(xid);
    if (globalTransactionDO == null) {
        return null;
    }
    // branch transactions
    List<BranchTransactionDO> branchTransactionDOs = null;
    // reduce rpc with db when branchRegister and getGlobalStatus
    if (withBranchSessions) {
        branchTransactionDOs = logStore.queryBranchTransactionDO(globalTransactionDO.getXid());
    }
    return getGlobalSession(globalTransactionDO, branchTransactionDOs);
}
Also used : GlobalTransactionDO(io.seata.core.store.GlobalTransactionDO) BranchTransactionDO(io.seata.core.store.BranchTransactionDO)

Example 12 with GlobalTransactionDO

use of io.seata.core.store.GlobalTransactionDO in project seata by seata.

the class DataBaseTransactionStoreManager method readSession.

/**
 * Read session global session.
 *
 * @param transactionId the transaction id
 * @return the global session
 */
public GlobalSession readSession(Long transactionId) {
    // global transaction
    GlobalTransactionDO globalTransactionDO = logStore.queryGlobalTransactionDO(transactionId);
    if (globalTransactionDO == null) {
        return null;
    }
    // branch transactions
    List<BranchTransactionDO> branchTransactionDOs = logStore.queryBranchTransactionDO(globalTransactionDO.getXid());
    return getGlobalSession(globalTransactionDO, branchTransactionDOs);
}
Also used : GlobalTransactionDO(io.seata.core.store.GlobalTransactionDO) BranchTransactionDO(io.seata.core.store.BranchTransactionDO)

Example 13 with GlobalTransactionDO

use of io.seata.core.store.GlobalTransactionDO in project XHuiCloud by sindaZeng.

the class DataBaseTransactionStoreManager method readSession.

/**
 * Read session global session.
 *
 * @param xid the xid
 * @param withBranchSessions the withBranchSessions
 * @return the global session
 */
@Override
public GlobalSession readSession(String xid, boolean withBranchSessions) {
    // global transaction
    GlobalTransactionDO globalTransactionDO = logStore.queryGlobalTransactionDO(xid);
    if (globalTransactionDO == null) {
        return null;
    }
    // branch transactions
    List<BranchTransactionDO> branchTransactionDOs = null;
    // reduce rpc with db when branchRegister and getGlobalStatus
    if (withBranchSessions) {
        branchTransactionDOs = logStore.queryBranchTransactionDO(globalTransactionDO.getXid());
    }
    return getGlobalSession(globalTransactionDO, branchTransactionDOs);
}
Also used : GlobalTransactionDO(io.seata.core.store.GlobalTransactionDO) BranchTransactionDO(io.seata.core.store.BranchTransactionDO)

Example 14 with GlobalTransactionDO

use of io.seata.core.store.GlobalTransactionDO in project XHuiCloud by sindaZeng.

the class SessionConverter method convertGlobalTransactionDO.

public static GlobalTransactionDO convertGlobalTransactionDO(SessionStorable session) {
    if (session == null || !(session instanceof GlobalSession)) {
        throw new IllegalArgumentException("The parameter of SessionStorable is not available, SessionStorable:" + StringUtils.toString(session));
    }
    GlobalSession globalSession = (GlobalSession) session;
    GlobalTransactionDO globalTransactionDO = new GlobalTransactionDO();
    globalTransactionDO.setXid(globalSession.getXid());
    globalTransactionDO.setStatus(globalSession.getStatus().getCode());
    globalTransactionDO.setApplicationId(globalSession.getApplicationId());
    globalTransactionDO.setBeginTime(globalSession.getBeginTime());
    globalTransactionDO.setTimeout(globalSession.getTimeout());
    globalTransactionDO.setTransactionId(globalSession.getTransactionId());
    globalTransactionDO.setTransactionName(globalSession.getTransactionName());
    globalTransactionDO.setTransactionServiceGroup(globalSession.getTransactionServiceGroup());
    globalTransactionDO.setApplicationData(globalSession.getApplicationData());
    return globalTransactionDO;
}
Also used : GlobalTransactionDO(io.seata.core.store.GlobalTransactionDO) GlobalSession(io.seata.server.session.GlobalSession)

Example 15 with GlobalTransactionDO

use of io.seata.core.store.GlobalTransactionDO in project seata by seata.

the class SessionConverterTest method testConvertGlobalTransactionDONotNull.

@Test
public void testConvertGlobalTransactionDONotNull() {
    Date date = new Date();
    long now = date.getTime();
    GlobalSession globalSession = new GlobalSession("application1", "fsp_tx", "createOrder", 60);
    globalSession.setXid("192.168.158.80:8091:39372760251957248");
    globalSession.setTransactionId(39372760251957248L);
    globalSession.setStatus(GlobalStatus.Begin);
    globalSession.setBeginTime(now);
    globalSession.setApplicationData("id=1,product=2");
    GlobalTransactionDO globalTransactionDO = SessionConverter.convertGlobalTransactionDO(globalSession);
    Assertions.assertEquals(globalSession.getXid(), globalTransactionDO.getXid());
    Assertions.assertEquals(globalSession.getTransactionId(), globalTransactionDO.getTransactionId());
    Assertions.assertEquals(globalSession.getStatus().getCode(), globalTransactionDO.getStatus());
    Assertions.assertEquals(globalSession.getTransactionName(), globalTransactionDO.getTransactionName());
    Assertions.assertEquals(globalSession.getApplicationId(), globalTransactionDO.getApplicationId());
    Assertions.assertEquals(globalSession.getTransactionServiceGroup(), globalTransactionDO.getTransactionServiceGroup());
    Assertions.assertEquals(globalSession.getTransactionName(), globalTransactionDO.getTransactionName());
    Assertions.assertEquals(globalSession.getTimeout(), globalTransactionDO.getTimeout());
    Assertions.assertEquals(globalSession.getBeginTime(), globalTransactionDO.getBeginTime());
    Assertions.assertEquals(globalSession.getApplicationData(), globalTransactionDO.getApplicationData());
}
Also used : GlobalTransactionDO(io.seata.core.store.GlobalTransactionDO) GlobalSession(io.seata.server.session.GlobalSession) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Aggregations

GlobalTransactionDO (io.seata.core.store.GlobalTransactionDO)24 Test (org.junit.jupiter.api.Test)10 BranchTransactionDO (io.seata.core.store.BranchTransactionDO)8 Connection (java.sql.Connection)8 GlobalSession (io.seata.server.session.GlobalSession)5 ResultSet (java.sql.ResultSet)4 Jedis (redis.clients.jedis.Jedis)4 ArrayList (java.util.ArrayList)3 DataAccessException (io.seata.common.exception.DataAccessException)2 Date (java.util.Date)2 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1