pull/1/head
1 9 months ago
parent 1d2f5c1d55
commit c17b8df8b7

@ -31,33 +31,39 @@ public class MetaData extends Task {
private String mRelatedGid = null;
public void setMeta(String gid, JSONObject metaInfo) {
//调用JSONObject库函数put ()Task类中的setNotes ()和setName ()函数生成元数据库
try {
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
} catch (JSONException e) {
Log.e(TAG, "failed to put related gid");
Log.e(TAG, "failed to put related gid");//输出错误信息
}
setNotes(metaInfo.toString());
setName(GTaskStringUtils.META_NOTE_NAME);
}
public String getRelatedGid() {
//获取相关联的Gid
return mRelatedGid;
}
@Override
public boolean isWorthSaving() {
//判断当前数据是否为空,若为空则返回真即值得保存
return getNotes() != null;
}
@Override
public void setContentByRemoteJSON(JSONObject js) {
//使用远程json数据对象设置元数据内容
super.setContentByRemoteJSON(js);
if (getNotes() != null) {
try {
JSONObject metaInfo = new JSONObject(getNotes().trim());
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
} catch (JSONException e) {
Log.w(TAG, "failed to get related gid");
Log.w(TAG, "failed to get related gid");//输出警告信息
mRelatedGid = null;
}
}
@ -66,16 +72,19 @@ public class MetaData extends Task {
@Override
public void setContentByLocalJSON(JSONObject js) {
// this function should not be called
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
//使用本地json数据对象设置元数据内容
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");//传递非法参数异常
}
@Override
public JSONObject getLocalJSONFromContent() {
//从元数据内容中获取本地json对象
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
}
@Override
public int getSyncAction(Cursor c) {
//获取同步动作状态
throw new IllegalAccessError("MetaData:getSyncAction should not be called");
}

@ -21,6 +21,7 @@ import android.database.Cursor;
import org.json.JSONObject;
public abstract class Node {
//定义了各种用于表征同步状态的常量
public static final int SYNC_ACTION_NONE = 0;
public static final int SYNC_ACTION_ADD_REMOTE = 1;

@ -36,6 +36,7 @@ import org.json.JSONObject;
public class SqlData {
//得到类的简写名称存入字符串TAG中
private static final String TAG = SqlData.class.getSimpleName();
private static final int INVALID_ID = -99999;
@ -72,6 +73,7 @@ public class SqlData {
private ContentValues mDiffDataValues;
public SqlData(Context context) {
//构造函数,用于初始化数据
mContentResolver = context.getContentResolver();
mIsCreate = true;
mDataId = INVALID_ID;
@ -83,6 +85,7 @@ public class SqlData {
}
public SqlData(Context context, Cursor c) {
//构造函数,用于初始化数据
mContentResolver = context.getContentResolver();
mIsCreate = false;
loadFromCursor(c);
@ -90,6 +93,7 @@ public class SqlData {
}
private void loadFromCursor(Cursor c) {
//从当前的光标处将五列的数据加载到该类的对象
mDataId = c.getLong(DATA_ID_COLUMN);
mDataMimeType = c.getString(DATA_MIME_TYPE_COLUMN);
mDataContent = c.getString(DATA_CONTENT_COLUMN);
@ -98,6 +102,7 @@ public class SqlData {
}
public void setContent(JSONObject js) throws JSONException {
//设置用于共享的数据
long dataId = js.has(DataColumns.ID) ? js.getLong(DataColumns.ID) : INVALID_ID;
if (mIsCreate || mDataId != dataId) {
mDiffDataValues.put(DataColumns.ID, dataId);
@ -131,6 +136,7 @@ public class SqlData {
}
public JSONObject getContent() throws JSONException {
//获取共享的数据内容
if (mIsCreate) {
Log.e(TAG, "it seems that we haven't created this in database yet");
return null;
@ -145,7 +151,7 @@ public class SqlData {
}
public void commit(long noteId, boolean validateVersion, long version) {
//把当前造作所做的修改保存到数据库
if (mIsCreate) {
if (mDataId == INVALID_ID && mDiffDataValues.containsKey(DataColumns.ID)) {
mDiffDataValues.remove(DataColumns.ID);
@ -184,6 +190,7 @@ public class SqlData {
}
public long getId() {
//获取当前id
return mDataId;
}
}

@ -39,6 +39,7 @@ import java.util.ArrayList;
public class SqlNote {
//得到类的简写名称存入字符串TAG中
private static final String TAG = SqlNote.class.getSimpleName();
private static final int INVALID_ID = -99999;
@ -123,6 +124,7 @@ public class SqlNote {
private ArrayList<SqlData> mDataList;
public SqlNote(Context context) {
//构造函数
mContext = context;
mContentResolver = context.getContentResolver();
mIsCreate = true;
@ -144,6 +146,7 @@ public class SqlNote {
}
public SqlNote(Context context, Cursor c) {
//构造函数
mContext = context;
mContentResolver = context.getContentResolver();
mIsCreate = false;
@ -167,6 +170,7 @@ public class SqlNote {
}
private void loadFromCursor(long id) {
//
Cursor c = null;
try {
c = mContentResolver.query(Notes.CONTENT_NOTE_URI, PROJECTION_NOTE, "(_id=?)",

Loading…
Cancel
Save