use of io.seata.core.store.GlobalTransactionDO in project seata by seata.
the class LogStoreDataBaseDAOTest method updateGlobalTransactionDO.
@Test
public void updateGlobalTransactionDO() throws SQLException {
GlobalTransactionDO globalTransactionDO = new GlobalTransactionDO();
globalTransactionDO.setXid("abc-123:222");
globalTransactionDO.setApplicationData("abc=5454");
globalTransactionDO.setTransactionServiceGroup("abc");
globalTransactionDO.setTransactionName("test");
globalTransactionDO.setTransactionId(12345);
globalTransactionDO.setTimeout(20);
globalTransactionDO.setBeginTime(System.currentTimeMillis());
globalTransactionDO.setApplicationId("test");
globalTransactionDO.setStatus(1);
boolean ret = logStoreDataBaseDAO.insertGlobalTransactionDO(globalTransactionDO);
Assertions.assertTrue(ret);
String sql = "select * from global_table where xid= 'abc-123:222'";
String delSql = "delete from global_table where xid= 'abc-123:222'";
Connection conn = null;
try {
conn = dataSource.getConnection();
ResultSet rs = conn.createStatement().executeQuery(sql);
if (rs.next()) {
Assertions.assertTrue(true);
Assertions.assertEquals(1, rs.getInt("status"));
} else {
Assertions.assertTrue(false);
}
rs.close();
// update
globalTransactionDO.setStatus(2);
Assertions.assertTrue(logStoreDataBaseDAO.updateGlobalTransactionDO(globalTransactionDO));
rs = conn.createStatement().executeQuery(sql);
if (rs.next()) {
Assertions.assertTrue(true);
Assertions.assertEquals(2, rs.getInt("status"));
} else {
Assertions.assertTrue(false);
}
rs.close();
// delete
conn.createStatement().execute(delSql);
} finally {
IOUtil.close(conn);
}
}
use of io.seata.core.store.GlobalTransactionDO in project seata by seata.
the class LogStoreDataBaseDAOTest method queryGlobalTransactionDO_by_statuses_limit.
@Test
public void queryGlobalTransactionDO_by_statuses_limit() throws SQLException {
{
GlobalTransactionDO globalTransactionDO = new GlobalTransactionDO();
globalTransactionDO.setXid("abc-123:1267");
globalTransactionDO.setApplicationData("abc=234356");
globalTransactionDO.setTransactionServiceGroup("abc");
globalTransactionDO.setTransactionName("test");
globalTransactionDO.setTransactionId(867978970);
globalTransactionDO.setTimeout(20);
globalTransactionDO.setBeginTime(System.currentTimeMillis());
globalTransactionDO.setApplicationId("test");
globalTransactionDO.setStatus(1);
Assertions.assertTrue(logStoreDataBaseDAO.insertGlobalTransactionDO(globalTransactionDO));
}
{
GlobalTransactionDO globalTransactionDO = new GlobalTransactionDO();
globalTransactionDO.setXid("abc-123:6978");
globalTransactionDO.setApplicationData("abc=87867978");
globalTransactionDO.setTransactionServiceGroup("abc");
globalTransactionDO.setTransactionName("test");
globalTransactionDO.setTransactionId(143546567);
globalTransactionDO.setTimeout(20);
globalTransactionDO.setBeginTime(System.currentTimeMillis());
globalTransactionDO.setApplicationId("test");
globalTransactionDO.setStatus(2);
boolean ret = logStoreDataBaseDAO.insertGlobalTransactionDO(globalTransactionDO);
Assertions.assertTrue(ret);
}
{
GlobalTransactionDO globalTransactionDO = new GlobalTransactionDO();
globalTransactionDO.setXid("abc-123:5657");
globalTransactionDO.setApplicationData("abc=5454");
globalTransactionDO.setTransactionServiceGroup("abc");
globalTransactionDO.setTransactionName("test");
globalTransactionDO.setTransactionId(12345);
globalTransactionDO.setTimeout(20);
globalTransactionDO.setBeginTime(System.currentTimeMillis());
globalTransactionDO.setApplicationId("test");
globalTransactionDO.setStatus(1);
boolean ret = logStoreDataBaseDAO.insertGlobalTransactionDO(globalTransactionDO);
Assertions.assertTrue(ret);
}
List<GlobalTransactionDO> globalTransactionDOs = logStoreDataBaseDAO.queryGlobalTransactionDO(new int[] { 1 }, 1);
Assertions.assertNotNull(globalTransactionDOs);
Assertions.assertEquals(1, globalTransactionDOs.size());
if ("abc-123:1267".equals(globalTransactionDOs.get(0).getXid())) {
Assertions.assertTrue(true);
} else {
Assertions.assertTrue(false);
}
String delSql = "delete from global_table where xid in ('abc-123:1267', 'abc-123:6978', 'abc-123:5657')";
Connection conn = null;
try {
conn = dataSource.getConnection();
conn.createStatement().execute(delSql);
} finally {
IOUtil.close(conn);
}
}
use of io.seata.core.store.GlobalTransactionDO in project seata by seata.
the class LogStoreDataBaseDAOTest method queryGlobalTransactionDO_by_xid.
@Test
public void queryGlobalTransactionDO_by_xid() throws SQLException {
GlobalTransactionDO globalTransactionDO = new GlobalTransactionDO();
globalTransactionDO.setXid("abc-123:978786");
globalTransactionDO.setApplicationData("abc=87867978");
globalTransactionDO.setTransactionServiceGroup("abc");
globalTransactionDO.setTransactionName("test");
globalTransactionDO.setTransactionId(143546567);
globalTransactionDO.setTimeout(20);
globalTransactionDO.setBeginTime(System.currentTimeMillis());
globalTransactionDO.setApplicationId("test");
globalTransactionDO.setStatus(1);
boolean ret = logStoreDataBaseDAO.insertGlobalTransactionDO(globalTransactionDO);
Assertions.assertTrue(ret);
GlobalTransactionDO globalTransactionDO_db = logStoreDataBaseDAO.queryGlobalTransactionDO("abc-123:978786");
Assertions.assertNotNull(globalTransactionDO_db);
Assertions.assertEquals(globalTransactionDO_db.getBeginTime(), globalTransactionDO_db.getBeginTime());
Assertions.assertEquals(globalTransactionDO_db.getTransactionName(), globalTransactionDO_db.getTransactionName());
Assertions.assertEquals(globalTransactionDO_db.getTransactionId(), globalTransactionDO_db.getTransactionId());
Assertions.assertEquals(globalTransactionDO_db.getStatus(), globalTransactionDO_db.getStatus());
Assertions.assertEquals(globalTransactionDO_db.getTimeout(), globalTransactionDO_db.getTimeout());
Assertions.assertEquals(globalTransactionDO_db.getTransactionServiceGroup(), globalTransactionDO_db.getTransactionServiceGroup());
Assertions.assertEquals(globalTransactionDO_db.getApplicationId(), globalTransactionDO_db.getApplicationId());
Assertions.assertNotNull(globalTransactionDO_db.getGmtCreate());
Assertions.assertNotNull(globalTransactionDO_db.getGmtModified());
String delSql = "delete from global_table where xid= 'abc-123:978786'";
Connection conn = null;
try {
conn = dataSource.getConnection();
// delete
conn.createStatement().execute(delSql);
} finally {
IOUtil.close(conn);
}
}
use of io.seata.core.store.GlobalTransactionDO in project seata by seata.
the class LogStoreDataBaseDAOTest method insertGlobalTransactionDO.
@Test
public void insertGlobalTransactionDO() throws SQLException {
GlobalTransactionDO globalTransactionDO = new GlobalTransactionDO();
globalTransactionDO.setXid("abc-123:333");
globalTransactionDO.setApplicationData("abc=5454");
globalTransactionDO.setTransactionServiceGroup("abc");
globalTransactionDO.setTransactionName("test");
globalTransactionDO.setTransactionId(12345);
globalTransactionDO.setTimeout(20);
globalTransactionDO.setBeginTime(System.currentTimeMillis());
globalTransactionDO.setApplicationId("test");
globalTransactionDO.setStatus(1);
boolean ret = logStoreDataBaseDAO.insertGlobalTransactionDO(globalTransactionDO);
Assertions.assertTrue(ret);
String sql = "select * from global_table where xid= 'abc-123:333'";
String delSql = "delete from global_table where xid= 'abc-123:333'";
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.GlobalTransactionDO 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