Do the .commit*() or .batch*() methods of a JooQ's Loader<?> matter within a TransactionalRunnable?

老子叫甜甜 提交于 2019-12-14 03:48:36

问题


This is using JooQ 3.7.0. JooQ allows you to use its API to import data from, for instance, a CSV.

Let us take this code as an example of an implementation (in Java 8, as a method reference) of a TransactionalRunnable:

// csvPath is a Path to a CSV file
private void writeCsv(final Configuration configuration)
{
    try (
        final Reader reader = Files.newBufferedReader(csvPath);
    ) {
        final Loader<PermethodMetricsRecord> loader = DSL.using(configuration)
            .loadInto(PERMETHOD_METRICS)
            .loadCSV(reader)
            .fields(PERMETHOD_METRICS.fields())
            .execute();
        LOGGER.info("{} lines stored in database", loader.stored());
    } catch (IOException e) {
        throw new RuntimeException("Cannot open CSV for reading", e);
    }
}

Now, the call to a DSLContext's .loadInto() is a LoaderOptionStep. And this class has several methods on it, in particular a default commit policy (.commitNone() is the default) and batch methods.

Here we are in a transaction created by JooQ; I don't specify any commit nor batch policy other than the defaults.

Does it matter at all whether I use any commit/batch policy depending on the RDBMS engine I use? Note that in my case, this is PostgreSQL 9.4.X.


回答1:


As of jOOQ 3.7, the behaviour of using jOOQ's transaction API along with anything other than commitNone() (the default) on the Loader API is undefined.

The Loader API will commit batches directly on the underlying JDBC connection, but this can behave differently, depending on how you produce this connection (e.g. via a connection pool, etc.)

There is a pending feature request to specify and implement a predictable behaviour: https://github.com/jOOQ/jOOQ/issues/4770



来源:https://stackoverflow.com/questions/33596329/do-the-commit-or-batch-methods-of-a-jooqs-loader-matter-within-a-tra

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!