Search in sources :

Example 16 with GlobalTransactionDO

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);
    }
}
Also used : GlobalTransactionDO(io.seata.core.store.GlobalTransactionDO) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Test(org.junit.jupiter.api.Test)

Example 17 with GlobalTransactionDO

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);
    }
}
Also used : GlobalTransactionDO(io.seata.core.store.GlobalTransactionDO) Connection(java.sql.Connection) Test(org.junit.jupiter.api.Test)

Example 18 with GlobalTransactionDO

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);
    }
}
Also used : GlobalTransactionDO(io.seata.core.store.GlobalTransactionDO) Connection(java.sql.Connection) Test(org.junit.jupiter.api.Test)

Example 19 with GlobalTransactionDO

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);
    }
}
Also used : GlobalTransactionDO(io.seata.core.store.GlobalTransactionDO) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Test(org.junit.jupiter.api.Test)

Example 20 with GlobalTransactionDO

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);
    }
}
Also used : Jedis(redis.clients.jedis.Jedis) GlobalTransactionDO(io.seata.core.store.GlobalTransactionDO) BranchTransactionDO(io.seata.core.store.BranchTransactionDO)

Aggregations

GlobalTransactionDO (io.seata.core.store.GlobalTransactionDO)24 Test (org.junit.jupiter.api.Test)10 BranchTransactionDO (io.seata.core.store.BranchTransactionDO)8 Connection (java.sql.Connection)8 GlobalSession (io.seata.server.session.GlobalSession)5 ResultSet (java.sql.ResultSet)4 Jedis (redis.clients.jedis.Jedis)4 ArrayList (java.util.ArrayList)3 DataAccessException (io.seata.common.exception.DataAccessException)2 Date (java.util.Date)2 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1