org.apache.commons.dbutils.handlers.AbstractListHandler Java Examples

The following examples show how to use org.apache.commons.dbutils.handlers.AbstractListHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FastJdbc.java    From litchi with Apache License 2.0 5 votes vote down vote up
public <T extends Table<?>> List<Long> getPKList(Class<T> clazz, LinkedHashMap<String, Object> condition, int limitBegin, int limitEnd) {
    try {
        QueryRunner runner = getJdbcTemplate(clazz);
        TableInfo info = SuperTable.getTableInfo(clazz);
        String[] key = new String[condition.keySet().size()];
        String sql = selectSql.toSqlString(info.pkName(), info.annotation().tableName(),
                info.buildDbColumns(), info.pkName(), limitBegin, limitEnd, condition.keySet().toArray(key));
        if (limitBegin > 0) {
            condition.put("limitBegin", limitBegin);
        }
        if (limitEnd > 0 && limitEnd > limitBegin) {
            condition.put("limitEnd", limitEnd);
        }

        //return runner.queryForList(sql, condition.values().toArray(), Long.class);
        // new BeanListHandler<>(Long.class)
        return runner.query(sql, new AbstractListHandler<Long>() {
            @Override
            protected Long handleRow(ResultSet rs) throws SQLException {
                if (rs.next()) {
                    return rs.getLong(1);
                }
                return null;
            }
        }, condition);
    } catch (Exception e) {
        LOGGER.error("", e);
    }
    return null;
}