use of org.jooq.ExecuteListener in project jOOQ by jOOQ.
the class Example_4_4_ExecuteListener method run.
@Test
public void run() {
Tools.title("Displaying execution time using a custom ExecuteListener");
ExecuteListener listener = new CallbackExecuteListener().onStart(ctx -> {
// Register the start time to the current context
ctx.data("time", System.nanoTime());
}).onEnd(ctx -> {
// Extract the start time from the current context
Long time = (Long) ctx.data("time");
System.out.println("Execution time : " + ((System.nanoTime() - time) / 1000 / 1000.0) + "ms. Query : " + ctx.sql());
});
DSL.using(new DefaultConfiguration().set(SQLDialect.H2).set(new DefaultConnectionProvider(connection())).set(new DefaultExecuteListenerProvider(listener))).select(AUTHOR.ID).from(AUTHOR).fetch();
}
use of org.jooq.ExecuteListener in project jOOQ by jOOQ.
the class ExecuteListeners method resultEnd.
@Override
public final void resultEnd(ExecuteContext ctx) {
((DefaultExecuteContext) ctx).resultLevel--;
resultStart = false;
for (ExecuteListener listener : listeners[1]) listener.resultEnd(ctx);
if (fetchEnd)
fetchEnd(ctx);
}
use of org.jooq.ExecuteListener in project jOOQ by jOOQ.
the class ExecuteListeners method resultStart.
@Override
public final void resultStart(ExecuteContext ctx) {
resultStart = true;
for (ExecuteListener listener : listeners[0]) listener.resultStart(ctx);
((DefaultExecuteContext) ctx).resultLevel++;
}
use of org.jooq.ExecuteListener in project jOOQ by jOOQ.
the class DefaultDSLContext method fetchLazy.
@Override
public Cursor<Record> fetchLazy(ResultSet rs, Field<?>... fields) {
ExecuteContext ctx = new DefaultExecuteContext(configuration());
ExecuteListener listener = ExecuteListeners.getAndStart(ctx);
ctx.resultSet(rs);
return new CursorImpl<>(ctx, listener, fields, null, false, true);
}
Aggregations