I do not really understand the proper usage pattern of SQLite transactions in Android.
Lets say method A starts a transaction. During the execution of the transaction another method B will attempt to do a transaction on the same table (possibly on the same row).
What will happen?
Will the method B “wait” until method A has finished the transaction, and then execute the transaction?
Or will the transction of method B fail?
How do I properly handle that?
To be more precise:
- Method A should query (inside a transaction) if a certain row already exists, and if so, return the row, if that certain row does not exist yet, it should in insert that row, and return the newly inserted row.
- Method B should query (inside a transaction) if a certain row already exists, update that row, if the row does not exist yet, Method B should insert that row.
The idea is to make sure, that, no matter which method first executes, to have either have inserted or updated that particular row
I am not even sure, if these can be achieved on the level of SQLite transactions, or do I have to synchronise methods in Java?
If so, can any body post an example, how such a synchronisation has to be coded in Java?
If ‘A’ modifies a table in transaction, ‘B’ should be blocked (inside SQLite itself) until ‘A’ is committed. It’s pretty similar to java synchronization except it’s dealing with persistent data. Some of details depend on isolation levels
http://en.wikipedia.org/wiki/Isolation_(database_systems)