use of org.jooq.ExecuteListener in project jOOQ by jOOQ.
the class BatchMultiple method execute.
static int[] execute(final Configuration configuration, final Query[] queries) {
ExecuteContext ctx = new DefaultExecuteContext(configuration, queries);
ExecuteListener listener = new ExecuteListeners(ctx);
Connection connection = ctx.connection();
try {
ctx.statement(new SettingsEnabledPreparedStatement(connection));
String[] batchSQL = ctx.batchSQL();
for (int i = 0; i < queries.length; i++) {
listener.renderStart(ctx);
batchSQL[i] = DSL.using(configuration).renderInlined(queries[i]);
listener.renderEnd(ctx);
}
for (String sql : batchSQL) {
ctx.sql(sql);
listener.prepareStart(ctx);
ctx.statement().addBatch(sql);
listener.prepareEnd(ctx);
ctx.sql(null);
}
listener.executeStart(ctx);
int[] result = ctx.statement().executeBatch();
int[] batchRows = ctx.batchRows();
for (int i = 0; i < batchRows.length && i < result.length; i++) batchRows[i] = result[i];
listener.executeEnd(ctx);
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 {
Tools.safeClose(listener, ctx);
}
}
use of org.jooq.ExecuteListener in project jOOQ by jOOQ.
the class BatchSingle method executePrepared.
private final int[] executePrepared() {
ExecuteContext ctx = new DefaultExecuteContext(configuration, new Query[] { query });
ExecuteListener listener = new ExecuteListeners(ctx);
Connection connection = ctx.connection();
// [#1371] fetch bind variables to restore them again, later
// [#3940] Don't include inlined bind variables
// [#4062] Make sure we collect also repeated named parameters
ParamCollector collector = new ParamCollector(configuration, false);
collector.visit(query);
List<Param<?>> params = new ArrayList<Param<?>>();
for (Entry<String, Param<?>> entry : collector.resultList) params.add(entry.getValue());
DataType<?>[] paramTypes = dataTypes(params.toArray(EMPTY_FIELD));
try {
listener.renderStart(ctx);
// [#1520] TODO: Should the number of bind values be checked, here?
ctx.sql(create.render(query));
listener.renderEnd(ctx);
listener.prepareStart(ctx);
ctx.statement(connection.prepareStatement(ctx.sql()));
listener.prepareEnd(ctx);
for (Object[] bindValues : allBindValues) {
listener.bindStart(ctx);
// [#1371] [#2139] Don't bind variables directly onto statement, bind them through the collected params
// list to preserve type information
// [#3547] The original query may have no Params specified - e.g. when it was constructed with
// plain SQL. In that case, infer the bind value type directly from the bind value
visitAll(new DefaultBindContext(configuration, ctx.statement()), (paramTypes.length > 0) ? fields(bindValues, paramTypes) : fields(bindValues));
listener.bindEnd(ctx);
ctx.statement().addBatch();
}
listener.executeStart(ctx);
int[] result = ctx.statement().executeBatch();
int[] batchRows = ctx.batchRows();
for (int i = 0; i < batchRows.length && i < result.length; i++) batchRows[i] = result[i];
listener.executeEnd(ctx);
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 {
Tools.safeClose(listener, ctx);
}
}
use of org.jooq.ExecuteListener in project jOOQ by jOOQ.
the class AbstractRoutine method executeCallableStatement.
private final int executeCallableStatement() {
ExecuteContext ctx = new DefaultExecuteContext(configuration, this);
ExecuteListener listener = new ExecuteListeners(ctx);
try {
Connection connection = ctx.connection();
listener.renderStart(ctx);
// [#1520] TODO: Should the number of bind values be checked, here?
ctx.sql(create(configuration).render(this));
listener.renderEnd(ctx);
listener.prepareStart(ctx);
ctx.statement(connection.prepareCall(ctx.sql()));
// [#1856] TODO: Add Statement flags like timeout here
listener.prepareEnd(ctx);
listener.bindStart(ctx);
using(configuration).bindContext(ctx.statement()).visit(this);
registerOutParameters(ctx);
listener.bindEnd(ctx);
execute0(ctx, listener);
// http://tracker.firebirdsql.org/browse/JDBC-350
if (ctx.family() != FIREBIRD)
Tools.consumeResultSets(ctx, listener, results, null);
listener.outStart(ctx);
fetchOutParameters(ctx);
listener.outEnd(ctx);
return 0;
}// [#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 {
Tools.safeClose(listener, ctx);
}
}
Aggregations