开发者

Client Server data sharing issue

I have a webservice with a mobile application. The user, with the application shares the data on the server - have a constraint in the DB that the name of the shared object is unique per user. Also application stores locally all created data (by the user - that is also shared).

I have the following scenario:

  1. User creates data with data-name X.
  2. User shares this data.
  3. Server has in it DB data-name X for this user
  4. User has a new phone and install the application.
  5. NO INTERNET CONNECTION
  6. user creates again data with data-name X.
  7. it is stored only locally - since NO INTERNET CONNECTION.
  8. Internet connection restored.
  9. Now a BG service run and start sharing all u shared data - in the BG.
  10. The problem found because of the constraint.

What 开发者_C百科should be done to solve the problem? I can popup a new window saying that it already shared and ask the user to rename/overwrite it, give option to D/L this data to its local DB etc. But since it is done in the BG - is it user-friendly to show this popup?

Any other ideas?

Probably there is a common way of doing it.

I can really use some help reagrding this issue.


Here is how a recent app I've done handles this:

  1. A user creates a new record on the mobile device. The new record gets assigned a negative primary key _id number.
  2. The app checks for internet connection and, if a connection exists, the app does an HTTP post to the server, creating the record on the server side. The server then sends back a response creating the new PK _id which gets updated in the app.
  3. If no internet connection, the app creates a record in my db_changes table containing the table name and the PK _id of the new record.
  4. A service runs in 5 minute increments which gets updates from the server and posts new data to the server. The db_changes table is polled each time for any existing inserts or updates that yet to be posted to the server.
  5. Once successful, the record from the db_changes table gets deleted.

In my situation, this works perfectly.


for this, you generally don't use a name or something of that sort, but UUIDs - i.e. 32-to-64 character long random strings that uniquely identify an object. When you create an object, just create a UUID on the device and sync this to the server. Heres the documentation of the UUID class in android.

While it theoretically feasible to have the same UUIDs, it's something you generally don't worry too much about it, as stated here: http://en.wikipedia.org/wiki/Universally_unique_identifier#Random_UUID_probability_of_duplicates

For iOS, you can use the CFUUID class to generate UUID

Another name for UUIDs ist GUID, Globaly unique identifiers. Hence, you remove any kind of uniqueness constraint.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