简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM