Batching
Batching can be the perfect solution for avoiding performance penalties caused by a significant number of separate database/network round trips representing inserts, deletes, updates, merges, and so on. For instance, without batching, having 1,000 inserts requires 1,000 separate round trips, while employing batching with a batch size of 30 will result in 34 separate round trips. The more inserts (statements) we have, the more helpful batching is.
Batching via DSLContext.batch()
The DSLContext
class exposes a suite of batch()
methods that allow us to execute a set of queries in batch mode. So, we have the following batch()
methods:
BatchBindStep batch(String sql) BatchBindStep batch(Query query) Batch batch(String... queries) Batch batch(Query... queries) Batch batch(Queries queries) Batch batch(Collection<? extends Query> queries) Batch batch(String sql, Object[]... bindings) Batch batch(Query query, Object[]... bindings)
Behind the scenes, jOOQ implements...