In addition to connection pooling and prepared statement caching, OpenJPA employs statement batching to speed up JDBC updates. Statement batching is enabled by default for any JDBC driver that supports it. When batching is on, OpenJPA automatically orders its SQL statements to maximize the size of each batch. This can result in large performance gains for transactions that modify a lot of data.
You configure statement batching through the system DBDictionary, which is controlled by the openjpa.jdbc.DBDictionary configuration property. You can enable the statement batching by setting the batchLimit in the value. The batch limit is the maximum number of statements OpenJPA will ever batch together. A value has the following meaning:
-1: Unlimited number of statements for a batch.
0: Disable batch support. This is the default for most
any positive number: Maximum number of statements for a batch.
By default, the batch support is based on each Dictionary to define the default batch limit. Currently only DB2 and Oracle dictionaries are set the default batch limit to 100. The default batch limit for the rest of the dictionaries is set to zero (disabled).
The example below shows how to enable and disable statement batching via your configuration properties.
Example 4.12. Enable SQL statement batching
<property name="openjpa.jdbc.DBDictionary" value="db2(batchLimit=25)"/> <property name="openjpa.jdbc.DBDictionary" value="oracle(batchLimit=-1)"/> Or <property name="openjpa.jdbc.DBDictionary" value="batchLimit=25"/> <property name="openjpa.jdbc.DBDictionary" value="batchLimit=-1"/>
Example 4.13. Disable SQL statement batching
<property name="openjpa.jdbc.DBDictionary" value="db2(batchLimit=0)"/> Or <property name="openjpa.jdbc.DBDictionary" value="batchLimit=0"/>
Example 4.14. Plug-in custom statement batching implementation
<property name="openjpa.jdbc.UpdateManager" value="mycomp.MyUpdateManager"/>