/** * Default implementation for query execution using a prepared statement. * Subclasses may override this method. */ protected int execute(ExecuteContext ctx, ExecuteListener listener) throws SQLException { int result = 0; listener.executeStart(ctx); if (!ctx.statement().execute()) { result = ctx.statement().getUpdateCount(); ctx.rows(result); } listener.executeEnd(ctx); return result; }
/** * Default implementation for preparing a statement. Subclasses may override * this method. */ protected void prepare(ExecuteContext ctx) throws SQLException { ctx.statement(ctx.connection().prepareStatement(ctx.sql())); }
/** * Default implementation for preparing a statement. Subclasses may override * this method. */ protected void prepare(ExecuteContext ctx) throws SQLException { ctx.statement(ctx.connection().prepareStatement(ctx.sql())); }
private final <U> void fetchOutParameter(ExecuteContext ctx, Parameter<U> parameter) throws SQLException { { DefaultBindingGetStatementContext<U> out = new DefaultBindingGetStatementContext<U>( ctx.configuration(), ctx.data(), (CallableStatement) ctx.statement(), resultIndexes.get(parameter) ); parameter.getBinding().get(out); outValues.put(parameter, out.value()); } }
ctx.statement(ctx.connection().prepareStatement(ctx.sql(), type, concurrency)); ctx.statement(ctx.connection().prepareStatement(ctx.sql(), type, concurrency, resultSetHoldability)); ctx.statement(ctx.connection().prepareStatement(ctx.sql(), TYPE_SCROLL_SENSITIVE, CONCUR_UPDATABLE)); ctx.statement(ctx.connection().prepareStatement(ctx.sql())); log.debug("Setting fetch size", fetchSize); ctx.statement().setFetchSize(fetchSize); ctx.statement().setMaxRows(maxRows);
/** * Safely close a statement */ static final void safeClose(ExecuteListener listener, ExecuteContext ctx, boolean keepStatement, boolean keepResultSet) { // [#2523] Set JDBC objects to null, to prevent repeated closing JDBCUtils.safeClose(ctx.resultSet()); ctx.resultSet(null); // [#385] Close statements only if not requested to keep open if (!keepStatement) { JDBCUtils.safeClose(ctx.statement()); ctx.statement(null); } // [#1868] [#2373] Terminate ExecuteListener lifecycle, if needed if (keepResultSet) listener.end(ctx); // [#1326] Clean up any potentially remaining temporary lobs DefaultExecuteContext.clean(); }
/** * [#5666] Handle the complexity of each dialect's understanding of * correctly calling {@link Statement#execute()}. */ static final SQLException executeStatementAndGetFirstResultSet(ExecuteContext ctx, int skipUpdateCounts) throws SQLException { PreparedStatement stmt = ctx.statement(); try { if (stmt.execute()) { ctx.resultSet(stmt.getResultSet()); } else { ctx.resultSet(null); ctx.rows(stmt.getUpdateCount()); } return null; } // [#3011] [#3054] [#6390] [#6413] Consume additional exceptions if there are any catch (SQLException e) { if (ctx.settings().getThrowExceptions() != THROW_NONE) { consumeExceptions(ctx.configuration(), ctx.statement(), e); throw e; } else { return e; } } }
ctx.statement(ctx.connection().prepareStatement(ctx.sql(), type, concurrency)); ctx.statement(ctx.connection().prepareStatement(ctx.sql(), type, concurrency, resultSetHoldability)); ctx.statement(ctx.connection().prepareStatement(ctx.sql(), TYPE_SCROLL_SENSITIVE, CONCUR_UPDATABLE)); ctx.statement(ctx.connection().prepareStatement(ctx.sql())); log.debug("Setting fetch size", f); ctx.statement().setFetchSize(f); ctx.statement().setMaxRows(m);
/** * Default implementation for query execution using a prepared statement. * Subclasses may override this method. */ protected int execute(ExecuteContext ctx, ExecuteListener listener) throws SQLException { int result = 0; PreparedStatement stmt = ctx.statement(); try { listener.executeStart(ctx); // [#1829] Statement.execute() is preferred over Statement.executeUpdate(), as // we might be executing plain SQL and returning results. if (!stmt.execute()) { result = stmt.getUpdateCount(); ctx.rows(result); } listener.executeEnd(ctx); return result; } // [#3011] [#3054] [#6390] [#6413] Consume additional exceptions if there are any catch (SQLException e) { consumeExceptions(ctx.configuration(), stmt, e); if (ctx.settings().getThrowExceptions() != THROW_NONE) throw e; else return stmt.getUpdateCount(); } }
private final void registerOutParameters(ExecuteContext ctx) throws SQLException { Configuration c = ctx.configuration(); Map<Object, Object> data = ctx.data(); CallableStatement statement = (CallableStatement) ctx.statement(); // Register all out / inout parameters according to their position // Note that some RDBMS do not support binding by name very well for (Parameter<?> parameter : getParameters()) if (resultParameter(parameter)) registerOutParameter(c, data, statement, parameter); }
@Override public void exception(ExecuteContext ctx) { SQLException ex = ctx.sqlException(); Statement stmt = ctx.statement(); Connection con = ctx.getConnection(); DataSource dataSource = ctx.getDataSource(); JdbcUtils.closeStatement(stmt); ctx.exception(getExceptionTranslator(dataSource).translate("jOOQ", ctx.sql(), ex)); }
/** * [#3076] Consume warnings from a {@link Statement} and notify listeners. */ static final void consumeWarnings(ExecuteContext ctx, ExecuteListener listener) { // [#3558] In some databases (e.g. MySQL), the call to PreparedStatement.getWarnings() issues // a separate SHOW WARNINGS query. Users may want to avoid this query, explicitly if (!Boolean.FALSE.equals(ctx.settings().isFetchWarnings())) { try { ctx.sqlWarning(ctx.statement().getWarnings()); } // [#3741] In MySQL, calling SHOW WARNINGS on open streaming result sets can cause issues. // while this has been resolved, we should expect the above call to cause other issues, too catch (SQLException e) { ctx.sqlWarning(new SQLWarning("Could not fetch SQLWarning", e)); } } if (ctx.sqlWarning() != null) listener.warning(ctx); }
ctx.statement(new SettingsEnabledPreparedStatement(connection)); ctx.sql(batchSQL[i]); listener.prepareStart(ctx); ctx.statement().addBatch(batchSQL[i]); listener.prepareEnd(ctx); int[] result = ctx.statement().executeBatch(); int[] batchRows = ctx.batchRows(); for (int i = 0; i < batchRows.length && i < result.length; i++)