Hi Ian,
> I note that Jooq does support JDBC batch processing, but it's not clear
> whether .store() can be used in some kind of batch mode. Can it?
No. But that is a very nice idea
> Is there some other recommended way to do a large number of inserts/updates?
Right now, you'll probably have to hande batch inserts/update
yourself, using the Factory.batch() methods. Unfortunately, there's no
simple way of extracting a .store() method's generated SQL, short of
providing jOOQ with a dummy JDBC connection, intercepting the SQL and
its execution:
-------------------------------------------------------
public class DummyConnection implements Connection {
@Override
public PreparedStatement prepareStatement(String sql) {
// Collect the SQL statement here
}
@Override
public int executeUpdate() {
// Ignore
}
}
-------------------------------------------------------
But jOOQ should support this, correctly handling inserts and updates.
There are two execution modes:
- With bind variables: then the bulk of records would have to be
ordered by record type, and then by INSERT/UPDATE. There is a risk of
bad ordering though, if one record would depend on another
- Without bind variables: the bulk of records can just be
inserted/updated in the provided order
NOTE: I doubt there is any way to fetch generated keys in batch mode.
I'll have to read into that (examples welcome), but I'd say it is not
possible.
The API would probably look something like this:
// Without bind variables
Factory.batchStore(TableRecord<?>...)
I'll track this as feature request 1361:
https://sourceforge.net/apps/trac/jooq/ticket/1361
Cheers
Lukas