use of org.jooq.ExecuteListenerProvider in project jOOQ by jOOQ.
the class ExecuteListeners method listeners.
/**
* Provide delegate listeners from an <code>ExecuteContext</code>
*/
private static final ExecuteListener[][] listeners(ExecuteContext ctx) {
List<ExecuteListener> list = null;
// [#6580] Fetching server output may require some pre / post actions around the actual statement
if (SettingsTools.getFetchServerOutputSize(0, ctx.settings()) > 0)
(list = init(list)).add(new FetchServerOutputListener());
// [#6051] The previously used StopWatchListener is no longer included by default
if (!FALSE.equals(ctx.settings().isExecuteLogging())) {
// we do not DEBUG log anyway.
if (LOGGER_LISTENER_LOGGER.isDebugEnabled())
(list = init(list)).add(new LoggerListener());
}
for (ExecuteListenerProvider provider : ctx.configuration().executeListenerProviders()) // Could be null after deserialisation
if (provider != null)
(list = init(list)).add(provider.provide());
if (list == null)
return null;
ExecuteListener[] def = list.toArray(EMPTY_EXECUTE_LISTENER);
ExecuteListener[] rev = null;
return new ExecuteListener[][] { ctx.settings().getExecuteListenerStartInvocationOrder() != REVERSE ? def : (rev = Tools.reverse(def.clone())), ctx.settings().getExecuteListenerEndInvocationOrder() != REVERSE ? def : (rev != null ? rev : (rev = Tools.reverse(def.clone()))) };
}
use of org.jooq.ExecuteListenerProvider in project spring-boot by spring-projects.
the class JooqAutoConfigurationTests method jooqWithSeveralExecuteListenerProviders.
@Test
void jooqWithSeveralExecuteListenerProviders() {
this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class, TestExecuteListenerProvider.class).run((context) -> {
DSLContext dsl = context.getBean(DSLContext.class);
ExecuteListenerProvider[] executeListenerProviders = dsl.configuration().executeListenerProviders();
assertThat(executeListenerProviders).hasSize(2);
assertThat(executeListenerProviders[0]).isInstanceOf(DefaultExecuteListenerProvider.class);
assertThat(executeListenerProviders[1]).isInstanceOf(TestExecuteListenerProvider.class);
});
}
use of org.jooq.ExecuteListenerProvider in project jOOQ by jOOQ.
the class AbstractDatabase method create.
@SuppressWarnings("serial")
protected final DSLContext create(boolean muteExceptions) {
// [#3800] Make sure that faulty queries are logged in a formatted
// way to help users provide us with bug reports
final Configuration configuration = create0().configuration();
if (muteExceptions) {
return DSL.using(configuration);
} else {
final Settings newSettings = SettingsTools.clone(configuration.settings()).withRenderFormatted(true);
final ExecuteListenerProvider[] oldProviders = configuration.executeListenerProviders();
final ExecuteListenerProvider[] newProviders = new ExecuteListenerProvider[oldProviders.length + 1];
System.arraycopy(oldProviders, 0, newProviders, 0, oldProviders.length);
newProviders[oldProviders.length] = new DefaultExecuteListenerProvider(new DefaultExecuteListener() {
class SQLPerformanceWarning extends Exception {
}
@Override
public void start(ExecuteContext ctx) {
// SQLPerformanceWarning.
if (!initialised) {
DSL.using(configuration).selectOne().fetch();
initialised = true;
}
}
@Override
public void executeStart(ExecuteContext ctx) {
ctx.data("org.jooq.util.AbstractDatabase.watch", new StopWatch());
}
@Override
public void executeEnd(ExecuteContext ctx) {
StopWatch watch = (StopWatch) ctx.data("org.jooq.util.AbstractDatabase.watch");
if (watch.split() > TimeUnit.SECONDS.toNanos(5L)) {
watch.splitWarn("Slow SQL");
log.warn("Slow SQL", "jOOQ Meta executed a slow query (slower than 5 seconds)" + "\n\n" + "Please report this bug here: https://github.com/jOOQ/jOOQ/issues/new\n\n" + formatted(ctx.query()), new SQLPerformanceWarning());
}
}
@Override
public void exception(ExecuteContext ctx) {
log.warn("SQL exception", "Exception while executing meta query: " + (ctx.sqlException() != null ? ctx.sqlException().getMessage() : ctx.exception() != null ? ctx.exception().getMessage() : "No exception available") + "\n\n" + "Please report this bug here: https://github.com/jOOQ/jOOQ/issues/new\n\n" + formatted(ctx.query()));
}
private String formatted(Query query) {
return DSL.using(configuration.derive(newSettings)).renderInlined(query);
}
});
return DSL.using(configuration.derive(newProviders));
}
}
Aggregations