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

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

Introduction

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

Prototype

public QueryRunner(DataSource ds) 

Source Link

Document

Constructor for QueryRunner that takes a DataSource to use.

Usage

From source file:com.pinterest.arcee.db.DBGroupInfoDAOImpl.java

@Override
public List<String> getGroupNamesByEnvNameAndASGStatus(String envName, String asgStatus) throws Exception {
    return new QueryRunner(dataSource).query(GET_GROUPNAMES_BY_ENVNAME_AND_ASGSTATUS,
            SingleResultSetHandlerFactory.<String>newListObjectHandler(), envName, asgStatus);
}

From source file:com.eryansky.core.db.DbUtilsDao.java

/**
 * ??Map?Map?List//  ww w. ja  va2s . co m
 * 
 * @param sql
 *            sql?
 * @param params
 *            ?
 * @return 
 */
public List<Map<String, Object>> find(String sql, Object[] params) throws DaoException {
    queryRunner = new QueryRunner(dataSource);
    List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
    try {
        if (params == null) {
            list = (List<Map<String, Object>>) queryRunner.query(sql, new MapListHandler());
        } else {
            list = (List<Map<String, Object>>) queryRunner.query(sql, new MapListHandler(), params);
        }
    } catch (SQLException e) {
        logger.error("Error occured while attempting to query data", e);
        throw new DaoException(e);
    }
    return list;
}

From source file:com.pinterest.deployservice.db.DBAgentDAOImpl.java

@Override
public List<AgentBean> getByEnvAndFirstDeployTime(String envId, long time) throws Exception {
    ResultSetHandler<List<AgentBean>> h = new BeanListHandler<>(AgentBean.class);
    return new QueryRunner(dataSource).query(GET_AGENT_BY_ENV_AND_FIRST_DEPLOY_TIME, h, envId, time);
}

From source file:info.pancancer.arch3.persistence.PostgreSQL.java

private <T> T runInsertStatement(String query, ResultSetHandler<T> handler, Object... params) {
    try {/*from w  w w  .j  av a  2 s.  c  o  m*/
        QueryRunner run = new QueryRunner(dataSource);
        return run.insert(query, handler, params);
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}

From source file:de.tu_berlin.dima.oligos.db.oracle.OracleColumnConnector.java

@Override
public Set<Constraint> getConstraints() throws SQLException {
    if (constraints == null) {
        constraints = Sets.newHashSet();
        ResultSetHandler<List<String>> handler = new ColumnListHandler<>("TYPE");
        QueryRunner runner = new QueryRunner(true);
        List<String> cons = runner.query(connector.getConnection(), CONSTRAINT_QUERY, handler, schema, table,
                column);//from   w w w . j av a2 s.c o  m

        if (cons.contains("U")) {
            constraints.add(Constraint.UNIQUE);
        } else if (cons.contains("P")) {
            constraints.add(Constraint.PRIMARY_KEY);
        } else if (cons.contains("R")) {
            constraints.add(Constraint.FOREIGN_KEY);
        }

    }
    return constraints;
}

From source file:jongo.demo.Demo.java

private static void destroyDemoDatabase(final DatabaseConfiguration dbcfg) {
    final String database = dbcfg.getDatabase();
    QueryRunner run = new QueryRunner(JDBCConnectionFactory.getDataSource(dbcfg));
    l.info("Destroying Demo Tables in database " + database);
    try {//w w w.ja  va  2  s.  c  om
        run.update("DROP FUNCTION simpleStoredProcedure");
        run.update("DROP PROCEDURE insert_comment");
        run.update("DROP PROCEDURE get_year_sales");
        run.update("DROP VIEW MAKER_STATS_2010");
        run.update("DROP TABLE maker_stats");
        run.update("DROP TABLE sales_stats");
        run.update("DROP TABLE comments");
        run.update("DROP TABLE pictures");
        run.update("DROP TABLE car");
        run.update("DROP TABLE users");
        run.update("DROP TABLE maker");
        run.update("DROP TABLE empty");
    } catch (SQLException ex) {
        l.error("Failed to destroy demo tables " + ex.getMessage());
    } finally {
        try {
            run.getDataSource().getConnection().close();
        } catch (SQLException ex) {
            l.error("Failed to close demo database " + ex.getMessage());
        }
    }
}

From source file:com.pinterest.deployservice.db.DBHostTagDAOImpl.java

@Override
public long countHostsByEnvIdAndTags(String envId, String tagName, List<String> tagValues) throws Exception {
    String tagValuesStr = QueryUtils.genStringGroupClause(tagValues);
    Long n = new QueryRunner(dataSource).query(String.format(COUNT_HOSTS_BY_ENV_ID_AND_TAGS, tagValuesStr),
            SingleResultSetHandlerFactory.<Long>newObjectHandler(), envId, tagName);
    return n == null ? 0 : n;
}

From source file:com.pinterest.deployservice.db.DBBuildDAOImpl.java

@Override
public List<BuildBean> getByNameDate(String buildName, String branch, long before, long after)
        throws Exception {
    QueryRunner run = new QueryRunner(this.dataSource);
    ResultSetHandler<List<BuildBean>> h = new BeanListHandler<>(BuildBean.class);
    if (StringUtils.isNotEmpty(branch)) {
        return run.query(GET_BUILDS_BY_NAME_X_2, h, buildName, branch, before, after);
    } else {/*w ww . jav a 2s. c o m*/
        return run.query(GET_BUILDS_BY_NAME_X, h, buildName, before, after);
    }
}

From source file:com.pinterest.deployservice.db.DBDeployDAOImpl.java

@Override
public void insert(DeployBean deployBean) throws Exception {
    SetClause setClause = deployBean.genSetClause();
    String clause = String.format(INSERT_DEPLOYMENT_TEMPLATE, setClause.getClause());
    new QueryRunner(dataSource).update(clause, setClause.getValueArray());
}

From source file:com.pinterest.deployservice.db.DBAgentDAOImpl.java

@Override
public AgentBean getByHostEnvIds(String hostId, String envId) throws Exception {
    ResultSetHandler<AgentBean> h = new BeanHandler<>(AgentBean.class);
    return new QueryRunner(dataSource).query(GET_BY_IDS, h, hostId, envId);
}