Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 265
Héctor Avatar asked Mar 17 '23 23:03

Héctor


1 Answers

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(...).

like image 181
Gray Avatar answered Apr 26 '23 08:04

Gray