use of io.seata.core.store.BranchTransactionDO in project seata by seata.
the class RedisTransactionStoreManager method readBranchSessionByXid.
/**
* Read the branch session list by xid
* @param jedis
* @param xid the xid
* @return the branch transactionDo list
*/
private List<BranchTransactionDO> readBranchSessionByXid(Jedis jedis, String xid) {
List<BranchTransactionDO> branchTransactionDOs = new ArrayList<>();
String branchListKey = buildBranchListKeyByXid(xid);
List<String> branchKeys = jedis.lrange(branchListKey, 0, -1);
Pipeline pipeline = jedis.pipelined();
if (CollectionUtils.isNotEmpty(branchKeys)) {
branchKeys.stream().forEachOrdered(branchKey -> pipeline.hgetAll(branchKey));
List<Object> branchInfos = pipeline.syncAndReturnAll();
for (Object branchInfo : branchInfos) {
if (branchInfo != null) {
Map<String, String> branchInfoMap = (Map<String, String>) branchInfo;
Optional<BranchTransactionDO> branchTransactionDO = Optional.ofNullable((BranchTransactionDO) BeanUtils.mapToObject(branchInfoMap, BranchTransactionDO.class));
branchTransactionDO.ifPresent(branchTransactionDOs::add);
}
}
}
if (CollectionUtils.isNotEmpty(branchTransactionDOs)) {
branchTransactionDOs = branchTransactionDOs.stream().sorted(Comparator.comparing(BranchTransactionDO::getGmtCreate)).collect(Collectors.toList());
}
return branchTransactionDOs;
}
use of io.seata.core.store.BranchTransactionDO in project seata by seata.
the class SessionConverterTest method testConvertBranchTransactionDONotNull.
@Test
public void testConvertBranchTransactionDONotNull() {
BranchSession branchSession = new BranchSession();
branchSession.setXid("192.168.158.80:8091:39372760251957248");
branchSession.setResourceId("jdbc:mysql://116.62.62.62/seata-storage");
branchSession.setTransactionId(39372760251957248L);
branchSession.setBranchId(39372760251957111L);
branchSession.setBranchType(BranchType.XA);
branchSession.setResourceGroupId("abc");
branchSession.setClientId("storage-server:192.168.158.80:11934");
branchSession.setStatus(BranchStatus.PhaseOne_Failed);
branchSession.setApplicationData("abc=123");
BranchTransactionDO branchTransactionDO = SessionConverter.convertBranchTransactionDO(branchSession);
Assertions.assertEquals(branchSession.getXid(), branchTransactionDO.getXid());
Assertions.assertEquals(branchSession.getResourceId(), branchTransactionDO.getResourceId());
Assertions.assertEquals(branchSession.getTransactionId(), branchTransactionDO.getTransactionId());
Assertions.assertEquals(branchSession.getBranchId(), branchTransactionDO.getBranchId());
Assertions.assertEquals(branchSession.getBranchType().name(), branchTransactionDO.getBranchType());
Assertions.assertEquals(branchSession.getResourceGroupId(), branchTransactionDO.getResourceGroupId());
Assertions.assertEquals(branchSession.getClientId(), branchTransactionDO.getClientId());
Assertions.assertEquals(branchSession.getStatus().getCode(), branchTransactionDO.getStatus());
Assertions.assertEquals(branchSession.getApplicationData(), branchTransactionDO.getApplicationData());
}
use of io.seata.core.store.BranchTransactionDO in project seata by seata.
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 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);
}
use of io.seata.core.store.BranchTransactionDO 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);
}
Aggregations