问题
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