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 resetFailedAgents(String envId, String deployId) throws Exception {
    new QueryRunner(dataSource).update(RESET_FAILED_AGENTS, envId, deployId);
}

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

@Override
public void updateAlarmInfoById(String alarmId, AsgAlarmBean asgAlarmBean) throws Exception {
    SetClause setClause = asgAlarmBean.genSetClause();
    String clause = String.format(UPDATE_ALARM_BY_ID, setClause.getClause());
    setClause.addValue(alarmId);//from   ww  w  .j a va2  s.c  o  m
    new QueryRunner(dataSource).update(clause, setClause.getValueArray());
}

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

@Override
public List<TokenRolesBean> getByResource(String resourceId, Resource.Type resourceType) throws Exception {
    ResultSetHandler<List<TokenRolesBean>> h = new BeanListHandler<>(TokenRolesBean.class);
    return new QueryRunner(dataSource).query(GET_BY_RESOURCE, h, resourceId, resourceType.toString());
}

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

@Override
public void insertGroupInfo(GroupBean groupBean) throws Exception {
    if (groupBean.getLast_update() == null) {
        groupBean.setLast_update(System.currentTimeMillis());
    }/*www .  j  a  v a2s .  c om*/
    SetClause setClause = groupBean.genSetClause();
    String clause = String.format(INSERT_GROUP_INFO, setClause.getClause());
    new QueryRunner(dataSource).update(clause, setClause.getValueArray());
}

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

public int insertEODTicker(String equity, EODTicker ticker) throws SQLException {
    String sql = "insert into EOD (equity,openPrice,closePrice,highPrice,lowPrice,adjustedClose,volume,date) values(?,?,?,?,?,?,?,?)";
    String date = Util.getDate(ticker.getDate());
    Object[] params = new Object[] { equity, ticker.getOpenPrice(), ticker.getClosePrice(),
            ticker.getHighPrice(), ticker.getLowPrice(), ticker.getAdjustedClose(), ticker.getVolume(), date };
    QueryRunner run = new QueryRunner(DatabaseProperty.getDataSource());
    int updates = run.update(sql, params);
    //run.update("delete from EOD where volume=0");
    return updates;
}

From source file:de.iritgo.aktario.jdbc.LoadObject.java

/**
 * Load an object.//www.j ava2  s  . c  o  m
 *
 * @param dataSource The data source to load from.
 * @param typeId The type of the object to load.
 * @param uniqueId The unique id of the object to load.
 * @return The loaded object (already registered with the base registry).
 */
private DataObject load(final DataSource dataSource, final String typeId, long uniqueId) {
    DataObject object = null;

    try {
        QueryRunner query = new QueryRunner(dataSource);

        object = (DataObject) query.query("select * from " + typeId + " where id=" + uniqueId,
                new ResultSetHandler() {
                    public Object handle(ResultSet rs) throws SQLException {
                        rs.getMetaData();

                        if (rs.next()) {
                            try {
                                DataObject object = (DataObject) Engine.instance().getIObjectFactory()
                                        .newInstance(typeId);

                                object.setUniqueId(rs.getLong("id"));

                                for (Iterator i = object.getAttributes().entrySet().iterator(); i.hasNext();) {
                                    Map.Entry attribute = (Map.Entry) i.next();

                                    if (attribute.getValue() instanceof IObjectList) {
                                        loadList(dataSource, object,
                                                object.getIObjectListAttribute((String) attribute.getKey()));
                                    } else {
                                        try {
                                            if (!object.getAttribute((String) attribute.getKey()).getClass()
                                                    .equals(rs.getObject((String) attribute.getKey())
                                                            .getClass())) {
                                                System.out.println(
                                                        "********* Datastruct is not compatible with dataobject:"
                                                                + object.getTypeId() + ":" + attribute.getKey()
                                                                + " Types:"
                                                                + object.getAttribute(
                                                                        (String) attribute.getKey()).getClass()
                                                                + "!="
                                                                + rs.getObject((String) attribute.getKey())
                                                                        .getClass());
                                            }

                                            object.setAttribute((String) attribute.getKey(),
                                                    rs.getObject((String) attribute.getKey()));
                                        } catch (NullPointerException x) {
                                            System.out.println("LoadObject error: " + attribute.getKey());
                                        }
                                    }
                                }

                                return object;
                            } catch (NoSuchIObjectException ignored) {
                                Log.logError("persist", "LoadObject", "NoSuchIObjectException");
                            }
                        } else {
                        }

                        return null;
                    }
                });

        if (object != null) {
            Log.logVerbose("persist", "LoadObject", "Successfully loaded object " + typeId + ":" + uniqueId);
        } else {
            Log.logError("persist", "LoadObject", "Unable to find object " + typeId + ":" + uniqueId);
        }
    } catch (SQLException x) {
        Log.logError("persist", "LoadObject",
                "Error while loading the object " + typeId + ":" + uniqueId + ": " + x);
    }

    return object;
}

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

@Override
public List<SpotAutoScalingBean> getAllSpotAutoScalingGroups() throws Exception {
    ResultSetHandler<List<SpotAutoScalingBean>> h = new BeanListHandler<>(SpotAutoScalingBean.class);
    return new QueryRunner(dataSource).query(GET_ALL_CLUSTER, h);
}

From source file:azkaban.AzkabanCommonModule.java

@Provides
public QueryRunner createQueryRunner(AzkabanDataSource dataSource) {
    return new QueryRunner(dataSource);
}

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

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

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

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