OrmLite: Difference between Dao.callBatchTasks() and TransactionManager.callInTransaction()

android, java, ormlite, transactions

Solution

Difference between `Dao.callBatchTasks()` and `TransactionManager.callInTransaction()`

The difference depends on the database you are using. Under Android, there is no difference. The javadocs for `callBatchTasks(...)` says:

Call the call-able that will perform a number of batch tasks. This is for performance when you want to run a number of database operations at once -- maybe loading data from a file. This will turn off what databases call "auto-commit" mode, run the call-able, and then re-enable "auto-commit". If auto-commit is not supported then a transaction will be used instead.

Android's SQLite is one of the databases. Inside the internal ORMLite code you see:

private <CT> CT doCallBatchTasks(DatabaseConnection connection, boolean saved,
        Callable<CT> callable) throws SQLException {
    if (databaseType.isBatchUseTransaction()) {
        return TransactionManager.callInTransaction(connection, saved, databaseType,
            callable);
    }
    ...

So internally, when using under Android, `dao.callBatchTasks(...)` is a call through to `TransactionManager.callInTransaction(...)`.

Problem

Which is the difference between these methods? I have readed the docs but I don't understand what `callBatchTasks` method do. Documentation says: This will turn off what databases call "auto-commit" mode, run the call-able and then re-enable "auto-commit". Is't it a transaction? Thanks.

Original source