Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite transactions with Google IO REST pattern's ContentProvider?

I'm trying to implement the second REST client model presented by Virgil Dobjanschi on this video:

http://developer.android.com/videos/index.html#v=xHXn3Kg2IQE

This is the high level diagram for the model I'm talking about:

enter image description here

I implemented everything as suggested, but I have a complex SQLite database model with lots of tables and I need to use transactions to update my local data with brand new data retrieved from server (step 7 in the picture).

Are there any suggestions you could make to help me out implement a transactional ContentProvider for this case?

Some of you may suggest me to use raw SQLite instead, but this way I won't take the advantages of ContentObservers, managedQueries and database accesses synchronization provided by the ContentProvider.

Any help would be appreciated.

like image 787
Flávio Faria Avatar asked Nov 05 '22 12:11

Flávio Faria


1 Answers

Since you don't have access to the the Level 11 API, you could do this instead. Lets say you want to do this transaction stuff in your update method:

final Cursor update(Uri uri, ContentValues values, String where, String[] selectionArgs)
{

   if(uri == uri1){
     //do stuff you normally do
   }
   //other uri stuff
   ...
   else if(uri == special_uri){
     //do your transaction stuff here
   }
}

In this case, special_uri is a uri you use to indicate that you're going to need to do your special transaction stuff. In other words, we're using the URI here to indicate that a transaction must be done.

like image 112
Kurtis Nusbaum Avatar answered Nov 09 '22 16:11

Kurtis Nusbaum