Turn on or off statement batching. Statement batching can be transparent
for drivers and databases that support getGeneratedKeys. Otherwise you may
wish to specifically control when batching is used via this method.
Refer to java.sql.PreparedStatement.addBatch();
Note that you may also wish to use the setPersistCascade method to stop
save and delete cascade behaviour. You may do this to have full control
over the order of execution rather than the normal cascading fashion.
Note that the execution order in batch mode may be different from
non batch mode execution order. Also note that insert behaviour
may be different depending on the JDBC driver and its support for
getGeneratedKeys. That is, for JDBC drivers that do not support
getGeneratedKeys you may not get back the generated IDs (used for inserting
associated detail beans etc).
Calls to save(), delete(), insert() and execute() all support batch
processing. This includes normal beans, MapBean, CallableSql and UpdateSql.
The flushing of the batched statements is automatic but you can call
batchFlush when you like. Note that flushing occurs when a query is
executed or when you mix UpdateSql and CallableSql with save and delete of
beans.
Example: batch processing executing every 3 rows
String data = "This is a simple test of the batch processing"String sql = "{call sp_t3(?,?)}";
CallableSql cs = new CallableSql(sql);
cs.registerOut(2, Types.INTEGER);
// (optional) inform eBean this stored procedure
// inserts into a table called sp_test
cs.addModification("sp_test", true, false, false);
Transaction txn = ebeanServer.beginTransaction();
txn.setBatchMode(true);
txn.setBatchSize(3);
try
for (int i = 0; i < da.length;)
cs.setParameter(1, da[i]);
ebeanServer.execute(cs);
}
// NB: commit implicitly flushes
txn.commit();
} finally
txn.end();
}
}