简体   繁体   English

Groovy SQL批处理

[英]Groovy SQL batch

I've read about Groovy's batch method. 我已经阅读了Groovy的batch方法。 The part that I'm confused about is int batchSize . 我感到困惑的部分是int batchSize What does it do and what is really for? 它有什么作用,真正的作用是什么? I've made sample scripts using batch method and it doesn't seem to make a difference. 我已经使用batch方法制作了示例脚本,但似乎没有什么不同。 I just want another point-of-view. 我只想换一个角度。

When you have a large number of SQL queries to run, you can either run them one by one (which can be very slow) or all at once (which can flood the database). 当您有大量的SQL查询要运行时,您可以一个一个地运行它们(这可能很慢),也可以一次全部运行(这可能会淹没数据库)。 And you may not even know in advance how many queries you will have (consider for example storing a bunch of user generated structures). 而且,您甚至可能事先都不知道要查询多少个查询(例如考虑存储一堆用户生成的结构)。

Batch processing allows you to take the middle ground and run up to batchSize queries at once. 批处理允许您采取中间立场,并立即运行batchSize查询。 When they finish, the code will run the next batchSize queries. 完成后,代码将运行下一个batchSize查询。 And even if you are not dealing with with a potentially large number of queries, withBatch is a shortcut to calling the appropriate Java methods for executing many SQL queries. 即使您不处理可能大量的查询, withBatch还是调用适当的 Java方法来执行许多SQL查询的快捷方式。

As for why it makes no difference in your code, you would have to tell us more about how you are using it and what kind of difference you were expecting but didn't experience. 至于为什么它在您的代码中没有区别,您将不得不告诉我们更多有关如何使用它以及您期望但没有经历过的区别的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM