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) 

Source Link

Document

Creates a new instance of BeanListHandler.

Usage

From source file:com.che.software.testato.domain.dao.jdbc.impl.TransitionDAO.java

/**
 * Transition search from a bean of criterions.
 * /*from ww w.  j a  v  a 2s.  c  o  m*/
 * @author Clement HELIOU (clement.heliou@che-software.com).
 * @param searchBean the criterions to use for the search.
 * @return the resulting object list.
 * @since July, 2011.
 * @throws TransitionSearchDAOException if an error occurs during the
 *         search.
 */
@Override
public List<Transition> searchTransition(TransitionSearch searchBean) throws TransitionSearchDAOException {
    LOGGER.debug("searchTransition().");
    Connection connection = null;
    try {
        connection = getDataSource().getConnection();
        List<Object> params = new ArrayList<Object>();
        return getQueryRunner().query(connection, getTransitionSearchQueryFromCriterion(searchBean, params),
                new BeanListHandler<Transition>(Transition.class), params.toArray());
    } catch (SQLException e) {
        throw new TransitionSearchDAOException(e);
    } finally {
        if (null != connection) {
            DbUtils.closeQuietly(connection);
        }
    }
}

From source file:com.che.software.testato.domain.dao.jdbc.impl.ScriptItemDAO.java

/**
 * Script item search from a bean of criterions.
 * //from  ww  w  .j a v a2s .co m
 * @author Clement HELIOU (clement.heliou@che-software.com).
 * @param searchBean the criterions to use for the search.
 * @return the resulting object list.
 * @since July, 2011.
 * @throws ScriptItemSearchDAOException if an error occurs during the
 *         search.
 */
@Override
public List<ScriptItem> searchScriptItem(ScriptItemSearch searchBean) throws ScriptItemSearchDAOException {
    LOGGER.debug("searchScriptItem().");
    Connection connection = null;
    try {
        connection = getDataSource().getConnection();
        List<Object> params = new ArrayList<Object>();
        return getQueryRunner().query(connection, getScriptItemSearchQueryFromCriterion(searchBean, params),
                new BeanListHandler<ScriptItem>(ScriptItem.class), params.toArray());
    } catch (SQLException e) {
        throw new ScriptItemSearchDAOException(e);
    } finally {
        if (null != connection) {
            DbUtils.closeQuietly(connection);
        }
    }
}

From source file:com.che.software.testato.domain.dao.jdbc.impl.RandomIndexDAO.java

/**
 * Random index search from a bean of criterions.
 * /* ww w  .ja v a 2  s . co  m*/
 * @author Clement HELIOU (clement.heliou@che-software.com).
 * @param searchBean the criterions to use for the search.
 * @return the resulting object list.
 * @since August, 2011.
 * @throws RandomIndexSearchDAOException if an error occurs during the
 *         search.
 */
@Override
public List<RandomIndex> searchRandomIndex(RandomIndexSearch searchBean) throws RandomIndexSearchDAOException {
    LOGGER.debug("searchRandomIndex().");
    Connection connection = null;
    try {
        connection = getDataSource().getConnection();
        List<Object> params = new ArrayList<Object>();
        return getQueryRunner().query(connection, getRandomIndexSearchQueryFromCriterion(searchBean, params),
                new BeanListHandler<RandomIndex>(RandomIndex.class), params.toArray());
    } catch (SQLException e) {
        throw new RandomIndexSearchDAOException(e);
    } finally {
        if (null != connection) {
            DbUtils.closeQuietly(connection);
        }
    }
}

From source file:com.ouc.cpss.dao.BaseDao.java

/**
 * ?/*from  w  w  w  .j a v a  2 s .  c  om*/
 *
 * @param sql
 * @param clazz
 * @return
 */
public List query(String sql, Class clazz, Object[] params) {
    List beans = null;
    Connection conn = null;
    try {
        conn = getConnection();
        QueryRunner qRunner = new QueryRunner();
        beans = (List) qRunner.query(conn, sql, new BeanListHandler(clazz), params);

        //BeanListHandler?ResultSet???List?
        //????ResultSet
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        DbUtils.closeQuietly(conn);
    }
    return beans;
}

From source file:com.paladin.sys.db.QueryHelper.java

/**
 *  /*from   w  w  w. j  a v a 2  s. c o m*/
 *
 * @param <T>
 * @param beanClass
 * @param sql
 * @param params
 * @return
 */
