Update SqlData.java

dev
ph2y8awtk 2 years ago
parent 05df45cbfc
commit cac3930263

@ -154,35 +154,45 @@ public class SqlData {
return js;
}
/*
* commit
*/
/**
*
*
* @param noteId ID
* @param validateVersion
* @param version
*/
public void commit(long noteId, boolean validateVersion, long version) {
// 如果是新创建的数据
if (mIsCreate) {
// 如果数据 ID 无效且差异数据集合包含数据 ID则移除数据 ID
if (mDataId == INVALID_ID && mDiffDataValues.containsKey(DataColumns.ID)) {
mDiffDataValues.remove(DataColumns.ID);
}
// 设置笔记 ID将差异数据插入到数据表
mDiffDataValues.put(DataColumns.NOTE_ID, noteId);
Uri uri = mContentResolver.insert(Notes.CONTENT_DATA_URI, mDiffDataValues);
try {
// 从 URI 中获取插入的数据 ID
mDataId = Long.valueOf(uri.getPathSegments().get(1));
} catch (NumberFormatException e) {
Log.e(TAG, "Get note id error :" + e.toString());
throw new ActionFailureException("create note failed");
}
} else {
// 如果有数据更新
if (mDiffDataValues.size() > 0) {
int result = 0;
if (!validateVersion) {
// 如果不需要验证版本,直接更新数据表
result = mContentResolver.update(ContentUris.withAppendedId(
Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues, null, null);
} else {
// 需要验证版本,构造 SQL 语句进行更新
result = mContentResolver.update(ContentUris.withAppendedId(
Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues,
" ? in (SELECT " + NoteColumns.ID + " FROM " + TABLE.NOTE
+ " WHERE " + NoteColumns.VERSION + "=?)", new String[] {
+ " WHERE " + NoteColumns.VERSION + "=?)", new String[]{
String.valueOf(noteId), String.valueOf(version)
});
}
@ -191,10 +201,12 @@ public class SqlData {
}
}
}
// 清空差异数据集合和创建标志
mDiffDataValues.clear();
mIsCreate = false;
}
/*
* id

Loading…
Cancel
Save