// [#1191] The following triggers a start event on all listeners.
// This may be used to provide jOOQ with a JDBC connection,
// in case this Query / Configuration was previously
// deserialised
DefaultExecuteContext ctx = new DefaultExecuteContext(c, this);
ExecuteListener listener = new ExecuteListeners(ctx);
int result = 0;
try {
// [#385] If a statement was previously kept open
if (keepStatement() && statement != null) {
ctx.sql(sql);
ctx.statement(statement);
// [#3191] Pre-initialise the ExecuteContext with a previous connection, if available.
ctx.connection(c.connectionProvider(), statement.getConnection());
}
// [#385] First time statement preparing
else {
listener.renderStart(ctx);
ctx.sql(getSQL0(ctx));
listener.renderEnd(ctx);
sql = ctx.sql();
// [#3234] Defer initialising of a connection until the prepare step
// This optimises unnecessary ConnectionProvider.acquire() calls when
// ControlFlowSignals are thrown
if (ctx.connection() == null) {
throw new DetachedException("Cannot execute query. No Connection configured");
}
listener.prepareStart(ctx);
prepare(ctx);
listener.prepareEnd(ctx);
statement = ctx.statement();
}
// [#1856] Set the query timeout onto the Statement
if (timeout != 0) {
ctx.statement().setQueryTimeout(timeout);
}
if (
// [#1145] Bind variables only for true prepared statements
// [#2414] Even if parameters are inlined here, child
// QueryParts may override this behaviour!
executePreparedStatements(c.settings()) &&
// [#1520] Renderers may enforce static statements, too
!Boolean.TRUE.equals(ctx.data(DATA_FORCE_STATIC_STATEMENT))) {
listener.bindStart(ctx);
using(c).bindContext(ctx.statement()).visit(this);
listener.bindEnd(ctx);
}
result = execute(ctx, listener);
return result;
}
// [#3427] ControlFlowSignals must not be passed on to ExecuteListners
catch (ControlFlowSignal e) {
throw e;
}
catch (RuntimeException e) {
ctx.exception(e);
listener.exception(ctx);
throw ctx.exception();
}
catch (SQLException e) {
ctx.sqlException(e);
listener.exception(ctx);
throw ctx.exception();
}
finally {
// [#2385] Successful fetchLazy() needs to keep open resources