Example usage for org.apache.commons.dbutils.handlers BeanListHandler BeanListHandler

List of usage examples for org.apache.commons.dbutils.handlers BeanListHandler BeanListHandler

Introduction

In this page you can find the example usage for org.apache.commons.dbutils.handlers BeanListHandler BeanListHandler.

Prototype

public BeanListHandler(Class<T> type, RowProcessor convert) 

Source Link

Document

Creates a new instance of BeanListHandler.

Usage

From source file:org.rti.zcore.dar.utils.DatabaseUtils.java

/**
 * Fetch a simple list of values//from  ww  w .ja  v a2  s . co  m
 *
 * @param clazz
 * @param sql
 * @param values
 * @return
 * @throws ServletException
 * @throws SQLException
 */
public static List getList(Connection conn, Class clazz, String sql, ArrayList values)
        throws ServletException, SQLException {
    QueryRunner run = null;
    try {
        // run = new QueryRunner(dataSource);
        run = new QueryRunner();
    } catch (Exception e) {
        log.error(e);
    }
    ResultSetHandler h = new BeanListHandler(clazz, new BasicRowProcessor(new ZEPRSBeanProcessor()));
    // return the results in a new object generated by the BeanHandler.
    List list = null;
    try {
        list = (List) run.query(conn, sql, values.toArray(), h);
    } catch (SQLException e) {
        log.error(e);
        e.printStackTrace();
    }
    return list;
}

From source file:org.rti.zcore.dar.utils.DatabaseUtils.java

/**
 * Fetch a simple list of values. Emulates MySQL LIMIT
 * @param conn//from  ww w .  j  a  v a2s  . c  o  m
 * @param clazz
 * @param sql
 * @param values
 * @param maxRows
 * @return
 * @throws ServletException
 * @throws SQLException
 */
public static List getList(Connection conn, Class clazz, String sql, ArrayList values, Integer maxRows)
        throws ServletException, SQLException {
    ZEPRSQueryRunner run = null;
    try {
        run = new ZEPRSQueryRunner();
    } catch (Exception e) {
        log.error(e);
    }
    ResultSetHandler h = new BeanListHandler(clazz, new BasicRowProcessor(new ZEPRSBeanProcessor()));
    // return the results in a new object generated by the BeanHandler.
    List list = null;
    try {
        list = (List) run.query(conn, sql, values.toArray(), h, maxRows);
    } catch (SQLException e) {
        log.error(e);
        e.printStackTrace();
    }
    return list;
}

From source file:org.rti.zcore.dar.utils.DatabaseUtils.java

/**
 * For classes w/ nested objects such as AuditInfo
 *
 * @param clazz/*www.jav a  2  s  .co m*/
 * @param sql
 * @param values
 * @param convert
 * @return
 * @throws ServletException
 * @throws SQLException
 */
public static List getList(Class clazz, String sql, ArrayList values, RowProcessor convert)
        throws ServletException, SQLException {
    DataSource dataSource = null;
    dataSource = DatabaseUtils.getZEPRSDataSource();
    QueryRunner run = new QueryRunner(dataSource);
    ResultSetHandler h = new BeanListHandler(clazz, convert);
    // return the results in a new object generated by the BeanHandler.
    List list = (List) run.query(sql, values.toArray(), h);
    return list;

}

From source file:org.rti.zcore.dar.utils.DatabaseUtils.java

/**
 * For classes w/ nested objects such as AuditInfo. Takes a connection (reports)
 *
 * @param clazz//from w  ww.  ja  va  2s .  c om
 * @param sql
 * @param values
 * @param convert
 * @return
 * @throws ServletException
 * @throws SQLException
 */
public static List getList(Connection conn, Class clazz, String sql, ArrayList values, RowProcessor convert)
        throws ServletException, SQLException {
    //DataSource dataSource = null;
    //dataSource = DatabaseUtils.getZEPRSDataSource();
    QueryRunner run = new QueryRunner();
    ResultSetHandler h = new BeanListHandler(clazz, convert);
    // return the results in a new object generated by the BeanHandler.
    List list = (List) run.query(conn, sql, values.toArray(), h);
    return list;

}

From source file:test.com.handle.DataSource.java

public static <T> List<T> queryBeanList(Class<T> cls, Map<String, String> map, String sql, Object... params)
        throws SQLException {
    Connection conn = ds.getConnection();

    List<T> result = null;//  w ww .  j  a  v  a  2 s.co  m
    try {
        if (MapUtils.isNotEmpty(map)) {
            result = runner.query(conn, sql,
                    new BeanListHandler<T>(cls, new BasicRowProcessor(new BeanProcessor(map))), params);
        } else {
            result = runner.query(conn, sql, new BeanListHandler<T>(cls), params);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    shutdown();
    return result;
}