Search in sources :

Example 6 with GlobalTransactionDO

use of io.seata.core.store.GlobalTransactionDO in project seata by seata.

the class SessionConverterTest method testConvertGlobalSessionNull.

@Test
public void testConvertGlobalSessionNull() {
    GlobalTransactionDO globalTransactionDO = null;
    GlobalSession globalSession = SessionConverter.convertGlobalSession(globalTransactionDO);
    Assertions.assertNull(globalSession);
}
Also used : GlobalTransactionDO(io.seata.core.store.GlobalTransactionDO) GlobalSession(io.seata.server.session.GlobalSession) Test(org.junit.jupiter.api.Test)

Example 7 with GlobalTransactionDO

use of io.seata.core.store.GlobalTransactionDO in project seata by seata.

the class SessionConverterTest method testConvertGlobalSessionNotNull.

@Test
public void testConvertGlobalSessionNotNull() {
    GlobalTransactionDO globalTransactionDO = new GlobalTransactionDO();
    Date date = new Date();
    long now = date.getTime();
    globalTransactionDO.setXid("192.168.158.80:8091:39372760251957248");
    globalTransactionDO.setTransactionId(39372760251957248L);
    globalTransactionDO.setStatus(1);
    globalTransactionDO.setApplicationId("credit");
    globalTransactionDO.setTransactionServiceGroup("fsp_tx");
    globalTransactionDO.setTransactionName("createOrder");
    globalTransactionDO.setTimeout(60);
    globalTransactionDO.setBeginTime(now);
    globalTransactionDO.setApplicationData("id=1,product=2");
    globalTransactionDO.setGmtCreate(date);
    globalTransactionDO.setGmtModified(date);
    GlobalSession globalSession = SessionConverter.convertGlobalSession(globalTransactionDO);
    Assertions.assertEquals(globalTransactionDO.getXid(), globalSession.getXid());
    Assertions.assertEquals(globalTransactionDO.getTransactionId(), globalSession.getTransactionId());
    Assertions.assertEquals(globalTransactionDO.getStatus(), globalSession.getStatus().getCode());
    Assertions.assertEquals(globalTransactionDO.getApplicationId(), globalSession.getApplicationId());
    Assertions.assertEquals(globalTransactionDO.getTransactionServiceGroup(), globalSession.getTransactionServiceGroup());
    Assertions.assertEquals(globalTransactionDO.getTransactionName(), globalSession.getTransactionName());
    Assertions.assertEquals(globalTransactionDO.getTimeout(), globalSession.getTimeout());
    Assertions.assertEquals(globalTransactionDO.getBeginTime(), globalSession.getBeginTime());
    Assertions.assertEquals(globalTransactionDO.getApplicationData(), globalSession.getApplicationData());
}
Also used : GlobalTransactionDO(io.seata.core.store.GlobalTransactionDO) GlobalSession(io.seata.server.session.GlobalSession) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 8 with GlobalTransactionDO

use of io.seata.core.store.GlobalTransactionDO in project seata by seata.

the class LogStoreDataBaseDAO method convertGlobalTransactionDO.

