use of io.seata.core.store.BranchTransactionDO in project seata by seata.
the class LogStoreDataBaseDAOTest method deleteBranchTransactionDO.
@Test
public void deleteBranchTransactionDO() throws SQLException {
BranchTransactionDO branchTransactionDO = new BranchTransactionDO();
branchTransactionDO.setResourceId("qqqq");
branchTransactionDO.setXid("abc-123:9999");
branchTransactionDO.setTransactionId(1285343);
branchTransactionDO.setBranchId(34567798);
branchTransactionDO.setBranchType("TCC");
branchTransactionDO.setResourceGroupId("abc");
branchTransactionDO.setResourceGroupId("a");
branchTransactionDO.setClientId("1.1.1.1");
branchTransactionDO.setStatus(1);
branchTransactionDO.setApplicationData("abc=123");
branchTransactionDO.setResourceGroupId("test");
boolean ret = logStoreDataBaseDAO.insertBranchTransactionDO(branchTransactionDO);
Assertions.assertTrue(ret);
String sql = "select * from branch_table where xid= 'abc-123:9999' and branch_id = 34567798";
String delSql = "delete from branch_table where xid= 'abc-123:9999' and branch_id = 34567798";
Connection conn = null;
try {
conn = dataSource.getConnection();
ResultSet rs = conn.createStatement().executeQuery(sql);
if (rs.next()) {
Assertions.assertTrue(true);
} else {
Assertions.assertTrue(false);
}
rs.close();
// delete
logStoreDataBaseDAO.deleteBranchTransactionDO(branchTransactionDO);
rs = conn.createStatement().executeQuery(sql);
if (rs.next()) {
Assertions.assertTrue(false);
} else {
Assertions.assertTrue(true);
}
rs.close();
} finally {
IOUtil.close(conn);
}
}
use of io.seata.core.store.BranchTransactionDO in project seata by seata.
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 seata by seata.
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;
}
use of io.seata.core.store.BranchTransactionDO in project seata by seata.
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 XHuiCloud by sindaZeng.
the class RedisTransactionStoreManager method readSessionByTransactionId.
/**
* read the global session by transactionId
* @param transactionId the transaction id
* @param withBranchSessions if read branch sessions
* @return the global session
*/
private GlobalSession readSessionByTransactionId(String transactionId, boolean withBranchSessions) {
String globalKey = buildGlobalKeyByTransactionId(transactionId);
String xid = null;
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);
if (globalTransactionDO != null) {
xid = globalTransactionDO.getXid();
}
List<BranchTransactionDO> branchTransactionDOs = new ArrayList<>();
if (withBranchSessions) {
branchTransactionDOs = this.readBranchSessionByXid(jedis, xid);
}
return getGlobalSession(globalTransactionDO, branchTransactionDOs);
}
}
Aggregations