本文介绍了JooQ的加载程序的.commit *()或.batch *()方法是吗?在TransactionalRunnable中发生问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 这是使用JooQ 3.7.0。 JooQ允许您使用其API 从例如导入数据,即CSV 。This is using JooQ 3.7.0. JooQ allows you to use its API to import data from, for instance, a CSV.让我们将此代码作为 TransactionalRunnable : 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 fileprivate 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); }}现在,调用 DSLContext 的 .loadInto()是 LoaderOptionStep 。此类上有几种方法,特别是默认的提交策略(默认为 .commitNone())和批处理方法。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.在这里,我们正在进行JooQ创建的交易;除了默认值外,我没有指定任何提交或批处理策略。Here we are in a transaction created by JooQ; I don't specify any commit nor batch policy other than the defaults.是否取决于我使用的RDBMS引擎是否使用任何提交/批处理策略根本不重要?请注意,在我的情况下,这是PostgreSQL 9.4.X。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.推荐答案从jOOQ 3.7开始,使用jOOQ的事务API的行为以及 Loader API上除 commitNone()(默认值)以外的其他任何东西都是 undefined 。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. Loader API将直接在基础JDBC连接上提交批处理,但这可能会有所不同,具体取决于关于如何产生此连接(例如通过连接池等)的信息。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.)有一个待处理的功能请求,用于指定和实现可预测的行为: https://github.com/jOOQ/jOOQ/issues/4770 There is a pending feature request to specify and implement a predictable behaviour:https://github.com/jOOQ/jOOQ/issues/4770 这篇关于JooQ的加载程序的.commit *()或.batch *()方法是吗?在TransactionalRunnable中发生问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-14 05:09