Source:
public List<QueryHandle> findFinishedQueries(String state, String user, String queryName) throws GrillException { boolean addFilter = StringUtils.isNotBlank(state) || StringUtils.isNotBlank(user) || StringUtils.isNotBlank(queryName); StringBuilder builder = new StringBuilder("SELECT handle FROM finished_queries"); List<Object> params = null; if (addFilter) { builder.append(" WHERE "); List<String> filters = new ArrayList<String>(3); params = new ArrayList<Object>(3); if (StringUtils.isNotBlank(state)) { filters.add("state=?"); params.add(state); } if (StringUtils.isNotBlank(user)) { filters.add("submitter=?"); params.add(user); } if (StringUtils.isNotBlank(queryName)) { filters.add("queryname like '%?%'"); params.add(queryName); } builder.append(StringUtils.join(filters, " AND ")); } ResultSetHandler<List<QueryHandle>> resultSetHandler = new ResultSetHandler<List<QueryHandle>>() { @Override public List<QueryHandle> handle(ResultSet resultSet) throws SQLException { List<QueryHandle> queryHandleList = new ArrayList<QueryHandle>(); while (resultSet.next()) { String handle = resultSet.getString(1); try { queryHandleList.add(QueryHandle.fromString(handle)); } catch (IllegalArgumentException exc) { LOG.warn("Warning invalid query handle found in DB " + handle); } } return queryHandleList; } }; QueryRunner runner = new QueryRunner(ds); String query = builder.toString(); try { if(addFilter) { return runner.query(query, resultSetHandler, params.toArray()); } else { return runner.query(query, resultSetHandler); } } catch (SQLException e) { throw new GrillException(e); } }

Target:
public List<QueryHandle> findFinishedQueries(String state, String user, String queryName) throws GrillException { boolean addFilter = StringUtils.isNotBlank(state) || StringUtils.isNotBlank(user) || StringUtils.isNotBlank(queryName); StringBuilder builder = new StringBuilder("SELECT handle FROM finished_queries"); List<Object> params = null; if (addFilter) { builder.append(" WHERE "); List<String> filters = new ArrayList<String>(3); params = new ArrayList<Object>(3); if (StringUtils.isNotBlank(state)) { filters.add("status=?"); params.add(state); } if (StringUtils.isNotBlank(user)) { filters.add("submitter=?"); params.add(user); } if (StringUtils.isNotBlank(queryName)) { filters.add("queryname like ?"); params.add("%" + queryName + "%"); } builder.append(StringUtils.join(filters, " AND ")); } ResultSetHandler<List<QueryHandle>> resultSetHandler = new ResultSetHandler<List<QueryHandle>>() { @Override public List<QueryHandle> handle(ResultSet resultSet) throws SQLException { List<QueryHandle> queryHandleList = new ArrayList<QueryHandle>(); while (resultSet.next()) { String handle = resultSet.getString(1); try { queryHandleList.add(QueryHandle.fromString(handle)); } catch (IllegalArgumentException exc) { LOG.warn("Warning invalid query handle found in DB " + handle); } } return queryHandleList; } }; QueryRunner runner = new QueryRunner(ds); String query = builder.toString(); try { if (addFilter) { return runner.query(query, resultSetHandler, params.toArray()); } else { return runner.query(query, resultSetHandler); } } catch (SQLException e) { throw new GrillException(e); } }