public static <R> TimedResult<R> timedContextResult(final DataSource dataSource,
                                                        final boolean isTimed,
                                                        final Function<DSLContext, R> function) {
        TimedResult<R> timedResult;
        try (final Connection connection = dataSource.getConnection()) {
            try {
                checkDataSource(dataSource);
                final DSLContext context = createContext(connection);
                if (isTimed) {
                    timedResult = DurationTimer.measure(() ->
                            function.apply(context));
                } else {
                    timedResult = TimedResult.zero(function.apply(context));
                }
            } finally {
                releaseDataSource();
            }
        } catch (final Exception e) {
            throw convertException(e);
        }
        return timedResult;
    }
If {@code isTimed} is {@code true} it will measure the duration of function,
else it will return a {@link TimedResult} containing 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