Search in sources :

Example 11 with BranchTransactionDO

use of io.seata.core.store.BranchTransactionDO 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 12 with BranchTransactionDO

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

the class LogStoreDataBaseDAO method queryBranchTransactionDO.

@Override
public List<BranchTransactionDO> queryBranchTransactionDO(String xid) {
    List<BranchTransactionDO> rets = new ArrayList<>();
    String sql = LogStoreSqlsFactory.getLogStoreSqls(dbType).getQueryBranchTransaction(branchTable);
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        conn = logStoreDataSource.getConnection();
        conn.setAutoCommit(true);
        ps = conn.prepareStatement(sql);
        ps.setString(1, xid);
        rs = ps.executeQuery();
        while (rs.next()) {
            rets.add(convertBranchTransactionDO(rs));
        }
        return rets;
    } catch (SQLException e) {
        throw new DataAccessException(e);
    } finally {
        IOUtil.close(rs, ps, conn);
    }
}
Also used : ArrayList(java.util.ArrayList) BranchTransactionDO(io.seata.core.store.BranchTransactionDO) DataAccessException(io.seata.common.exception.DataAccessException)

Example 13 with BranchTransactionDO

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

the class SessionConverter method convertBranchTransactionDO.

public static BranchTransactionDO convertBranchTransactionDO(SessionStorable session) {
    if (session == null || !(session instanceof BranchSession)) {
        throw new IllegalArgumentException("The parameter of SessionStorable is not available, SessionStorable:" + StringUtils.toString(session));
    }
    BranchSession branchSession = (BranchSession) session;
    BranchTransactionDO branchTransactionDO = new BranchTransactionDO();
    branchTransactionDO.setXid(branchSession.getXid());
    branchTransactionDO.setBranchId(branchSession.getBranchId());
    branchTransactionDO.setBranchType(branchSession.getBranchType().name());
    branchTransactionDO.setClientId(branchSession.getClientId());
    branchTransactionDO.setResourceGroupId(branchSession.getResourceGroupId());
    branchTransactionDO.setTransactionId(branchSession.getTransactionId());
    branchTransactionDO.setApplicationData(branchSession.getApplicationData());
    branchTransactionDO.setResourceId(branchSession.getResourceId());
    branchTransactionDO.setStatus(branchSession.getStatus().getCode());
    return branchTransactionDO;
}
Also used : BranchSession(io.seata.server.session.BranchSession) BranchTransactionDO(io.seata.core.store.BranchTransactionDO)

Example 14 with BranchTransactionDO

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

the class SessionConverterTest method testConvertBranchSessionNull.

@Test
public void testConvertBranchSessionNull() {
    BranchTransactionDO branchTransactionDO = null;
    BranchSession branchSession = SessionConverter.convertBranchSession(branchTransactionDO);
    Assertions.assertNull(branchSession);
}
Also used : BranchSession(io.seata.server.session.BranchSession) BranchTransactionDO(io.seata.core.store.BranchTransactionDO) Test(org.junit.jupiter.api.Test)

Example 15 with BranchTransactionDO

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

the class SessionConverterTest method testConvertBranchSessionNotNull.

@Test
public void testConvertBranchSessionNotNull() {
    BranchTransactionDO branchTransactionDO = new BranchTransactionDO();
    Date date = new Date();
    branchTransactionDO.setXid("192.168.158.80:8091:39372760251957248");
    branchTransactionDO.setTransactionId(39372760251957248L);
    branchTransactionDO.setBranchId(39372760251957111L);
    branchTransactionDO.setResourceGroupId("t1");
    branchTransactionDO.setResourceId("jdbc:mysql://116.62.62.62/seata-storage");
    branchTransactionDO.setBranchType(BranchType.AT.name());
    branchTransactionDO.setStatus(1);
    branchTransactionDO.setClientId("storage-server:192.168.158.80:11934");
    branchTransactionDO.setApplicationData("");
    branchTransactionDO.setGmtCreate(date);
    branchTransactionDO.setGmtModified(date);
    BranchSession branchSession = SessionConverter.convertBranchSession(branchTransactionDO);
    Assertions.assertEquals(branchTransactionDO.getXid(), branchSession.getXid());
    Assertions.assertEquals(branchTransactionDO.getTransactionId(), branchSession.getTransactionId());
    Assertions.assertEquals(branchTransactionDO.getBranchId(), branchSession.getBranchId());
    Assertions.assertEquals(branchTransactionDO.getResourceGroupId(), branchSession.getResourceGroupId());
    Assertions.assertEquals(branchTransactionDO.getResourceId(), branchSession.getResourceId());
    Assertions.assertEquals(branchTransactionDO.getBranchType(), branchSession.getBranchType().name());
    Assertions.assertEquals(branchTransactionDO.getStatus(), branchSession.getStatus().getCode());
    Assertions.assertEquals(branchTransactionDO.getClientId(), branchSession.getClientId());
    Assertions.assertEquals(branchTransactionDO.getApplicationData(), branchSession.getApplicationData());
}
Also used : BranchSession(io.seata.server.session.BranchSession) BranchTransactionDO(io.seata.core.store.BranchTransactionDO) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Aggregations

BranchTransactionDO (io.seata.core.store.BranchTransactionDO)25 GlobalTransactionDO (io.seata.core.store.GlobalTransactionDO)8 Test (org.junit.jupiter.api.Test)7 Connection (java.sql.Connection)6 ArrayList (java.util.ArrayList)6 BranchSession (io.seata.server.session.BranchSession)5 ResultSet (java.sql.ResultSet)5 DataAccessException (io.seata.common.exception.DataAccessException)4 Jedis (redis.clients.jedis.Jedis)4 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2 Pipeline (redis.clients.jedis.Pipeline)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1