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.deployservice.db.DBAgentDAOImpl.java

@Override
public void deleteAllById(String id) throws Exception {
    new QueryRunner(dataSource).update(DELETE_AGENT_BY_ID, id);
}

From source file:gr.osmosis.rcpsamples.contact.db.derby.DerbyContactsDAO.java

public boolean updateContact(Contact contact) {
    if (contact == null) {
        throw new NullPointerException("contact parameter");
    }//  ww  w .j  a  va 2 s .co  m

    int rows = 0;

    try {
        StringBuffer sbUpdate = new StringBuffer();

        sbUpdate.append("UPDATE ");
        sbUpdate.append(ContactsConstants.CONTACTS_TABLE_NAME);
        sbUpdate.append(" SET ");
        sbUpdate.append(ContactsConstants.CONTACTS_COL_FNAME + " = '" + contact.getFname() + "' , ");
        sbUpdate.append(ContactsConstants.CONTACTS_COL_LNAME + " = '" + contact.getLname() + "' , ");
        sbUpdate.append(ContactsConstants.CONTACTS_COL_PHONE + " = '" + contact.getPhone() + "' , ");
        sbUpdate.append(ContactsConstants.CONTACTS_COL_ADDRESS + " = '" + contact.getAddress() + "' , ");
        sbUpdate.append(ContactsConstants.CONTACTS_COL_CITY + " = '" + contact.getCity() + "' , ");
        sbUpdate.append(ContactsConstants.CONTACTS_COL_ZIP + " = '" + contact.getZip() + "'  ");

        sbUpdate.append(" WHERE " + ContactsConstants.CONTACTS_COL_ID + " = " + contact.getId());

        DataSource d = DerbyDAOFactory.getDataSource();
        QueryRunner run = new QueryRunner(d);

        rows = run.update(sbUpdate.toString());

        if (rows != 1) {
            throw new SQLException("executeUpdate return value: " + rows);
        }

    } catch (SQLException ex) {
        // throw new DAORuntimeException(ex);
        System.out.println(ex.getMessage());
        return false;
    }

    return true;

}

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

@Override
public BuildBean getLatest(String buildName, String branch) throws Exception {
    QueryRunner run = new QueryRunner(this.dataSource);
    ResultSetHandler<BuildBean> h = new BeanHandler<>(BuildBean.class);
    if (StringUtils.isNotEmpty(branch)) {
        return run.query(GET_LATEST_BUILD_BY_NAME_2, h, buildName, branch);
    } else {//from   www . j a v  a  2s  .  c  om
        return run.query(GET_LATEST_BUILD_BY_NAME, h, buildName);
    }
}

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

@Override
public void update(String envName, String envStage, EnvironBean bean) throws Exception {
    SetClause setClause = bean.genSetClause();
    String clause = String.format(UPDATE_ENV_BY_STAGE_TEMPLATE, setClause.getClause());
    setClause.addValue(envName);//  w ww  .j av  a2 s.c o  m
    setClause.addValue(envStage);
    new QueryRunner(dataSource).update(clause, setClause.getValueArray());
}

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

@Override
public List<String> getNewGroupNames() throws Exception {
    return new QueryRunner(dataSource).query(GET_NEW_GROUP_INFO,
            SingleResultSetHandlerFactory.<String>newListObjectHandler());
}

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

@Override
public void delete(String deployId) throws Exception {
    new QueryRunner(dataSource).update(DELETE_DEPLOYMENT, deployId);
}

From source file:io.dockstore.common.BasicPostgreSQL.java

protected <T> T runInsertStatement(String query, ResultSetHandler<T> handler, Object... params) {
    try {/*from ww  w  .ja v a2s  . c  o  m*/
        QueryRunner run = new QueryRunner(dataSource);
        return run.insert(query, handler, params);
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}

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

@Override
public List<AgentBean> getByHost(String hostName) throws Exception {
    ResultSetHandler<List<AgentBean>> h = new BeanListHandler<>(AgentBean.class);
    return new QueryRunner(dataSource).query(GET_AGENT_BY_HOST, h, hostName);
}

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

@Override
public List<HostTagBean> getAllByEnvIdAndTagName(String envId, String tagName) throws Exception {
    ResultSetHandler<List<HostTagBean>> h = new BeanListHandler<>(HostTagBean.class);
    return new QueryRunner(dataSource).query(GET_ALL_BY_ENV_ID_AND_TAG_NAME, h, envId, tagName);
}

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

@Override
public List<HealthCheckBean> getRegularHealthChecksByGroupAndTime(String groupName, long time)
        throws Exception {
    ResultSetHandler<List<HealthCheckBean>> h = new BeanListHandler<HealthCheckBean>(HealthCheckBean.class);
    return new QueryRunner(dataSource).query(GET_REGULAR_HEALTH_CHECK_BY_GROUP_AND_TIME, h, groupName,
            HealthCheckType.TIME_TRIGGERED.toString(), time);
}