/** * Executes a raw query and returns an instance of {@link RowProcessor}. Use it in the following pattern: * <pre> * Base.find("select first_name, last_name from really_large_table").with(new RowListenerAdapter() { public void onNext(Map row) { ///write your code here Object o1 = row.get("first_name"); Object o2 = row.get("last_name"); } }); </pre> * * @param query raw SQL. * @param params list of parameters if query is parametrized. * @return instance of <code>RowProcessor</code> which has with() method for convenience. */ public RowProcessor find(String query, Object ... params) { //TODO: count ? signs and number of params, throw exception if do not match if(query.indexOf('?') == -1 && params.length != 0) throw new IllegalArgumentException("you passed arguments, but the query does not have placeholders: (?)"); //TODO: cache prepared statements here too PreparedStatement ps; ResultSet rs; try { ps = createStreamingPreparedStatement(query); setParameters(ps, params); rs = ps.executeQuery(); return new RowProcessor(rs, ps); } catch (SQLException e) { throw new DBException(query, params, e); } }
/** * Executes a raw query and calls instance of <code>RowListener</code> with every row found. * Use this method for very large result sets. * * @param sql raw SQL query. * @param listener client listener implementation for processing individual rows. */ public void find(String sql, RowListener listener) { Statement s = null; ResultSet rs = null; try { s = createStreamingStatement(); rs = s.executeQuery(sql); RowProcessor p = new RowProcessor(rs, s); p.with(listener); } catch (SQLException e) { throw new DBException(sql, null, e); } finally { closeQuietly(rs); closeQuietly(s); } }
/** * Executes a raw query and returns an instance of {@link RowProcessor}. Use it in the following pattern: * <pre> * Base.find("select first_name, last_name from really_large_table").with(new RowListenerAdapter() { public void onNext(Map row) { ///write your code here Object o1 = row.get("first_name"); Object o2 = row.get("last_name"); } }); </pre> * * @param query raw SQL. * @param params list of parameters if query is parametrized. * @return instance of <code>RowProcessor</code> which has with() method for convenience. */ public RowProcessor find(String query, Object ... params) { //TODO: count ? signs and number of params, throw exception if do not match if(query.indexOf('?') == -1 && params.length != 0) throw new IllegalArgumentException("you passed arguments, but the query does not have placeholders: (?)"); if(!SELECT_PATTERN.matcher(query).find()) { throw new IllegalArgumentException("query must be 'select' query"); } //TODO: cache prepared statements here too PreparedStatement ps; ResultSet rs; try { ps = createStreamingPreparedStatement(query); setParameters(ps, params); rs = ps.executeQuery(); return new RowProcessor(rs, ps); } catch (SQLException e) { throw new DBException(query, params, e); } }
/** * Executes a raw query and returns an instance of {@link RowProcessor}. Use it in the following pattern: * <pre> * Base.find("select first_name, last_name from really_large_table").with(new RowListenerAdapter() { public void onNext(Map row) { ///write your code here Object o1 = row.get("first_name"); Object o2 = row.get("last_name"); } }); </pre> * * @param query raw SQL. * @param params list of parameters if query is parametrized. * @return instance of <code>RowProcessor</code> which has with() method for convenience. */ public RowProcessor find(String query, Object ... params) { //TODO: count ? signs and number of params, throw exception if do not match if(query.indexOf('?') == -1 && params.length != 0) throw new IllegalArgumentException("you passed arguments, but the query does not have placeholders: (?)"); //TODO: cache prepared statements here too PreparedStatement ps; ResultSet rs; try { ps = createStreamingPreparedStatement(query); setParameters(ps, params); rs = ps.executeQuery(); return new RowProcessor(rs, ps); } catch (SQLException e) { throw new DBException(query, params, e); } }
settings.setProcessor(new RowProcessor() {
/** * Executes a raw query and calls instance of <code>RowListener</code> with every row found. * Use this method for very large result sets. * * @param sql raw SQL query. * @param listener client listener implementation for processing individual rows. */ public void find(String sql, RowListener listener) { Statement s = null; ResultSet rs = null; try { s = createStreamingStatement(); rs = s.executeQuery(sql); RowProcessor p = new RowProcessor(rs, s); p.with(listener); } catch (SQLException e) { throw new DBException(sql, null, e); } finally { closeQuietly(rs); closeQuietly(s); } }
/** * Executes a raw query and calls instance of <code>RowListener</code> with every row found. * Use this method for very large result sets. * * @param sql raw SQL query. * @param listener client listener implementation for processing individual rows. */ public void find(String sql, RowListener listener) { Statement s = null; ResultSet rs = null; try { s = createStreamingStatement(); rs = s.executeQuery(sql); RowProcessor p = new RowProcessor(rs, s); p.with(listener); } catch (SQLException e) { throw new DBException(sql, null, e); } finally { closeQuietly(rs); closeQuietly(s); } }