I'm using Virgil Dobjanschi's Option B (from this talk: http://www.google.com/events/io/2010/sessions/developing-RESTful-android-apps.html) to implement a web service on my Android App to connect to a Google Cloud Endpoints RESTful service (hence, my URLs are abstracted over).
The local SQLite database requires a Primary key (which must be called _id so it can link with a ListView). The AppEngine service also requires a unique ID per record. The resources in the service are shared between multiple clients, so their IDs need to be maintained unique on the server. The resource ID is generated, derived from two other IDs, and in the form of a String.
By design, these resources are never created locally on the Android app, they are only read and updated - creation and deletion happens elsewhere, and then those created are sent via Google Cloud Messaging, complete with their REST Ids, and inserted into the SQLite table. If I ever do create them locally, I'll be able to generate the unique ID from the REST resource locally as well.
Should I have the ID on the SQLite database be a separate unique id, maintained locally, and store the REST id in the record, or should I set the SQLite ID to be the same as the REST id?
ie:
My REST Resources are of the form:
String id; // unique, derived from two other ids
String data;
My SQLite options are:
create table myResource (
_id INTEGER PRIMARY KEY AUTOINCREMEMT,
restId TEXT,
data TEXT);
Or:
create table myResource (
_id TEXT PRIMARY KEY,
data TEXT);
In the first option, I could make restId UNIQUE as well. I'm leaning towards the second option, but am wondering if I'll run into unforeseen problems with this approach.
I also have another similar situation with some different resources where the REST key is a Long rather than a String, but I still question whether I should maintain a local primary key separate to the REST resource ID.