问题
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