private GlobalTransactionDO convertGlobalTransactionDO(ResultSet rs) throws SQLException {
    GlobalTransactionDO globalTransactionDO = new GlobalTransactionDO();
    globalTransactionDO.setXid(rs.getString(ServerTableColumnsName.GLOBAL_TABLE_XID));
    globalTransactionDO.setStatus(rs.getInt(ServerTableColumnsName.GLOBAL_TABLE_STATUS));
    globalTransactionDO.setApplicationId(rs.getString(ServerTableColumnsName.GLOBAL_TABLE_APPLICATION_ID));
    globalTransactionDO.setBeginTime(rs.getLong(ServerTableColumnsName.GLOBAL_TABLE_BEGIN_TIME));
    globalTransactionDO.setTimeout(rs.getInt(ServerTableColumnsName.GLOBAL_TABLE_TIMEOUT));
    globalTransactionDO.setTransactionId(rs.getLong(ServerTableColumnsName.GLOBAL_TABLE_TRANSACTION_ID));
    globalTransactionDO.setTransactionName(rs.getString(ServerTableColumnsName.GLOBAL_TABLE_TRANSACTION_NAME));
    globalTransactionDO.setTransactionServiceGroup(rs.getString(ServerTableColumnsName.GLOBAL_TABLE_TRANSACTION_SERVICE_GROUP));
    globalTransactionDO.setApplicationData(rs.getString(ServerTableColumnsName.GLOBAL_TABLE_APPLICATION_DATA));
    globalTransactionDO.setGmtCreate(rs.getTimestamp(ServerTableColumnsName.GLOBAL_TABLE_GMT_CREATE));
    globalTransactionDO.setGmtModified(rs.getTimestamp(ServerTableColumnsName.GLOBAL_TABLE_GMT_MODIFIED));
    return globalTransactionDO;
}
Also used : GlobalTransactionDO(io.seata.core.store.GlobalTransactionDO)

Example 9 with GlobalTransactionDO

use of io.seata.core.store.GlobalTransactionDO in project seata by seata.

the class LogStoreDataBaseDAO method queryGlobalTransactionDO.

@Override
public List<GlobalTransactionDO> queryGlobalTransactionDO(int[] statuses, int limit) {
    List<GlobalTransactionDO> ret = new ArrayList<>();
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        conn = logStoreDataSource.getConnection();
        conn.setAutoCommit(true);
        String paramsPlaceHolder = org.apache.commons.lang.StringUtils.repeat("?", ",", statuses.length);
        String sql = LogStoreSqlsFactory.getLogStoreSqls(dbType).getQueryGlobalTransactionSQLByStatus(globalTable, paramsPlaceHolder);
        ps = conn.prepareStatement(sql);
        for (int i = 0; i < statuses.length; i++) {
            int status = statuses[i];
            ps.setInt(i + 1, status);
        }
        ps.setInt(statuses.length + 1, limit);
        rs = ps.executeQuery();
        while (rs.next()) {
            ret.add(convertGlobalTransactionDO(rs));
        }
        return ret;
    } catch (SQLException e) {
        throw new DataAccessException(e);
    } finally {
        IOUtil.close(rs, ps, conn);
    }
}
Also used : GlobalTransactionDO(io.seata.core.store.GlobalTransactionDO) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DataAccessException(io.seata.common.exception.DataAccessException)

Example 10 with GlobalTransactionDO

use of io.seata.core.store.GlobalTransactionDO in project seata by seata.

the class SessionConverter method convertGlobalTransactionDO.

public static GlobalTransactionDO convertGlobalTransactionDO(SessionStorable session) {
    if (session == null || !(session instanceof GlobalSession)) {
        throw new IllegalArgumentException("The parameter of SessionStorable is not available, SessionStorable:" + StringUtils.toString(session));
    }
    GlobalSession globalSession = (GlobalSession) session;
    GlobalTransactionDO globalTransactionDO = new GlobalTransactionDO();
    globalTransactionDO.setXid(globalSession.getXid());
    globalTransactionDO.setStatus(globalSession.getStatus().getCode());
    globalTransactionDO.setApplicationId(globalSession.getApplicationId());
    globalTransactionDO.setBeginTime(globalSession.getBeginTime());
    globalTransactionDO.setTimeout(globalSession.getTimeout());
    globalTransactionDO.setTransactionId(globalSession.getTransactionId());
    globalTransactionDO.setTransactionName(globalSession.getTransactionName());
    globalTransactionDO.setTransactionServiceGroup(globalSession.getTransactionServiceGroup());
    globalTransactionDO.setApplicationData(globalSession.getApplicationData());
    return globalTransactionDO;
}
Also used : GlobalTransactionDO(io.seata.core.store.GlobalTransactionDO) GlobalSession(io.seata.server.session.GlobalSession)

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