个人网站www.pixysoft.net设计系列: 数据库同步的实现
個(gè)人網(wǎng)站www.pixysoft.net設(shè)計(jì)系列: 數(shù)據(jù)庫同步的實(shí)現(xiàn)
Iteration 1
.對于本地新增的數(shù)據(jù),版本號全部為0
.上傳成功后,版本自動(dòng)加1
.上傳失敗則直接返回(Web V?<= Local V)
.下載成功后,修改本地版本號
.下載失敗,直接返回(Web V >= Local V)
Interation 2
.CVCL放在本地端.
.本地直接操作數(shù)據(jù)庫的時(shí)候不修改版本(新增的數(shù)據(jù)自動(dòng)設(shè)0)
.當(dāng)確定同步的時(shí)候,本地?cái)?shù)據(jù)版本+1,然后上傳.如果成功則保存兩地版本
.如果失敗,則返回失敗信息通知處理
Interation 3
.在數(shù)據(jù)庫字段里面添加mark字段,表示是否被修改.
.上傳的時(shí)候讀取mark字段,作為上傳內(nèi)容.
.上傳/下載成功后,mark字段自動(dòng)被設(shè)置為false。
.本地?cái)?shù)據(jù)Insert/update的之后自動(dòng)設(shè)置Mark = true
Interation 4
。在WebDatabase數(shù)據(jù)庫操作類里面增加對mark的控制
。寫一個(gè)CVController: 放在Database上面.里面提供了與Database一樣的接口,通知增加了額外的操作
//Database Method
public Insert / change the mark for the data.
public Update / change the mark for the data.
private ActivateMark
private DeActivateMark
private InitVersion / When create a new data, it should initiate the version for that data.
//Net work method
public Download / download the data from Web: get local data according to the download data, compare the version, insert / update the correct data and list the error data.
public Upload / upload the data to the Web: select all the markTrue data, increate the version and upload.
private IncreateVersion / When upload, the data should pass this method to increate version.
private CompareVersion / When download, the data should be compared with those in local database, and list the conflict ones.
Interation 5 數(shù)據(jù)刪除
。當(dāng)本地刪除了數(shù)據(jù),如果是Download,則直接插入/ 如果是Upload,則提示是否刪除目標(biāo)數(shù)據(jù)
。目標(biāo)刪除了數(shù)據(jù)(默認(rèn)為沒添加數(shù)據(jù)),Download 則提示是否刪除本地?cái)?shù)據(jù).Upload則直接插入
to be continued ...
轉(zhuǎn)載于:https://www.cnblogs.com/zc22/articles/555389.html
總結(jié)
以上是生活随笔為你收集整理的个人网站www.pixysoft.net设计系列: 数据库同步的实现的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: QSettings 类【官翻】
- 下一篇: linux cmake编译源码,linu