use of io.seata.core.store.BranchTransactionDO in project seata by seata.
the class LogStoreDataBaseDAOTest method updateBranchTransactionDO.
@Test
public void updateBranchTransactionDO() throws SQLException {
BranchTransactionDO branchTransactionDO = new BranchTransactionDO();
branchTransactionDO.setResourceId("qqqq");
branchTransactionDO.setXid("abc-123:8888");
branchTransactionDO.setTransactionId(1285343);
branchTransactionDO.setBranchId(343434318);
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);
branchTransactionDO.setStatus(3);
Assertions.assertTrue(logStoreDataBaseDAO.updateBranchTransactionDO(branchTransactionDO));
String sql = "select * from branch_table where xid= 'abc-123:8888' and branch_id = 343434318";
String delSql = "delete from branch_table where xid= 'abc-123:8888' and branch_id = 343434318";
Connection conn = null;
try {
conn = dataSource.getConnection();
ResultSet rs = conn.createStatement().executeQuery(sql);
if (rs.next()) {
Assertions.assertTrue(true);
Assertions.assertEquals(3, rs.getInt("status"));
} else {
Assertions.assertTrue(false);
}
conn.createStatement().execute(delSql);
} finally {
IOUtil.close(conn);
}
}
use of io.seata.core.store.BranchTransactionDO in project seata by seata.
the class LogStoreDataBaseDAOTest method queryBranchTransactionDO.
@Test
public void queryBranchTransactionDO() throws SQLException {
{
// creata data for test
BranchTransactionDO branchTransactionDO = new BranchTransactionDO();
branchTransactionDO.setResourceId("qqqq");
branchTransactionDO.setXid("abc-123:6789");
branchTransactionDO.setTransactionId(24234235);
branchTransactionDO.setBranchId(345465676);
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);
}
{
// creata data for test
BranchTransactionDO branchTransactionDO = new BranchTransactionDO();
branchTransactionDO.setResourceId("qqqq");
branchTransactionDO.setXid("abc-123:6789");
branchTransactionDO.setTransactionId(24234235);
branchTransactionDO.setBranchId(78563453);
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);
}
List<BranchTransactionDO> rets = logStoreDataBaseDAO.queryBranchTransactionDO("abc-123:6789");
Assertions.assertTrue(CollectionUtils.isNotEmpty(rets));
Assertions.assertEquals(2, rets.size());
if (78563453 == rets.get(0).getBranchId() && 345465676 == rets.get(1).getBranchId()) {
Assertions.assertTrue(true);
} else if (78563453 == rets.get(1).getBranchId() && 345465676 == rets.get(0).getBranchId()) {
Assertions.assertTrue(true);
} else {
Assertions.assertTrue(false);
}
String delSql = "delete from branch_table where xid= 'abc-123:6789' ";
Connection conn = null;
try {
conn = dataSource.getConnection();
conn.createStatement().execute(delSql);
} finally {
IOUtil.close(conn);
}
}
use of io.seata.core.store.BranchTransactionDO in project seata by seata.
the class LogStoreDataBaseDAOTest method insertBranchTransactionDO.
@Test
public void insertBranchTransactionDO() throws SQLException {
BranchTransactionDO branchTransactionDO = new BranchTransactionDO();
branchTransactionDO.setResourceId("qqqq");
branchTransactionDO.setXid("abc-123:7777");
branchTransactionDO.setTransactionId(1285343);
branchTransactionDO.setBranchId(1234508);
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:7777' and branch_id = 1234508";
String delSql = "delete from branch_table where xid= 'abc-123:7777' and branch_id = 1234508";
Connection conn = null;
try {
conn = dataSource.getConnection();
ResultSet rs = conn.createStatement().executeQuery(sql);
if (rs.next()) {
Assertions.assertTrue(true);
} else {
Assertions.assertTrue(false);
}
conn.createStatement().execute(delSql);
} finally {
IOUtil.close(conn);
}
}
use of io.seata.core.store.BranchTransactionDO in project seata by seata.
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);
}
}
use of io.seata.core.store.BranchTransactionDO in project seata by seata.
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);
}
}
Aggregations