Search in sources :

Example 21 with GlobalTransactionDO

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

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

Example 22 with GlobalTransactionDO

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

the class DataBaseTransactionStoreManager method readSession.

/**
 * Read session global session.
 *
 * @param transactionId the transaction id
 * @return the global session
 */
public GlobalSession readSession(Long transactionId) {
    // global transaction
    GlobalTransactionDO globalTransactionDO = logStore.queryGlobalTransactionDO(transactionId);
    if (globalTransactionDO == null) {
        return null;
    }
    // branch transactions
    List<BranchTransactionDO> branchTransactionDOs = logStore.queryBranchTransactionDO(globalTransactionDO.getXid());
    return getGlobalSession(globalTransactionDO, branchTransactionDOs);
}
Also used : GlobalTransactionDO(io.seata.core.store.GlobalTransactionDO) BranchTransactionDO(io.seata.core.store.BranchTransactionDO)

Example 23 with GlobalTransactionDO

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

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 24 with GlobalTransactionDO

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

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) ArrayList(java.util.ArrayList) DataAccessException(io.seata.common.exception.DataAccessException)

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