/** * Execute the command that's defined by the subclass following * the Command pattern. Specialized parameters are held in the command instances. * * @return ResultSet from executing a query * @throws SQLException if a database error occurs */ protected final ResultSet execute() throws SQLException { connection = createConnection(); setInternalConnection(connection); statement = null; try { // The variation in the pattern is isolated ResultSet result = runQuery(connection); assert (null != statement); return result; } catch (SQLException e) { LOG.warning("Failed to execute: " + sql + " because: " + e.getMessage()); closeResources(); connection = null; statement = null; throw e; } }
return asList(sql, command.execute(), offset, maxRows, metaClosure); } finally { command.closeResources();
AbstractQueryCommand command = createPreparedQueryCommand(sql, params); command.setMaxRows(offset + maxRows); try { return asList(sql, command.execute(), offset, maxRows, metaClosure); } finally { command.closeResources();
AbstractQueryCommand command = createQueryCommand(sql); command.setMaxRows(offset + maxRows); ResultSet rs = null; try { rs = command.execute(); List<GroovyRowResult> result = asList(sql, rs, offset, maxRows, metaClosure); rs = null; return result; } finally { command.closeResources(rs);
ResultSet rs = null; try { rs = command.execute(); List<GroovyRowResult> result = asList(sql, rs, offset, maxRows, metaClosure); rs = null; return result; } finally { command.closeResources(rs);
AbstractQueryCommand command = createPreparedQueryCommand(sql, params); try { return asList(sql, command.execute(), metaClosure); command.closeResources();
/** * Performs the given SQL query and return the rows of the result set. * In addition, the <code>metaClosure</code> will be called once passing in the * <code>ResultSetMetaData</code> as argument. * <p/> * Example usage: * <pre> * def printNumCols = { meta -> println "Found $meta.columnCount columns" } * def ans = sql.rows("select * from PERSON", printNumCols) * println "Found ${ans.size()} rows" * </pre> * * @param sql the SQL statement * @param metaClosure called with meta data of the ResultSet * @return a list of GroovyRowResult objects * @throws SQLException if a database access error occurs */ public List<GroovyRowResult> rows(String sql, Closure metaClosure) throws SQLException { AbstractQueryCommand command = createQueryCommand(sql); ResultSet rs = null; try { rs = command.execute(); List<GroovyRowResult> result = asList(sql, rs, metaClosure); rs = null; return result; } finally { command.closeResources(rs); } }
/** * Execute the command that's defined by the subclass following * the Command pattern. Specialized parameters are held in the command instances. * * @return ResultSet from executing a query * @throws SQLException if a database error occurs */ final ResultSet execute() throws SQLException { connection = createConnection(); setInternalConnection(connection); statement = null; try { log.fine(sql); // The variation in the pattern is isolated ResultSet result = runQuery(connection); assert (null != statement); return result; } catch (SQLException e) { log.log(Level.FINE, "Failed to execute: " + sql, e); closeResources(); connection = null; statement = null; throw e; } }
/** * Execute the command that's defined by the subclass following * the Command pattern. Specialized parameters are held in the command instances. * * @return ResultSet from executing a query * @throws SQLException if a database error occurs */ protected final ResultSet execute() throws SQLException { connection = createConnection(); setInternalConnection(connection); statement = null; try { // The variation in the pattern is isolated ResultSet result = runQuery(connection); assert (null != statement); return result; } catch (SQLException e) { LOG.warning("Failed to execute: " + sql + " because: " + e.getMessage()); closeResources(); connection = null; statement = null; throw e; } }
/** * Useful helper method which handles resource management when executing a * query which returns a result set. * Derived classes of Sql can override "createQueryCommand" and then call * this method to access the ResultSet returned from the provided query * or alternatively can use the higher-level method of Sql which return * result sets which are funnelled through this method, e.g. eachRow, query. * * @param sql query to execute * @return the resulting ResultSet * @throws SQLException if a database error occurs */ protected final ResultSet executeQuery(String sql) throws SQLException { AbstractQueryCommand command = createQueryCommand(sql); ResultSet rs = null; try { rs = command.execute(); } finally { command.closeResources(); } return rs; }
/** * Useful helper method which handles resource management when executing a * query which returns a result set. * Derived classes of Sql can override "createQueryCommand" and then call * this method to access the ResultSet returned from the provided query * or alternatively can use the higher-level method of Sql which return * result sets which are funnelled through this method, e.g. eachRow, query. * * @param sql query to execute * @return the resulting ResultSet * @throws SQLException if a database error occurs */ protected final ResultSet executeQuery(String sql) throws SQLException { AbstractQueryCommand command = createQueryCommand(sql); ResultSet rs = null; try { rs = command.execute(); } finally { command.closeResources(); } return rs; }
/** * Useful helper method which handles resource management when executing a * prepared query which returns a result set. * Derived classes of Sql can override "createPreparedQueryCommand" and then * call this method to access the ResultSet returned from the provided query. * * @param sql query to execute * @param params parameters matching question mark placeholders in the query * @return the resulting ResultSet * @throws SQLException if a database error occurs */ protected final ResultSet executePreparedQuery(String sql, List<Object> params) throws SQLException { AbstractQueryCommand command = createPreparedQueryCommand(sql, params); ResultSet rs = null; try { rs = command.execute(); } finally { command.closeResources(); } return rs; }
/** * Execute the command that's defined by the subclass following * the Command pattern. Specialized parameters are held in the command instances. * * @return ResultSet from executing a query * @throws SQLException if a database error occurs */ protected final ResultSet execute() throws SQLException { connection = createConnection(); setInternalConnection(connection); statement = null; try { // The variation in the pattern is isolated ResultSet result = runQuery(connection); assert (null != statement); return result; } catch (SQLException e) { LOG.warning("Failed to execute: " + sql + " because: " + e.getMessage()); closeResources(); connection = null; statement = null; throw e; } }
/** * Overridden to fix passing the resultset to the closure */ @Override public void eachRow(String sql, Closure metaClosure, Closure rowClosure) throws SQLException { AbstractQueryCommand command = createQueryCommand(sql); ResultSet results = null; try { results = command.execute(); if (metaClosure != null) metaClosure.call(results.getMetaData()); GroovyResultSet groovyRS = new GroovyResultSetProxy(results).getImpl(); while (groovyRS.next()) { rowClosure.call(groovyRS); } } catch (SQLException e) { LOG.warning("Failed to execute: " + sql + " because: " + e.getMessage()); throw e; } finally { command.closeResources(); } }
/** * Useful helper method which handles resource management when executing a * prepared query which returns a result set. * Derived classes of Sql can override "createPreparedQueryCommand" and then * call this method to access the ResultSet returned from the provided query. * * @param sql query to execute * @param params parameters matching question mark placeholders in the query * @return the resulting ResultSet * @throws SQLException if a database error occurs */ protected final ResultSet executePreparedQuery(String sql, List<Object> params) throws SQLException { AbstractQueryCommand command = createPreparedQueryCommand(sql, params); ResultSet rs = null; try { rs = command.execute(); } finally { command.closeResources(); } return rs; }
/** * Hook to allow derived classes to access ResultSet returned from query. * * @param sql query to execute * @param params parameters matching question mark placeholders in the query * @return the resulting ResultSet * @throws SQLException if a database error occurs */ protected final ResultSet executePreparedQuery(String sql, List<Object> params) throws SQLException { AbstractQueryCommand command = createPreparedQueryCommand(sql, params); ResultSet rs = null; try { rs = command.execute(); } finally { command.closeResources(); } return rs; }
/** * Hook to allow derived classes to access ResultSet returned from query. * * @param sql query to execute * @return the resulting ResultSet * @throws SQLException if a database error occurs */ protected final ResultSet executeQuery(String sql) throws SQLException { AbstractQueryCommand command = createQueryCommand(sql); ResultSet rs = null; try { rs = command.execute(); } finally { command.closeResources(); } return rs; }