SQLite transactions with Google IO REST pattern's ContentProvider?

江枫思渺然 提交于 2019-12-21 17:00:16

问题


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:

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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/7828292/sqlite-transactions-with-google-io-rest-patterns-contentprovider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!