Example usage for org.apache.commons.dbutils BeanProcessor BeanProcessor

List of usage examples for org.apache.commons.dbutils BeanProcessor BeanProcessor

Introduction

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

Prototype

public BeanProcessor(Map<String, String> columnToPropertyOverrides) 

Source Link

Document

Constructor for BeanProcessor configured with column to property name overrides.

Usage

From source file:jp.co.golorp.emarf.model.Models.java

/**
 * dbutils?//  w  w  w.  j  a  v a  2  s  .  com
 *
 * @param modelName
 *            ??
 * @return RowProcessor
 */
private static RowProcessor getRowProcessor(final String modelName) {

    Map<String, String> mapping = new LinkedHashMap<String, String>();

    Map<String, String> propertyMeis = ModelUtil.getPropertyMeis(modelName);

    TableInfo tableInfo = MetaData.getTableInfo(modelName);

    for (String propertyName : propertyMeis.keySet()) {
        ColumnInfo columnInfo = tableInfo.getColumnInfo(propertyName);
        String columnName = columnInfo.getColumnName();
        mapping.put(columnName, propertyName);
    }

    BeanProcessor convert = new BeanProcessor(mapping);

    return new BasicRowProcessor(convert);
}

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  w w.j a v a 2  s .  c o  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;
}