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

The following examples show how to use org.apache.commons.dbutils.handlers.AbstractListHandler. These examples are extracted from open source projects. 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 Project: litchi   Source File: FastJdbc.java    License: 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;
}