SQLite transactions with Google IO REST pattern

2019-04-09 04:46发布

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.

2条回答
唯我独甜
2楼-- · 2019-04-09 05:01

You can implement custom function in your ContentProvider that execute your necessary transactions. Then you can call those funcitons using the call() function in your Processor.

查看更多
贪生不怕死
3楼-- · 2019-04-09 05:03

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.

查看更多
登录 后发表回答