Search in sources :

Example 6 with DefaultExecuteListenerProvider

use of org.jooq.impl.DefaultExecuteListenerProvider 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 7 with DefaultExecuteListenerProvider

use of org.jooq.impl.DefaultExecuteListenerProvider in project tutorials by eugenp.

the class PersistenceContextIntegrationTest method configuration.

@Bean
public DefaultConfiguration configuration() {
    DefaultConfiguration jooqConfiguration = new DefaultConfiguration();
    jooqConfiguration.set(connectionProvider());
    jooqConfiguration.set(new DefaultExecuteListenerProvider(exceptionTransformer()));
    String sqlDialectName = environment.getRequiredProperty("jooq.sql.dialect");
    SQLDialect dialect = SQLDialect.valueOf(sqlDialectName);
    jooqConfiguration.set(dialect);
    return jooqConfiguration;
}
Also used : DefaultExecuteListenerProvider(org.jooq.impl.DefaultExecuteListenerProvider) SQLDialect(org.jooq.SQLDialect) DefaultConfiguration(org.jooq.impl.DefaultConfiguration) Bean(org.springframework.context.annotation.Bean)

Aggregations

DefaultExecuteListenerProvider (org.jooq.impl.DefaultExecuteListenerProvider)7 DefaultConfiguration (org.jooq.impl.DefaultConfiguration)4 ExecuteContext (org.jooq.ExecuteContext)3 ExecuteListener (org.jooq.ExecuteListener)3 DefaultExecuteListener (org.jooq.impl.DefaultExecuteListener)3 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 DSLContext (org.jooq.DSLContext)2 SQLDialect (org.jooq.SQLDialect)2 Settings (org.jooq.conf.Settings)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 ExceptionTranslator (com.baeldung.jooq.introduction.ExceptionTranslator)1 PersonRecord (com.khartec.waltz.schema.tables.records.PersonRecord)1 List (java.util.List)1 BasicDataSource (org.apache.commons.dbcp.BasicDataSource)1 ObjectMapper (org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper)1 PersonRecord (org.finos.waltz.schema.tables.records.PersonRecord)1 Configuration (org.jooq.Configuration)1 ExecuteListenerProvider (org.jooq.ExecuteListenerProvider)1 Query (org.jooq.Query)1