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.
note/SqlData.java

147 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.
*/
java
// 导入所需的包
// ...(省略了导入语句,因为它们在前面的代码段中已给出)
// SqlData类用于处理与数据库中的特定数据项相关的操作
public class SqlData {
// 定义日志标签,用于调试和日志记录
private static final String TAG = SqlData.class.getSimpleName();
// 定义一个无效ID常量用于标识未设置或无效的ID
private static final int INVALID_ID = -99999;
// 定义要从数据库中检索的列的投影数组
public static final String[] PROJECTION_DATA = {
// ...(省略了列名,它们在前面的代码段中已给出)
};
// 定义投影数组中各列的索引以便在Cursor中快速访问
// ...(省略了列索引常量,它们在前面的代码段中已给出)
// 私有成员变量,用于存储与数据项相关的状态和信息
// ...(省略了成员变量声明,它们在前面的代码段中已给出)
// 构造方法用于创建新的SqlData实例
// 当isCreate为true时表示这是一个新创建的数据项否则它表示一个已存在的数据项
public SqlData(Context context) {
// ...(省略了构造方法体,它已经在前面的代码段中给出)
}
// 构造方法用于从Cursor加载已存在的数据项
public SqlData(Context context, Cursor c) {
// ...(省略了构造方法体,它已经在前面的代码段中给出)
}
// 私有方法用于从Cursor加载数据到成员变量中
private void loadFromCursor(Cursor c) {
// ...(省略了方法体,它已经在前面的代码段中给出)
}
// 公共方法用于设置数据项的内容根据传入的JSONObject更新成员变量和差异数据
public void setContent(JSONObject js) throws JSONException {
// ...(省略了方法体,但保留了注释说明)
// 这个方法首先检查JSONObject中是否包含特定的键并根据这些键的值更新成员变量和差异数据mDiffDataValues
}
// 公共方法用于获取数据项的内容并将其作为JSONObject返回
public JSONObject getContent() throws JSONException {
// ...(省略了方法体,但保留了注释说明)
// 如果这是一个新创建的数据项尚未插入数据库则记录错误并返回null
// 否则将数据项的内容构建为JSONObject并返回
}
// 公共方法,用于提交数据项到数据库
// 如果isCreate为true则插入新数据项否则更新现有数据项
public void commit(long noteId, boolean validateVersion, long version) {
// ...(省略了方法体,但保留了注释说明)
// 这个方法根据isCreate的值决定是插入新数据项还是更新现有数据项
// 如果validateVersion为true则在更新时检查版本以避免冲突
// 提交成功后清除差异数据并将isCreate设置为false
}
// 公共方法用于获取数据项的ID
public long getId() {
return mDataId;
}
}