From 230fbe3acff54a3316957d1b2f4697a327b1044c Mon Sep 17 00:00:00 2001 From: lukaseder Date: Tue, 9 Feb 2016 14:43:03 +0100 Subject: [PATCH] [#5072] Add default implementations for all SPIs, accepting functional event handlers --- .../section4/Example_4_4_ExecuteListener.java | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/jOOQ-examples/jOOQ-academy/src/test/java/org/jooq/academy/section4/Example_4_4_ExecuteListener.java b/jOOQ-examples/jOOQ-academy/src/test/java/org/jooq/academy/section4/Example_4_4_ExecuteListener.java index 16a324de44..369983abda 100644 --- a/jOOQ-examples/jOOQ-academy/src/test/java/org/jooq/academy/section4/Example_4_4_ExecuteListener.java +++ b/jOOQ-examples/jOOQ-academy/src/test/java/org/jooq/academy/section4/Example_4_4_ExecuteListener.java @@ -43,43 +43,35 @@ package org.jooq.academy.section4; import static org.jooq.academy.tools.Tools.connection; import static org.jooq.example.db.h2.Tables.AUTHOR; -import org.jooq.ExecuteContext; import org.jooq.ExecuteListener; import org.jooq.SQLDialect; import org.jooq.academy.tools.Tools; +import org.jooq.impl.CallbackExecuteListener; import org.jooq.impl.DSL; import org.jooq.impl.DefaultConfiguration; import org.jooq.impl.DefaultConnectionProvider; -import org.jooq.impl.DefaultExecuteListener; import org.jooq.impl.DefaultExecuteListenerProvider; import org.junit.Test; -@SuppressWarnings("serial") public class Example_4_4_ExecuteListener { @Test public void run() { Tools.title("Displaying execution time using a custom ExecuteListener"); - ExecuteListener listener = new DefaultExecuteListener() { - - @Override - public void start(ExecuteContext ctx) { + ExecuteListener listener = new CallbackExecuteListener() + .onStart(ctx -> { // Register the start time to the current context ctx.data("time", System.nanoTime()); - } - - @Override - public void end(ExecuteContext ctx) { - + }) + .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)