[#5072] Add default implementations for all SPIs, accepting functional event handlers

This commit is contained in:
lukaseder 2016-02-09 14:43:03 +01:00
parent 70e9396569
commit 230fbe3acf

View File

@ -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)