You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
4.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.gtask.data;
import android.database.Cursor;
import org.json.JSONObject;
/**
* 抽象节点类,定义同步任务的基础结构
*
* 功能说明:
* - 作为所有同步任务节点的基类,提供基础属性和抽象方法
* - 定义8种同步动作常量用于标识数据同步方向
* - 封装节点基础信息全局ID、名称、最后修改时间和删除状态
*
* 设计目的:
* - 为本地数据和远程数据同步提供统一接口
* - 支持双向同步(本地↔远程)和冲突处理
* - 通过抽象方法强制子类实现具体同步逻辑
*/
public abstract class Node {
public static final int SYNC_ACTION_NONE = 0;// 无需同步
public static final int SYNC_ACTION_ADD_REMOTE = 1; // 需要添加数据到远程
public static final int SYNC_ACTION_ADD_LOCAL = 2;// 需要添加数据到本地
public static final int SYNC_ACTION_DEL_REMOTE = 3;// 需要删除远程数据
public static final int SYNC_ACTION_DEL_LOCAL = 4; // 需要删除本地数据
public static final int SYNC_ACTION_UPDATE_REMOTE = 5;// 需要更新远程数据
public static final int SYNC_ACTION_UPDATE_LOCAL = 6;// 需要更新本地数据
public static final int SYNC_ACTION_UPDATE_CONFLICT = 7;// 需要解决更新冲突
public static final int SYNC_ACTION_ERROR = 8;// 同步过程发生错误
private String mGid;
private String mName;
private long mLastModified;
private boolean mDeleted;
public Node() {
mGid = null;
mName = "";
mLastModified = 0;
mDeleted = false;
}
/**
* 生成创建动作的JSON数据
* @param actionId 动作ID
* @return 包含创建指令的JSON对象
*/
public abstract JSONObject getCreateAction(int actionId);
/**
* 生成更新动作的JSON数据
* @param actionId 动作ID
* @return 包含更新指令的JSON对象
*/
public abstract JSONObject getUpdateAction(int actionId);
/**
* 用远程JSON数据设置节点内容
* @param js 来自远程的JSON数据
*/
public abstract void setContentByRemoteJSON(JSONObject js);
/**
* 用本地JSON数据设置节点内容
* @param js 来自本地的JSON数据
*/
public abstract void setContentByLocalJSON(JSONObject js);
/**
* 从内容生成本地JSON数据
* @return 包含节点内容的JSON对象
*/
public abstract JSONObject getLocalJSONFromContent();
/**
* 根据数据库游标获取同步动作类型
* @param c 数据库游标
* @return 同步动作常量值
*/
public abstract int getSyncAction(Cursor c);
// 设置/获取全局唯一标识
public void setGid(String gid) {
this.mGid = gid;
}
// 设置/获取节点名称
public void setName(String name) {
this.mName = name;
}
// 设置/获取最后修改时间戳
public void setLastModified(long lastModified) {
this.mLastModified = lastModified;
}
// 设置/获取删除标记
public void setDeleted(boolean deleted) {
this.mDeleted = deleted;
}
public String getGid() {
return this.mGid;
}
public String getName() {
return this.mName;
}
public long getLastModified() {
return this.mLastModified;
}
public boolean getDeleted() {
return this.mDeleted;
}
}