public static Duration timedContext(final DataSource dataSource,
                                        final boolean isTimed,
                                        final Consumer<DSLContext> consumer) {
        final Duration duration;
        try (final Connection connection = dataSource.getConnection()) {
            try {
                checkDataSource(dataSource);
                final DSLContext context = createContext(connection);
                if (isTimed) {
                    duration = DurationTimer.measure(() ->
                            consumer.accept(context));
                } else {
                    consumer.accept(context);
                    duration = Duration.ZERO;
                }
            } finally {
                releaseDataSource();
            }
        } catch (final Exception e) {
            throw convertException(e);
        }
        return duration;
    }
If {@code isTimed} is {@code true} it will measure the duration of consumer,
else it will return a zero duration. {@code isTimed} can be set using
{@code LOGGER.isDebugEnabled()} for example.
stroom-db-util/src/main/java/stroom/db/util/JooqUtil.java