@Override protected void configure(Statement statement) { super.configure(statement); try { statement.setMaxRows(maxRows); } catch (SQLException e) { LOG.log(Level.WARNING, "Caught exception setting max rows: " + e, e); } plan = null; annotations = null; debugLog = null; warnings = null; }
private Statement getStatement(Connection connection, String sql) throws SQLException { LOG.fine(sql); Statement stmt = getAbstractStatement(new CreateStatementCommand(), connection, sql); configure(stmt); return stmt; }
private Statement getStatement(Connection connection, String sql) throws SQLException { LOG.fine(sql); Statement stmt = getAbstractStatement(new CreateStatementCommand(), connection, sql); configure(stmt); return stmt; }
private Statement getStatement(Connection connection, String sql) throws SQLException { Statement stmt = getAbstractStatement(new CreateStatementCommand(), connection, sql); configure(stmt); return stmt; }
private CallableStatement getCallableStatement(Connection connection, String sql, List<Object> params) throws SQLException { LOG.fine(sql + " | " + params); CallableStatement statement = (CallableStatement) getAbstractStatement(new CreateCallableStatementCommand(), connection, sql); setParameters(params, statement); configure(statement); return statement; }
/** * Performs the given SQL query with parameters calling the closure with the * result set. * * @param sql the sql statement * @param params a list of parameters * @param closure called for each row with a GroovyResultSet * @throws SQLException if a database access error occurs */ public void query(String sql, List params, Closure closure) throws SQLException { Connection connection = createConnection(); PreparedStatement statement = null; ResultSet results = null; try { log.fine(sql); statement = connection.prepareStatement(sql); setParameters(params, statement); configure(statement); results = statement.executeQuery(); closure.call(results); } catch (SQLException e) { log.log(Level.FINE, "Failed to execute: " + sql, e); throw e; } finally { closeResources(connection, statement, results); } }
/** * Performs the given SQL query calling the closure with the result set. * * @param sql the sql statement * @param closure called for each row with a GroovyResultSet * @throws SQLException if a database access error occurs */ public void query(String sql, Closure closure) throws SQLException { Connection connection = createConnection(); Statement statement = getStatement(connection, sql); configure(statement); ResultSet results = null; try { log.fine(sql); results = statement.executeQuery(sql); closure.call(results); } catch (SQLException e) { log.log(Level.FINE, "Failed to execute: " + sql, e); throw e; } finally { closeResources(connection, statement, results); } }
/** * Performs the given SQL query calling the closure with the result set. * * @param sql the sql statement * @param closure called for each row with a GroovyResultSet * @throws SQLException if a database access error occurs */ public void query(String sql, Closure closure) throws SQLException { Connection connection = createConnection(); Statement statement = createConnection(connection); configure(statement); ResultSet results = null; try { log.fine(sql); results = statement.executeQuery(sql); closure.call(results); } catch (SQLException e) { log.log(Level.FINE, "Failed to execute: " + sql, e); throw e; } finally { closeResources(connection, statement, results); } }
/** * Performs the given SQL query and return the rows of the result set. * * @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 rows(String sql, Closure metaClosure) throws SQLException { List results = new ArrayList(); Connection connection = createConnection(); Statement statement = createConnection(connection); configure(statement); ResultSet rs = null; try { log.fine(sql); rs = statement.executeQuery(sql); if (metaClosure != null) metaClosure.call(rs.getMetaData()); while (rs.next()) { results.add(DefaultGroovyMethods.toRowResult(rs)); } return (results); } catch (SQLException e) { log.log(Level.FINE, "Failed to execute: " + sql, e); throw e; } finally { closeResources(connection, statement, rs); } }
/** * Executes the given SQL update with parameters. * * @param sql the SQL statement * @param params a list of parameters * @return the number of rows updated or 0 for SQL statements that return nothing * @throws SQLException if a database access error occurs */ public int executeUpdate(String sql, List params) throws SQLException { Connection connection = createConnection(); PreparedStatement statement = null; try { log.fine(sql); statement = connection.prepareStatement(sql); setParameters(params, statement); configure(statement); this.updateCount = statement.executeUpdate(); return this.updateCount; } catch (SQLException e) { log.log(Level.FINE, "Failed to execute: " + sql, e); throw e; } finally { closeResources(connection, statement); } }
/** * Executes the given SQL update. * * @param sql the SQL statement * @return the number of rows updated or 0 for SQL statements that return nothing * @throws SQLException if a database access error occurs */ public int executeUpdate(String sql) throws SQLException { Connection connection = createConnection(); Statement statement = null; try { log.fine(sql); statement = createConnection(connection); configure(statement); this.updateCount = statement.executeUpdate(sql); return this.updateCount; } catch (SQLException e) { log.log(Level.FINE, "Failed to execute: " + sql, e); throw e; } finally { closeResources(connection, statement); } }
/** * Executes the given SQL update. * * @param sql the SQL to execute * @return the number of rows updated or 0 for SQL statements that return nothing * @throws SQLException if a database access error occurs */ public int executeUpdate(String sql) throws SQLException { Connection connection = createConnection(); Statement statement = null; try { log.fine(sql); statement = getStatement(connection, sql); configure(statement); this.updateCount = statement.executeUpdate(sql); return this.updateCount; } catch (SQLException e) { log.log(Level.FINE, "Failed to execute: " + sql, e); throw e; } finally { closeResources(connection, statement); } }
private PreparedStatement getPreparedStatement(Connection connection, String sql, List<Object> params, int returnGeneratedKeys) throws SQLException { PreparedStatement statement = (PreparedStatement) getAbstractStatement(new CreatePreparedStatementCommand(returnGeneratedKeys), connection, sql); setParameters(params, statement); configure(statement); return statement; }
/** * Performs a stored procedure call with the given parameters. * * @param sql the SQL statement * @param params a list of parameters * @return the number of rows updated or 0 for SQL statements that return nothing * @throws SQLException if a database access error occurs */ public int call(String sql, List params) throws Exception { Connection connection = createConnection(); CallableStatement statement = connection.prepareCall(sql); try { log.fine(sql); setParameters(params, statement); configure(statement); return statement.executeUpdate(); } catch (SQLException e) { log.log(Level.FINE, "Failed to execute: " + sql, e); throw e; } finally { closeResources(connection, statement); } }
/** * Performs a stored procedure call with the given parameters. * * @param sql the SQL statement * @param params a list of parameters * @return the number of rows updated or 0 for SQL statements that return nothing * @throws SQLException if a database access error occurs */ public int call(String sql, List params) throws Exception { Connection connection = createConnection(); CallableStatement statement = connection.prepareCall(sql); try { log.fine(sql); setParameters(params, statement); configure(statement); return statement.executeUpdate(); } catch (SQLException e) { log.log(Level.FINE, "Failed to execute: " + sql, e); throw e; } finally { closeResources(connection, statement); } }
/** * Executes the given SQL update with parameters. * * @param sql the SQL statement * @param params a list of parameters * @return the number of rows updated or 0 for SQL statements that return nothing * @throws SQLException if a database access error occurs */ public int executeUpdate(String sql, List params) throws SQLException { Connection connection = createConnection(); PreparedStatement statement = null; try { log.fine(sql); statement = getPreparedStatement(connection, sql); setParameters(params, statement); configure(statement); this.updateCount = statement.executeUpdate(); return this.updateCount; } catch (SQLException e) { log.log(Level.FINE, "Failed to execute: " + sql, e); throw e; } finally { closeResources(connection, statement); } }
/** * Performs the given SQL query calling closures for metadata and each row * * @param sql the sql statement * @param metaClosure called for meta data (only once after sql execution) * @param rowClosure called for each row with a GroovyResultSet * @throws SQLException if a database access error occurs */ public void eachRow(String sql, Closure metaClosure, Closure rowClosure) throws SQLException { Connection connection = createConnection(); Statement statement = createConnection(connection); configure(statement); ResultSet results = null; try { log.fine(sql); results = statement.executeQuery(sql); if (metaClosure != null) metaClosure.call(results.getMetaData()); GroovyResultSet groovyRS = new GroovyResultSetProxy(results).getImpl(); while (groovyRS.next()) { rowClosure.call(groovyRS); } } catch (SQLException e) { log.log(Level.FINE, "Failed to execute: " + sql, e); throw e; } finally { closeResources(connection, statement, results); } }
/** * Performs the given SQL query calling closures for metadata and each row * * @param sql the sql statement * @param metaClosure called for meta data (only once after sql execution) * @param rowClosure called for each row with a GroovyResultSet * @throws SQLException if a database access error occurs */ public void eachRow(String sql, Closure metaClosure, Closure rowClosure) throws SQLException { Connection connection = createConnection(); Statement statement = getStatement(connection, sql); configure(statement); ResultSet results = null; try { log.fine(sql); results = statement.executeQuery(sql); if (metaClosure != null) metaClosure.call(results.getMetaData()); GroovyResultSet groovyRS = new GroovyResultSetProxy(results).getImpl(); while (groovyRS.next()) { rowClosure.call(groovyRS); } } catch (SQLException e) { log.log(Level.FINE, "Failed to execute: " + sql, e); throw e; } finally { closeResources(connection, statement, results); } }
private PreparedStatement getPreparedStatement(Connection connection, String sql, List<Object> params, int returnGeneratedKeys) throws SQLException { SqlWithParams updated = checkForNamedParams(sql, params); LOG.fine(updated.getSql() + " | " + updated.getParams()); PreparedStatement statement = (PreparedStatement) getAbstractStatement(new CreatePreparedStatementCommand(returnGeneratedKeys), connection, updated.getSql()); setParameters(updated.getParams(), statement); configure(statement); return statement; }
private PreparedStatement getPreparedStatement(Connection connection, String sql, List<Object> params, int returnGeneratedKeys) throws SQLException { SqlWithParams updated = checkForNamedParams(sql, params); LOG.fine(updated.getSql() + " | " + updated.getParams()); PreparedStatement statement = (PreparedStatement) getAbstractStatement(new CreatePreparedStatementCommand(returnGeneratedKeys), connection, updated.getSql()); setParameters(updated.getParams(), statement); configure(statement); return statement; }