use of org.jooq.impl.CallbackExecuteListener 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 -> {
ctx.data("time", System.nanoTime());
}).onEnd(ctx -> {
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();
}
Aggregations