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

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

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

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

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

Loading…
Cancel
Save