Search in sources :

Example 11 with ExecuteListener

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();
}
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)

Example 12 with ExecuteListener

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);
}
Also used : ExecuteListener(org.jooq.ExecuteListener)

Example 13 with ExecuteListener

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++;
}
Also used : ExecuteListener(org.jooq.ExecuteListener)

Example 14 with ExecuteListener

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);
}
Also used : ExecuteContext(org.jooq.ExecuteContext) ExecuteListener(org.jooq.ExecuteListener)

Aggregations

ExecuteListener (org.jooq.ExecuteListener)14 ExecuteContext (org.jooq.ExecuteContext)8 SQLException (java.sql.SQLException)4 ControlFlowSignal (org.jooq.exception.ControlFlowSignal)4 Connection (java.sql.Connection)3 DSLContext (org.jooq.DSLContext)3 DefaultExecuteListener (org.jooq.impl.DefaultExecuteListener)3 DefaultExecuteListenerProvider (org.jooq.impl.DefaultExecuteListenerProvider)3 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 Configuration (org.jooq.Configuration)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 PersonRecord (com.khartec.waltz.schema.tables.records.PersonRecord)1 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 PersonRecord (org.finos.waltz.schema.tables.records.PersonRecord)1 ExecuteListenerProvider (org.jooq.ExecuteListenerProvider)1 Param (org.jooq.Param)1