新批注了另外两个

data文件夹已批注完
pull/1/head
夏彦博 2 years ago
parent 1eafd04b5e
commit 16c1a52349

@ -27,7 +27,7 @@ import net.micode.notes.data.Notes.DataConstants;
import net.micode.notes.data.Notes.NoteColumns;
public class NotesDatabaseHelper extends SQLiteOpenHelper {
public class NotesDatabaseHelper extends SQLiteOpenHelper { //定义数据库相关的名称以及标签
private static final String DB_NAME = "note.db";
private static final int DB_VERSION = 4;
@ -42,7 +42,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
private static NotesDatabaseHelper mInstance;
private static final String CREATE_NOTE_TABLE_SQL =
private static final String CREATE_NOTE_TABLE_SQL =//规范定义数据库存储信息的格式以及组成部分
"CREATE TABLE " + TABLE.NOTE + "(" +
NoteColumns.ID + " INTEGER PRIMARY KEY," +
NoteColumns.PARENT_ID + " INTEGER NOT NULL DEFAULT 0," +
@ -85,7 +85,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/**
* Increase folder's note count when move note to the folder
*/
private static final String NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =
private static final String NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =//设置触发器在笔记集更新的时候增加数量1
"CREATE TRIGGER increase_folder_count_on_update "+
" AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE +
" BEGIN " +
@ -97,7 +97,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/**
* Decrease folder's note count when move note from folder
*/
private static final String NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =
private static final String NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =//类似的设置触发器在笔记集更新的时候减少数量1
"CREATE TRIGGER decrease_folder_count_on_update " +
" AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE +
" BEGIN " +
@ -110,7 +110,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/**
* Increase folder's note count when insert new note to the folder
*/
private static final String NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER =
private static final String NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER =//设置触发器在笔记集创建的时候增加数量1
"CREATE TRIGGER increase_folder_count_on_insert " +
" AFTER INSERT ON " + TABLE.NOTE +
" BEGIN " +
@ -122,7 +122,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/**
* Decrease folder's note count when delete note from the folder
*/
private static final String NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER =
private static final String NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER =//设置触发器,在笔记集删除文件的时候-1
"CREATE TRIGGER decrease_folder_count_on_delete " +
" AFTER DELETE ON " + TABLE.NOTE +
" BEGIN " +
@ -135,7 +135,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/**
* Update note's content when insert data with type {@link DataConstants#NOTE}
*/
private static final String DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER =
private static final String DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER =//设置触发器用于在笔记中数据更改时进行相应ID字段等的更新
"CREATE TRIGGER update_note_content_on_insert " +
" AFTER INSERT ON " + TABLE.DATA +
" WHEN new." + DataColumns.MIME_TYPE + "='" + DataConstants.NOTE + "'" +
@ -210,14 +210,14 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
super(context, DB_NAME, null, DB_VERSION);
}
public void createNoteTable(SQLiteDatabase db) {
public void createNoteTable(SQLiteDatabase db) {//创建并管理日志信息表
db.execSQL(CREATE_NOTE_TABLE_SQL);
reCreateNoteTableTriggers(db);
createSystemFolder(db);
Log.d(TAG, "note table has been created");
}
private void reCreateNoteTableTriggers(SQLiteDatabase db) {
private void reCreateNoteTableTriggers(SQLiteDatabase db) {//重置触发器
db.execSQL("DROP TRIGGER IF EXISTS increase_folder_count_on_update");
db.execSQL("DROP TRIGGER IF EXISTS decrease_folder_count_on_update");
db.execSQL("DROP TRIGGER IF EXISTS decrease_folder_count_on_delete");
@ -301,7 +301,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {//用于检查并进行数据库版本的更新,保障版本控制
boolean reCreateTriggers = false;
boolean skipV2 = false;

@ -35,7 +35,7 @@ import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.NotesDatabaseHelper.TABLE;
public class NotesProvider extends ContentProvider {
public class NotesProvider extends ContentProvider {//定义URL以及匹配规则
private static final UriMatcher mMatcher;
private NotesDatabaseHelper mHelper;
@ -86,12 +86,12 @@ public class NotesProvider extends ContentProvider {
}
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,//执行数据库查询操作
String sortOrder) {
Cursor c = null;
SQLiteDatabase db = mHelper.getReadableDatabase();
String id = null;
switch (mMatcher.match(uri)) {
switch (mMatcher.match(uri)) {//匹配数据库查询关键字
case URI_NOTE:
c = db.query(TABLE.NOTE, projection, selection, selectionArgs, null, null,
sortOrder);
@ -148,7 +148,7 @@ public class NotesProvider extends ContentProvider {
}
@Override
public Uri insert(Uri uri, ContentValues values) {
public Uri insert(Uri uri, ContentValues values) {//insert向数据库中插入一条数据信息值
SQLiteDatabase db = mHelper.getWritableDatabase();
long dataId = 0, noteId = 0, insertedId = 0;
switch (mMatcher.match(uri)) {
@ -182,7 +182,8 @@ public class NotesProvider extends ContentProvider {
}
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
public int delete(Uri uri, String selection, String[] selectionArgs) {//实现删除操作
/*这两个参数通常在一起使用以定义一个特定的删除操作。selection 定义了哪些数据应该被删除,而 selectionArgs 为 selection 中的占位符提供了具体的值。*/
int count = 0;
String id = null;
SQLiteDatabase db = mHelper.getWritableDatabase();
@ -228,7 +229,7 @@ public class NotesProvider extends ContentProvider {
}
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {//更新
int count = 0;
String id = null;
SQLiteDatabase db = mHelper.getWritableDatabase();

Loading…
Cancel
Save