public static <R> R contextResultWithOptimisticLocking(final DataSource dataSource,
                                                           final Function<DSLContext, R> function) {
        R result;
        try (final Connection connection = dataSource.getConnection()) {
            try {
                checkDataSource(dataSource);
                final DSLContext context = createContextWithOptimisticLocking(connection);
                result = function.apply(context);
            } finally {
                releaseDataSource();
            }
        } catch (DataChangedException e) {
            throw new stroom.util.exception.DataChangedException(e.getMessage(), e);
        } catch (final Exception e) {
            throw convertException(e);
        }
        return result;
    }
@param dataSource
@param function
@param <R>
@return
@throws stroom.util.exception.DataChangedException If another thread/node has already changed the data
stroom-db-util/src/main/java/stroom/db/util/JooqUtil.java