Search in sources :

Example 1 with CallbackExecuteListener

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();
}
Also used : DSL(org.jooq.impl.DSL) DefaultConfiguration(org.jooq.impl.DefaultConfiguration) CallbackExecuteListener(org.jooq.impl.CallbackExecuteListener) ExecuteListener(org.jooq.ExecuteListener) Tools(org.jooq.academy.tools.Tools) DefaultConnectionProvider(org.jooq.impl.DefaultConnectionProvider) Test(org.junit.Test) SQLDialect(org.jooq.SQLDialect) Tools.connection(org.jooq.academy.tools.Tools.connection) AUTHOR(org.jooq.example.db.h2.Tables.AUTHOR) DefaultExecuteListenerProvider(org.jooq.impl.DefaultExecuteListenerProvider) CallbackExecuteListener(org.jooq.impl.CallbackExecuteListener) DefaultConnectionProvider(org.jooq.impl.DefaultConnectionProvider) DefaultExecuteListenerProvider(org.jooq.impl.DefaultExecuteListenerProvider) DefaultConfiguration(org.jooq.impl.DefaultConfiguration) CallbackExecuteListener(org.jooq.impl.CallbackExecuteListener) ExecuteListener(org.jooq.ExecuteListener) Test(org.junit.Test)

Aggregations

ExecuteListener (org.jooq.ExecuteListener)1 SQLDialect (org.jooq.SQLDialect)1 Tools (org.jooq.academy.tools.Tools)1 Tools.connection (org.jooq.academy.tools.Tools.connection)1 AUTHOR (org.jooq.example.db.h2.Tables.AUTHOR)1 CallbackExecuteListener (org.jooq.impl.CallbackExecuteListener)1 DSL (org.jooq.impl.DSL)1 DefaultConfiguration (org.jooq.impl.DefaultConfiguration)1 DefaultConnectionProvider (org.jooq.impl.DefaultConnectionProvider)1 DefaultExecuteListenerProvider (org.jooq.impl.DefaultExecuteListenerProvider)1 Test (org.junit.Test)1