public static <T> List<T> query(Class<T> beanClass, String sql, Object... params) {
    try {
        return (List<T>) RUNNER.query(getConnection(), sql,
                IS_PRIMITIVE(beanClass) ? COLUMN_LIST_HANDLER : new BeanListHandler(beanClass), params);
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        DBManager.closeConnection();
    }
    return null;
}

From source file:com.fluke.database.dataservice.EODDao.java

public List<EODTicker> getEODTickers(String equity, Date fromDate, Date toDate) throws SQLException {
    QueryRunner run = new QueryRunner(DatabaseProperty.getDataSource());
    String sql = "select * from EOD  where equity = ? and date between '%s' and '%s' order by date";
    String from = Util.getDate(fromDate);
    String to = Util.getDate(toDate);
    sql = String.format(sql, from, to);
    Object[] params = new Object[] { equity };
    ResultSetHandler rsh = new BeanListHandler(EODTicker.class);
    return filterDupicateDate((List<EODTicker>) run.query(sql, rsh, params));
}

From source file:epgtools.epgdbbean.bean.Programme.ProgrammeGetterTest.java

private ProgrammeChannelNo_ReadOnly chooseAppropriately(Connection con) throws SQLException {
    //?????????1??
    QueryRunner runner = new QueryRunner();
    List<ProgrammeChannelNo> Programmes;
    Programmes = runner.query(con, SELECT_ALL_CHANNEL_VIEW,
            new BeanListHandler<ProgrammeChannelNo>(ProgrammeChannelNo.class));
    Iterator<ProgrammeChannelNo> j = Programmes.iterator();

    Random rnd = new Random();
    int ran = rnd.nextInt(Programmes.size()) + 1;
    ProgrammeChannelNo p = null;//from w  w  w . java2s  . c om

    int i = 1;
    while (j.hasNext()) { //Iterator????? 
        p = j.next();
        if (ran == i) {
            break;
        }
        i++;
    }
    return p;
}

From source file:com.softberries.klerk.dao.AddressDao.java

public List<Address> findAllByPersonId(Long companyId, QueryRunner run, Connection conn) throws SQLException {
    List<Address> addresses = new ArrayList<Address>();
    ResultSetHandler<List<Address>> h = new BeanListHandler<Address>(Address.class);
    addresses = run.query(conn, SQL_FIND_ADDRESS_ALL_BY_PERSON_ID, h, companyId);
    return addresses;
}

From source file:com.softberries.klerk.dao.DocumentItemDao.java

public List<DocumentItem> findAllByDocumentId(Long docId, QueryRunner run, Connection conn)
        throws SQLException {
    List<DocumentItem> items = new ArrayList<DocumentItem>();
    ResultSetHandler<List<DocumentItem>> h = new BeanListHandler<DocumentItem>(DocumentItem.class);
    items = run.query(conn, SQL_FIND_DOCUMENTITEM_ALL_BY_DOCUMENT_ID, h, docId);
    ProductDao pdao = new ProductDao(this.path);
    for (DocumentItem di : items) {
        di.setProduct(pdao.find(di.getProduct_id(), run, conn));
    }/*from   w w  w  .  j a  v a  2 s . c om*/
    return items;
}

From source file:magrathea.marvin.desktop.user.dao.DerbyDAO.DerbyUserDAO.java

@Override
public List<User> findUsersByProperty(UserSearchType searchType, Object value) {
    String whereClause = "";
    String valueClause = "";

    switch (searchType) {
    case ID://from   w  ww. ja  v  a 2 s  .  co m
        whereClause = "id = ?";
        valueClause = value.toString();
        break;
    case NICKNAME:
        whereClause = "nickname LIKE ?";
        valueClause = "%" + value.toString() + "%";
        break;
    case PASSWORD:
        whereClause = "password = ?";
        valueClause = value.toString();
        break;
    case EMAIL:
        whereClause = "email LIKE ?";
        valueClause = "%" + value.toString() + "%";
        break;
    case ADMINISTRATOR:
        whereClause = "administrator = ?";
        valueClause = value.toString();
        break;
    default:
        throw new AssertionError(searchType.name());
    }

    try {
        return dbAccess.query(con, "SELECT * FROM \"User\" WHERE " + whereClause,
                // proces a row from result to a bean
                new BeanListHandler<User>(User.class), valueClause);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return EMPTY;
}