客户端服务器数据共享问题

发布于 2024-12-06 09:28:55 字数 561 浏览 2 评论 0原文

我有一个带有移动应用程序的网络服务。用户与应用程序共享服务器上的数据 - 在数据库中存在一个约束,即每个用户的共享对象的名称是唯一的。此外,应用程序在本地存储所有创建的数据(由用户 - 也是共享的)。

我有以下场景:

  1. 用户创建数据名称为 X 的数据。
  2. 用户共享此数据。
  3. 服务器中有该用户的数据库数据名称 X
  4. 用户有一部新手机并安装该应用程序。
  5. 无互联网连接
  6. 用户再次创建数据名为 X 的数据。
  7. 它仅存储在本地 - 因为无互联网连接。
  8. 互联网连接已恢复。
  9. 现在,BG 服务运行并开始共享 BG 中的所有共享数据。
  10. 发现问题是因为约束。

应该怎样做才能解决问题呢?我可以弹出一个新窗口,说它已经共享,并要求用户重命名/覆盖它,提供将该数据 D/L 到其本地数据库等的选项。但由于它是在 BG 中完成的 - 用户是否友好显示这个弹出窗口?

还有其他想法吗?

可能有一种通用的方法可以做到这一点。

我确实需要一些帮助来解决这个问题。

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 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梅倚清风 2024-12-13 09:28:56

以下是我最近完成的一个应用程序处理此问题的方式:

  1. 用户在移动设备上创建一条新记录。新记录被分配一个负主键 _id 号。
  2. 该应用程序会检查互联网连接,如果存在连接,该应用程序会向服务器发送 HTTP 消息,从而在服务器端创建记录。然后,服务器发回创建新 PK _id 的响应,该 PK _id 在应用程序中更新。
  3. 如果没有互联网连接,应用程序会在我的 db_changes 表中创建一条记录,其中包含新记录的表名称和 PK _id。
  4. 服务以 5 分钟为增量运行,从服务器获取更新并将新数据发布到服务器。每次都会轮询 db_changes 表以查找尚未发布到服务器的任何现有插入或更新。
  5. 一旦成功,db_changes 表中的记录将被删除。

在我的情况下,这非常有效。

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.

一花一树开 2024-12-13 09:28:56

为此,您通常不使用名称或类似的东西,而是使用 UUID - 即唯一标识对象的 32 到 64 个字符长的随机字符串。创建对象时,只需在设备上创建一个 UUID 并将其同步到服务器即可。这是 android 中 UUID 类的文档。

虽然理论上具有相同的 UUID 是可行的,但您通常不必太担心,如下所述:http://en.wikipedia.org/wiki/Universally_unique_identifier#Random_UUID_probability_of_duplicates

对于 iOS,您可以使用 CFUUID 类生成UUID

UUID的另一个名称是GUID,全局唯一标识符。因此,您可以删除任何类型的唯一性约束。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文