List of usage examples for org.apache.commons.dbutils QueryRunner query
private <T> T query(Connection conn, boolean closeConn, String sql, ResultSetHandler<T> rsh, Object... params) throws SQLException
From source file:com.pinterest.deployservice.db.DBHotfixDAOImpl.java
@Override public List<HotfixBean> getHotfixes(String envName, int pageIndex, int pageSize) throws Exception { ResultSetHandler<List<HotfixBean>> h = new BeanListHandler<>(HotfixBean.class); QueryRunner run = new QueryRunner(this.dataSource); return run.query(GET_HOTFIXES, h, envName, (pageIndex - 1) * pageSize, pageSize); }
From source file:com.pinterest.arcee.db.DBImageDAOImpl.java
@Override public List<ImageBean> getImages(String appName, int pageIndex, int pageSize) throws Exception { QueryRunner run = new QueryRunner(dataSource); ResultSetHandler<List<ImageBean>> h = new BeanListHandler<>(ImageBean.class); if (StringUtils.isNotEmpty(appName)) { return run.query(GET_AMI_BY_APPNAME, h, appName, (pageIndex - 1) * pageSize, pageSize); } else {/* www . j a va 2 s.co m*/ return run.query(GET_ALL_AMI, h, (pageIndex - 1) * pageSize, pageSize); } }
From source file:com.pinterest.deployservice.db.DBBuildDAOImpl.java
@Override public List<String> getBuildNames(String nameFilter, int pageIndex, int pageSize) throws Exception { QueryRunner run = new QueryRunner(this.dataSource); if (StringUtils.isNotEmpty(nameFilter)) { return run.query(GET_BUILD_NAMES, SingleResultSetHandlerFactory.<String>newListObjectHandler(), String.format("%%%s%%", nameFilter), (pageIndex - 1) * pageSize, pageSize); } else {//from w w w . j a va2s . co m return run.query(GET_BUILD_NAMES2, SingleResultSetHandlerFactory.<String>newListObjectHandler(), (pageIndex - 1) * pageSize, pageSize); } }
From source file:com.pinterest.deployservice.db.DBConfigHistoryDAOImpl.java
@Override public List<ConfigHistoryBean> getByConfigId(String configId, int pageIndex, int pageSize) throws Exception { QueryRunner run = new QueryRunner(this.dataSource); long start = (pageIndex - 1) * pageSize; ResultSetHandler<List<ConfigHistoryBean>> h = new BeanListHandler<ConfigHistoryBean>( ConfigHistoryBean.class); return run.query(GET_ALL_BY_CONFIG_ID, h, configId, start, pageSize); }
From source file:com.pinterest.arcee.db.DBHealthCheckDAOImpl.java
@Override public List<HealthCheckBean> getHealthChecksByGroup(String groupName, int pageIndex, int pageSize) throws Exception { QueryRunner run = new QueryRunner(this.dataSource); long start = (pageIndex - 1) * pageSize; ResultSetHandler<List<HealthCheckBean>> h = new BeanListHandler<>(HealthCheckBean.class); return run.query(GET_HEALTH_CHECK_BY_GROUP, h, groupName, start, pageSize); }
From source file:io.apiman.gateway.engine.jdbc.JdbcRegistry.java
/** * Gets an api from the DB./*from ww w.ja v a2 s . c om*/ * @param organizationId * @param apiId * @param apiVersion * @throws SQLException */ protected Api getApiInternal(String organizationId, String apiId, String apiVersion) throws SQLException { QueryRunner run = new QueryRunner(ds); return run.query("SELECT bean FROM gw_apis WHERE org_id = ? AND id = ? AND version = ?", //$NON-NLS-1$ Handlers.API_HANDLER, organizationId, apiId, apiVersion); }
From source file:net.gcolin.simplerepo.search.SearchController.java
public void add(final Repository repository, File pomFile, Model model) throws IOException { SearchResult result = buildResult(repository.getName(), pomFile, model); try {/*from w w w . j a v a 2 s . c om*/ Connection connection = null; try { connection = datasource.getConnection(); connection.setAutoCommit(false); QueryRunner run = new QueryRunner(); Long artifactIdx = run.query(connection, "select id from artifact where groupId=? and artifactId=?", getLong, result.getGroupId(), result.getArtifactId()); if (artifactIdx == null) { artifactIdx = run.query(connection, "select artifact from artifactindex", getLong); run.update(connection, "update artifactindex set artifact=?", artifactIdx + 1); run.update(connection, "insert into artifact (id,groupId,artifactId) VALUES (?,?,?)", artifactIdx, result.getGroupId(), result.getArtifactId()); } Long versionId = run.query(connection, "select version from artifactindex", getLong); run.update(connection, "update artifactindex set version=?", versionId + 1); run.update(connection, "insert into artifactversion(artifact_id,id,version,reponame) VALUES (?,?,?,?)", artifactIdx, versionId, result.getVersion(), result.getRepoName()); for (ResultType res : result.getTypes()) { run.update(connection, "insert into artifacttype(version_id,packaging,classifier) VALUES (?,?,?)", versionId, res.getName(), res.getClassifier()); } connection.commit(); } catch (SQLException ex) { connection.rollback(); throw ex; } finally { DbUtils.close(connection); } } catch (SQLException ex) { logger.log(Level.SEVERE, null, ex); throw new IOException(ex); } }
From source file:azkaban.project.JdbcProjectLoader.java
@Override public Flow fetchFlow(Project project, String flowId) throws ProjectManagerException { QueryRunner runner = createQueryRunner(); ProjectFlowsResultHandler handler = new ProjectFlowsResultHandler(); try {/*from w ww . java2s .c om*/ List<Flow> flows = runner.query(ProjectFlowsResultHandler.SELECT_PROJECT_FLOW, handler, project.getId(), project.getVersion(), flowId); if (flows.isEmpty()) { return null; } else { return flows.get(0); } } catch (SQLException e) { throw new ProjectManagerException("Error fetching flow " + flowId, e); } }
From source file:azkaban.executor.JdbcExecutorLoader.java
@Override public ExecutableJobInfo fetchJobInfo(int execId, String jobId, int attempts) throws ExecutorManagerException { QueryRunner runner = createQueryRunner(); try {//from w ww .j a v a2 s .c om List<ExecutableJobInfo> info = runner.query(FetchExecutableJobHandler.FETCH_EXECUTABLE_NODE, new FetchExecutableJobHandler(), execId, jobId, attempts); if (info == null || info.isEmpty()) { return null; } return info.get(0); } catch (SQLException e) { throw new ExecutorManagerException("Error querying job info " + jobId, e); } }
From source file:azkaban.project.JdbcProjectLoader.java
@Override public Props fetchProjectProperty(Project project, String propsName) throws ProjectManagerException { QueryRunner runner = createQueryRunner(); ProjectPropertiesResultsHandler handler = new ProjectPropertiesResultsHandler(); try {//from w w w. j av a 2 s . c o m List<Pair<String, Props>> properties = runner.query( ProjectPropertiesResultsHandler.SELECT_PROJECT_PROPERTY, handler, project.getId(), project.getVersion(), propsName); if (properties == null || properties.isEmpty()) { return null; } return properties.get(0).getSecond(); } catch (SQLException e) { throw new ProjectManagerException("Error fetching property " + propsName, e); } }