且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

同步处理资料Android客户端与远程SQL服务器数据库,使用Web服务

更新时间:2023-01-18 09:58:29

我建议你使用额外的字段。添加四个colums到本地表中的Andr​​oid:

I suggest you to use extra fields. Add four colums to your local tables in Android :


  • TRANSACTING_FLAG:它设置为true,当你发布或更新服务器上的该资源

  • REQUEST_STATE:设置该标志张贴/更新/删除等

  • RESULT_ code:这个字段设置为服务器为这个特定的资源接收到的最后结果code

  • TIMESTAMP:至极数据后时期已经被更新

工作流程很简单:
当您为您的服务器获取数据只是检查,如果你的资源的最后更新的时间戳优于你以前定义的缓存时间戳。如果时间戳优于执行更新数据的请求。在办理布尔让你知道一个特定的资源实际上是与服务器同步。结果code可以让你知道,如果请求失败与否和enventually重试当网络可用。因为你可以检查之前见过的任何本地资源多亏了额外的字段的同步状态任何时候做这样你将保持本地和远程数据库之间的persitence。

Workflow is simple : When you retrieve data for your server just check if the last updated timestamp of your resource is superior to the cache timestamp you have defined before. If the timestamp is superior perform a request to update data. The transacting boolean let you know that a particular resource is actually synchronizing with the server. The result code lets you know if the request has failed or not and enventually retry it when the network is available. Doing this way you will maintain the persitence between your local and remote database because at any moment you can check the "synchronized state" of any local resource thanks to extra fields seen before.

我做了一个库来处理这个问题。看看到 RESTDroid 。即使缓存functionnality不是手柄,你就可以简单地添加它。

I made a library to handle this. Take a look to RESTDroid. Even if the cache functionnality is not handles, you will be able to simply add it.