diff --git a/src/net/micode/notes/gtask/data/SqlNote.java b/src/net/micode/notes/gtask/data/SqlNote.java index f6937f7..db68f72 100644 --- a/src/net/micode/notes/gtask/data/SqlNote.java +++ b/src/net/micode/notes/gtask/data/SqlNote.java @@ -122,8 +122,7 @@ public class SqlNote { private ArrayList mDataList; - public SqlNote(Context context) { - //初始化成员变量 + public SqlNote(Context context) {//初始化成员变量 mContext = context;// 上下文 mContentResolver = context.getContentResolver();// 获取内容解析器 mIsCreate = true; // 是否为新建笔记 @@ -204,15 +203,13 @@ public class SqlNote { private void loadDataContent() { Cursor c = null; mDataList.clear();// 清空数据列表 - try { - // 通过ContentResolver从Content Provider查询数据内容 + try {// 通过ContentResolver从Content Provider查询数据内容 c = mContentResolver.query(Notes.CONTENT_DATA_URI, SqlData.PROJECTION_DATA, "(note_id=?)", new String[] { String.valueOf(mId) }, null); if (c != null) { - if (c.getCount() == 0) { - // 数据内容为空 + if (c.getCount() == 0) {// 数据内容为空 Log.w(TAG, "it seems that the note has not data"); return; } @@ -445,24 +442,22 @@ public class SqlNote { public void commit(boolean validateVersion) { if (mIsCreate) {// 判断当前对象是否为新建对象。如果是,则执行以下代码块。 - if (mId == INVALID_ID && mDiffNoteValues.containsKey(NoteColumns.ID)) { - // 如果当前对象的id为无效id,并且mDiffNoteValues中包含NoteColumns.ID这个键,则移除该键值对。 + if (mId == INVALID_ID && mDiffNoteValues.containsKey(NoteColumns.ID)) {// 如果当前对象的id为无效id,并且mDiffNoteValues中包含NoteColumns.ID这个键,则移除该键值对。 mDiffNoteValues.remove(NoteColumns.ID); - } - // 通过ContentResolver向Notes表中插入一条记录,第一部分是插入的uri。 + }// 通过ContentResolver向Notes表中插入一条记录,第一部分是插入的uri。 Uri uri = mContentResolver.insert(Notes.CONTENT_NOTE_URI, mDiffNoteValues); try {// 试图从uri的路径段中获取note的id。 - // 将获取到的id转换为long类型并赋值给mId。如果转换失败,会抛出NumberFormatException异常。 - mId = Long.valueOf(uri.getPathSegments().get(1)); - } catch (NumberFormatException e) { - // 记录错误日志,创建note失败。抛出ActionFailureException异常,异常信息为create note failed。 + + mId = Long.valueOf(uri.getPathSegments().get(1));// 将获取到的id转换为long类型并赋值给mId。如果转换失败,会抛出NumberFormatException异常。 + } catch (NumberFormatException e) {// 记录错误日志,创建note失败。抛出ActionFailureException异常,异常信息为create note failed。 + Log.e(TAG, "Get note id error :" + e.toString()); throw new ActionFailureException("create note failed"); } if (mId == 0) {// 如果mId仍然为0,抛出一个IllegalStateException异常,创建thread id失败。 throw new IllegalStateException("Create thread id failed"); - } - // 如果mType等于Notes.TYPE_NOTE,执行以下代码块。 + }// 如果mType等于Notes.TYPE_NOTE,执行以下代码块。 + if (mType == Notes.TYPE_NOTE) { for (SqlData sqlData : mDataList) { sqlData.commit(mId, false, -1); @@ -471,28 +466,28 @@ public class SqlNote { } else { if (mId <= 0 && mId != Notes.ID_ROOT_FOLDER && mId != Notes.ID_CALL_RECORD_FOLDER) { Log.e(TAG, "No such note");// 打印错误日志"No such note - // 抛出异常IllegalStateException - throw new IllegalStateException("Try to update note with invalid id"); + + throw new IllegalStateException("Try to update note with invalid id"); // 抛出异常IllegalStateException } if (mDiffNoteValues.size() > 0) { mVersion ++; int result = 0; if (!validateVersion) { - //更新Notes表中的记录,将mDiffNoteValues中的键值对更新到Notes表中 - result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "(" + + result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "("//更新Notes表中的记录,将mDiffNoteValues中的键值对更新到Notes表中 + NoteColumns.ID + "=?)", new String[] { String.valueOf(mId) }); } else { - // 更新Notes表中的记录,将mDiffNoteValues中的键值对更新到Notes表中 - result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "(" + + result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "("// 更新Notes表中的记录,将mDiffNoteValues中的键值对更新到Notes表中 + NoteColumns.ID + "=?) AND (" + NoteColumns.VERSION + "<=?)", new String[] { String.valueOf(mId), String.valueOf(mVersion) }); } - // 如果result为0,即没有更新记录,则打印警告日志 - if (result == 0) { + + if (result == 0) {// 如果result为0,即没有更新记录,则打印警告日志 Log.w(TAG, "there is no update. maybe user updates note when syncing"); } } @@ -502,9 +497,9 @@ public class SqlNote { sqlData.commit(mId, validateVersion, mVersion); } } - } + }// refresh local info - // refresh local info + loadFromCursor(mId); if (mType == Notes.TYPE_NOTE) loadDataContent();