同步处理资料Android客户端与远程SQL服务器数据库,使用Web服务 [英] Syncronizing Android client with remote SQL-server database, using web service

查看:199
本文介绍了同步处理资料Android客户端与远程SQL服务器数据库,使用Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了一个Android应用程序需要一组数据,通过SQL Server数据库服用。该应用程序获得的数据调用WS。第一呼叫时的应用程序的启动在第一时间WS之后,我需要保持更新的数据,根据本修改的可能发生的服务器端(SQL服务器数据库)。
为了得到这个结果我执行,具有与predefined频率,WS调用,因为知道,如果数据库数据被更改。如果新的数据是可用的,其他的Web服务调用获得它们。

I implemented an Android application that requires a set of data, taken by a SQL Server database. The application obtains the data calling a WS. After a first call to WS when the application start the first time, I need to maintain the data updated, according to the modify that may happens server-side (SQL server database). For obtaining this result I perform, with a with a predefined frequency, a WS call, for knowing if data on database are changed. If new data are available, other web service is called for obtaining them.

此解决方案正常工作对我(我不要求实时更新)。但是,我认为,这个解决方案在能耗,消耗CPU和网络流量的长期过于昂贵。
一直以来,我想象,这就是我想知道,如果存在一个通用的方法来处理它一个非常普遍的问题。

This solution works fine for my ( I don't require real-time update). But, I think that this solution is too expensive in term of energy consumption, cpu consumption and network traffic. Since, I immagine this is a very common problem I would know if exists a generic way to deal with it.

推荐答案

我建议你使用额外的字段。添加四个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.

这篇关于同步处理资料Android客户端与远程SQL服务器数据库,使用Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