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);
}
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);
}
}
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;
}
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);
}
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());
}
Aggregations