Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Transaction for large Data ~15k entries #36

Closed
bhapps opened this issue Dec 9, 2018 · 8 comments
Closed

Using Transaction for large Data ~15k entries #36

bhapps opened this issue Dec 9, 2018 · 8 comments

Comments

@bhapps
Copy link

bhapps commented Dec 9, 2018

Current Version: com.reactiveandroid:reactiveandroid:1.4.3

I have, on launch a scenario of comparing local string & server side string, and on false, I run an update to my DB which has data pulled from API (~15k items) in which I pass this data to public static helper to do DB updates on the tables;

Problem is when I use begin/end transaction in this method(), even though the save() passes true, nothing gets actually added or updated (get count of 0), but if I remove the begin/end transaction everything gets updated/created in the DB as i should (get count of ~15k) but is very slow and not ideal at all;

Also both types freeze the UI indefinitely until task completed;

@bhapps bhapps changed the title Using Transaction for large Data ~15k entries via CRUD Using Transaction for large Data ~15k entries Dec 9, 2018
@bhapps
Copy link
Author

bhapps commented Dec 9, 2018

Moved code to pass through AsyncTask to stop UI freezing (worked), however, the below,

begin/end transaction, even though the if(class.save() > 0){} passes true on each data item (in List<>), nothing gets actually added or updated (get count of 0)

still persists..

@ImangazalievM
Copy link
Owner

  1. Can you create a test project, that reproduces your problem?
  2. To avoid UI freezing you have to perform your operations with a database in the background thread.

@ImangazalievM
Copy link
Owner

@bennith can you create a simple project that reproduces your problem, and share it on GitHub?

@bhapps
Copy link
Author

bhapps commented Dec 11, 2018

@ImangazalievM

Please see sample project which uses transaction to add data (which still fails), but turning off transactions data is added (getting counts of 15K rows)

Change public static boolean useTransactions = true; in MainApplication to enable/disable transaction

Please see ORMHelpers file and the method public static Boolean setRowData(List<String> getPassedData) which processes the passed data;

https://github.com/Bennith/ORMTransactionExample

@ImangazalievM
Copy link
Owner

I will check it out soon. Unfortunately, I have a lot of work to do now.

@bhapps
Copy link
Author

bhapps commented Dec 13, 2018

Maybe it is due to missing the setTransactionSuccessful() to do the actual commit.
I will test this on my side to confirm.

How you can use database transaction in Android

  • If you want to start the transaction there is a method beginTransaction()
  • If you want to commit the transaction there is a method setTransactionSuccessful() which will commit the values in the database
  • If you had start the transaction you need to close the transaction so there is a method endTransaction() which will end your database transaction

If so, can we add this to the documentation transactions

@bhapps
Copy link
Author

bhapps commented Dec 14, 2018

Confirmed, It is due to the missing line code setTransactionSuccessful()
beginTransaction()
/* do sql work here */
ReActiveAndroid.getDatabase(ORMAppDatabase.class).getWritableDatabase().setTransactionSuccessful();
endTransaction()

@bhapps bhapps closed this as completed Dec 14, 2018
@ImangazalievM
Copy link
Owner

@bennith Good job! I will add new API for working with transactions in the new version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants