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

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

Introduction

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

Prototype

public BeanHandler(Class<T> type) 

Source Link

Document

Creates a new instance of BeanHandler.

Usage

From source file:org.gaixie.jibu.security.dao.impl.SettingDAODerby.java

public Setting getDefault(Connection conn, String name) throws SQLException {
    ResultSetHandler<Setting> h = new BeanHandler(Setting.class);
    return run.query(conn,
            "SELECT id,name,value,sortindex,enabled FROM settings WHERE sortindex = 0 and name=? ", h, name);
}

From source file:org.gaixie.jibu.security.dao.impl.SettingDAODerby.java

public Setting getByUsername(Connection conn, String name, String username) throws SQLException {
    ResultSetHandler<Setting> h = new BeanHandler(Setting.class);
    String sql = " SELECT s.id,s.name,s.value,s.sortindex,s.enabled \n"
            + " FROM settings s, userbase u, user_setting_map usm \n" + " WHERE u.username=? \n"
            + "       AND u.id = usm.user_id \n" + "       AND usm.setting_id = s.id \n"
            + "       AND s.name = ?";

    return run.query(conn, sql, h, username, name);
}

From source file:org.gaixie.jibu.security.dao.impl.TokenDAODerby.java

public Token get(Connection conn, int id) throws SQLException {
    ResultSetHandler<Token> h = new BeanHandler(Token.class);
    return run.query(conn, "SELECT id,value,type,expiration,user_id FROM tokens WHERE id=? ", h, id);
}

From source file:org.gaixie.jibu.security.dao.impl.TokenDAODerby.java

public Token get(Connection conn, String value) throws SQLException {
    ResultSetHandler<Token> h = new BeanHandler(Token.class);
    return run.query(conn, "SELECT id,value,type,expiration,user_id FROM tokens WHERE value=? ", h, value);
}

From source file:org.gaixie.jibu.security.dao.impl.UserDAODerby.java

/**
 * {@inheritDoc}/*w  w  w .ja  v a2 s  . c om*/
 * <p>
 * password  null
 */
public User get(Connection conn, int id) throws SQLException {
    ResultSetHandler<User> h = new BeanHandler(User.class);
    return run.query(conn, "SELECT id,username,fullname,emailaddress,enabled FROM userbase WHERE id=? ", h, id);
}

From source file:org.gaixie.jibu.security.dao.impl.UserDAODerby.java

/**
 * {@inheritDoc}/*from w  w w.jav  a  2  s.  co  m*/
 * <p>
 * password  null
 */
public User get(Connection conn, String username) throws SQLException {
    ResultSetHandler<User> h = new BeanHandler(User.class);
    return run.query(conn, "SELECT id,username,fullname,emailaddress,enabled FROM userbase WHERE username=? ",
            h, username);
}

From source file:org.gaixie.jibu.security.dao.impl.UserDAODerby.java

/**
 * {@inheritDoc}//from  w  w  w.  ja  va  2s. co  m
 * <p>
 * password  null
 */
public User login(Connection conn, String username, String password) throws SQLException {
    ResultSetHandler<User> h = new BeanHandler(User.class);
    return run.query(conn,
            "SELECT id,username,fullname,emailaddress,enabled FROM userbase WHERE username=? AND password=? and enabled=1",
            h, username, password);
}

From source file:org.gaixie.jibu.security.dao.impl.UserDAOPgSQL.java

/**
 * {@inheritDoc}/*from   w w  w  . j av a 2  s  .co m*/
 * <p>
 * password  null
 */
public User login(Connection conn, String username, String password) throws SQLException {
    ResultSetHandler<User> h = new BeanHandler(User.class);
    return run.query(conn,
            "SELECT id,username,fullname,emailaddress,enabled FROM userbase WHERE username=? AND password=? and enabled=true",
            h, username, password);
}

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

/**
 * Return the first resultset row stuffed into a bean
 *
 * @param clazz//from www  .j a  v  a2 s .  c  o  m
 * @param sql
 * @param values
 * @return
 * @throws ServletException
 * @throws SQLException
 */
public static Object getBean(Class clazz, String sql, ArrayList values)
        throws ServletException, SQLException, ObjectNotFoundException {
    // DataSource dataSource = null;
    //dataSource = DatabaseUtils.getZEPRSDataSource();
    QueryRunner run = new QueryRunner(getZEPRSDataSource());
    ResultSetHandler h = new BeanHandler(clazz);
    // return the results in a new object generated by the BeanHandler.
    Object result = null;
    //  try {
    try {
        result = run.query(sql, values.toArray(), h);
    } catch (SQLException e) {
        log.error("SQL - params: " + values + "Error: " + e);
    }
    // log.info("Getting the bean " + clazz.toString());
    /* } catch (SQLException e) {
    log.error("SQL - params: " + values + "Error: " + e);
    }*/
    if (result == null) {
        throw new ObjectNotFoundException();
    }

    return result;
}

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

/**
 * Return the first resultset row stuffed into a bean
 * Be aware that getBean initialises null Objects such as Integer to 0. If you don't like that, use getZEPRSBean instead.
 *
 * @param clazz/*  w w  w.j a va 2s  . c o m*/
 * @param sql
 * @param values
 * @return
 * @throws ServletException
 * @throws SQLException
 */
public static Object getBean(Connection conn, Class clazz, String sql, ArrayList values)
        throws ServletException, SQLException, ObjectNotFoundException {

    QueryRunner run = new QueryRunner();
    ResultSetHandler h = new BeanHandler(clazz);
    // return the results in a new object generated by the BeanHandler.
    Object result = null;
    try {
        result = run.query(conn, sql, h, values.toArray());
    } catch (SQLException e) {
        log.error("SQL - params: " + values + "Error: " + e);
    }

    if (result == null) {
        throw new ObjectNotFoundException();
    }

    return result;
}