use of io.seata.core.store.BranchTransactionDO in project XHuiCloud by sindaZeng.
the class RedisTransactionStoreManager 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) {
String transactionId = String.valueOf(XID.getTransactionId(xid));
String globalKey = buildGlobalKeyByTransactionId(transactionId);
try (Jedis jedis = JedisPooledFactory.getJedisInstance()) {
Map<String, String> map = jedis.hgetAll(globalKey);
if (CollectionUtils.isEmpty(map)) {
return null;
}
GlobalTransactionDO globalTransactionDO = (GlobalTransactionDO) BeanUtils.mapToObject(map, GlobalTransactionDO.class);
List<BranchTransactionDO> branchTransactionDOs = null;
if (withBranchSessions) {
branchTransactionDOs = this.readBranchSessionByXid(jedis, xid);
}
return getGlobalSession(globalTransactionDO, branchTransactionDOs);
}
}
use of io.seata.core.store.BranchTransactionDO in project XHuiCloud by sindaZeng.
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;
BranchTransactionDO branchTransactionDO = (BranchTransactionDO) BeanUtils.mapToObject(branchInfoMap, BranchTransactionDO.class);
branchTransactionDOs.add(branchTransactionDO);
}
}
}
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 XHuiCloud by sindaZeng.
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);
}
use of io.seata.core.store.BranchTransactionDO in project XHuiCloud by sindaZeng.
the class LogStoreDataBaseDAO method queryBranchTransactionDO.
@Override
public List<BranchTransactionDO> queryBranchTransactionDO(List<String> xids) {
int length = xids.size();
List<BranchTransactionDO> rets = new ArrayList<>(length * 3);
String paramsPlaceHolder = org.apache.commons.lang.StringUtils.repeat("?", ",", length);
String sql = LogStoreSqlsFactory.getLogStoreSqls(dbType).getQueryBranchTransaction(branchTable, paramsPlaceHolder);
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = logStoreDataSource.getConnection();
conn.setAutoCommit(true);
ps = conn.prepareStatement(sql);
for (int i = 0; i < length; i++) {
ps.setString(i + 1, xids.get(i));
}
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 LogStoreDataBaseDAO method convertBranchTransactionDO.
private BranchTransactionDO convertBranchTransactionDO(ResultSet rs) throws SQLException {
BranchTransactionDO branchTransactionDO = new BranchTransactionDO();
branchTransactionDO.setResourceGroupId(rs.getString(ServerTableColumnsName.BRANCH_TABLE_RESOURCE_GROUP_ID));
branchTransactionDO.setStatus(rs.getInt(ServerTableColumnsName.BRANCH_TABLE_STATUS));
branchTransactionDO.setApplicationData(rs.getString(ServerTableColumnsName.BRANCH_TABLE_APPLICATION_DATA));
branchTransactionDO.setClientId(rs.getString(ServerTableColumnsName.BRANCH_TABLE_CLIENT_ID));
branchTransactionDO.setXid(rs.getString(ServerTableColumnsName.BRANCH_TABLE_XID));
branchTransactionDO.setResourceId(rs.getString(ServerTableColumnsName.BRANCH_TABLE_RESOURCE_ID));
branchTransactionDO.setBranchId(rs.getLong(ServerTableColumnsName.BRANCH_TABLE_BRANCH_ID));
branchTransactionDO.setBranchType(rs.getString(ServerTableColumnsName.BRANCH_TABLE_BRANCH_TYPE));
branchTransactionDO.setTransactionId(rs.getLong(ServerTableColumnsName.BRANCH_TABLE_TRANSACTION_ID));
branchTransactionDO.setGmtCreate(rs.getTimestamp(ServerTableColumnsName.BRANCH_TABLE_GMT_CREATE));
branchTransactionDO.setGmtModified(rs.getTimestamp(ServerTableColumnsName.BRANCH_TABLE_GMT_MODIFIED));
return branchTransactionDO;
}
Aggregations