Search in sources :

Example 16 with DataAccessException

use of io.seata.common.exception.DataAccessException 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

DataAccessException (io.seata.common.exception.DataAccessException)16 SQLException (java.sql.SQLException)10 Connection (java.sql.Connection)8 PreparedStatement (java.sql.PreparedStatement)8 ResultSet (java.sql.ResultSet)8 ArrayList (java.util.ArrayList)6 BranchTransactionDO (io.seata.core.store.BranchTransactionDO)4 GlobalTransactionDO (io.seata.core.store.GlobalTransactionDO)2 StringJoiner (java.util.StringJoiner)1