From 661f6ab5b74246a40f5af83252db98941d5ea77a Mon Sep 17 00:00:00 2001 From: SYH <1017401752@qq.com> Date: Tue, 17 Dec 2024 12:54:08 +0800 Subject: [PATCH] 2 --- .../monkeybook/dao/BookContentBeanDao.java | 84 +++++++------- .../monke/monkeybook/dao/BookInfoBeanDao.java | 104 +++++++++--------- .../monkeybook/dao/BookShelfBeanDao.java | 48 ++++---- .../monkeybook/dao/ChapterListBeanDao.java | 76 ++++++------- .../com/monke/basemvplib/ApplicationTest.java | 13 ++- 5 files changed, 164 insertions(+), 161 deletions(-) diff --git a/app/src/main/java/com/monke/monkeybook/dao/BookContentBeanDao.java b/app/src/main/java/com/monke/monkeybook/dao/BookContentBeanDao.java index 92c5d2f..d93d879 100644 --- a/app/src/main/java/com/monke/monkeybook/dao/BookContentBeanDao.java +++ b/app/src/main/java/com/monke/monkeybook/dao/BookContentBeanDao.java @@ -1,13 +1,13 @@ //指定了当前类BookContentBeanDao所在的包路径,即com.monke.monkeybook.dao package com.monke.monkeybook.dao; //导入必要的类,包含GreenDAO、SQLite和Android数据库操作的相关类 -import android.database.Cursor; -import android.database.sqlite.SQLiteStatement; -import org.greenrobot.greendao.AbstractDao; -import org.greenrobot.greendao.Property; -import org.greenrobot.greendao.internal.DaoConfig; -import org.greenrobot.greendao.database.Database; -import org.greenrobot.greendao.database.DatabaseStatement; +import android.database.Cursor;// 导入Cursor类,用于数据库查询结果 +import android.database.sqlite.SQLiteStatement;// 导入SQLiteStatement类,用于预编译SQL语句 +import org.greenrobot.greendao.AbstractDao;// 导入AbstractDao类,这是GreenDAO的基类,用于实现DAO功能 +import org.greenrobot.greendao.Property;// 导入Property类,用于属性映射 +import org.greenrobot.greendao.internal.DaoConfig;// 导入DaoConfig类,包含DAO的配置 +import org.greenrobot.greendao.database.Database;// 导入Database类,代表数据库操作 +import org.greenrobot.greendao.database.DatabaseStatement;// 导入DatabaseStatement类,用于执行数据库语句 // 导入实体类 BookContentBean import com.monke.monkeybook.bean.BookContentBean; @@ -18,7 +18,7 @@ import com.monke.monkeybook.bean.BookContentBean; //继承自GreenDAO的AbstractDao类,BookContentBean为实体类,String为主键类型 public class BookContentBeanDao extends AbstractDao { //定义常量TABLENAME,表示该表的名称 - public static final String TABLENAME = "BOOK_CONTENT_BEAN"; + public static final String TABLENAME = "BOOK_CONTENT_BEAN";// 表名常量 /** * Properties of entity BookContentBean.
* Can be used for QueryBuilder and for referencing column names. @@ -26,10 +26,10 @@ public class BookContentBeanDao extends AbstractDao { */ // 定义实体类属性映射:对应数据库表字段名的属性 public static class Properties { - public final static Property DurChapterUrl = new Property(0, String.class, "durChapterUrl", true, "DUR_CHAPTER_URL"); - public final static Property DurChapterIndex = new Property(1, int.class, "durChapterIndex", false, "DUR_CHAPTER_INDEX"); - public final static Property DurCapterContent = new Property(2, String.class, "durCapterContent", false, "DUR_CAPTER_CONTENT"); - public final static Property Tag = new Property(3, String.class, "tag", false, "TAG"); + public final static Property DurChapterUrl = new Property(0, String.class, "durChapterUrl", true, "DUR_CHAPTER_URL");// 章节URL属性 + public final static Property DurChapterIndex = new Property(1, int.class, "durChapterIndex", false, "DUR_CHAPTER_INDEX");// 章节索引属性 + public final static Property DurCapterContent = new Property(2, String.class, "durCapterContent", false, "DUR_CAPTER_CONTENT");// 章节内容属性 + public final static Property Tag = new Property(3, String.class, "tag", false, "TAG");// 标签属性 }; //构造函数,传入DaoConfig,用于初始化DAO @@ -51,10 +51,10 @@ public class BookContentBeanDao extends AbstractDao { String constraint = ifNotExists? "IF NOT EXISTS ": ""; //使用SQL执行表创建语句 db.execSQL("CREATE TABLE " + constraint + "\"BOOK_CONTENT_BEAN\" (" + // - "\"DUR_CHAPTER_URL\" TEXT PRIMARY KEY NOT NULL ," + // 0: durChapterUrl - "\"DUR_CHAPTER_INDEX\" INTEGER NOT NULL ," + // 1: durChapterIndex - "\"DUR_CAPTER_CONTENT\" TEXT," + // 2: durCapterContent - "\"TAG\" TEXT);"); // 3: tag + "\"DUR_CHAPTER_URL\" TEXT PRIMARY KEY NOT NULL ," + // 0: durChapterUrl, 主键列 + "\"DUR_CHAPTER_INDEX\" INTEGER NOT NULL ," + // 1: durChapterIndex, 整数列 + "\"DUR_CAPTER_CONTENT\" TEXT," + // 2: durCapterContent,章节内容列 + "\"TAG\" TEXT);"); // 3: tag, 标签列 } /** Drops the underlying database table. @@ -62,73 +62,73 @@ public class BookContentBeanDao extends AbstractDao { */ public static void dropTable(Database db, boolean ifExists) { //使用SQL删除表,确保表存在时删除 - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"BOOK_CONTENT_BEAN\""; - db.execSQL(sql); + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"BOOK_CONTENT_BEAN\"";// 生成删除表的SQL语句 + db.execSQL(sql);// 执行删除表操作 } @Override protected final void bindValues(DatabaseStatement stmt, BookContentBean entity) { //清除绑定的值,确保每次绑定时都是干净的 - stmt.clearBindings(); + stmt.clearBindings();// 清除先前绑定的参数 //绑定durChapterUrl字段到SQL语句的第一个位置 - String durChapterUrl = entity.getDurChapterUrl(); + String durChapterUrl = entity.getDurChapterUrl();// 获取durChapterUrl属性值 if (durChapterUrl != null) { //将章节URL字符串绑定到SQL语句的第一个位置 - stmt.bindString(1, durChapterUrl); + stmt.bindString(1, durChapterUrl);// 将durChapterUrl绑定到SQL语句的第一个参数 } //绑定durChapterIndex字段到SQL语句的第二个位置 stmt.bindLong(2, entity.getDurChapterIndex());//将章节索引绑定到SQL语句的第二个位置 //绑定durCapterContent字段到SQL语句的第三个位置 - String durCapterContent = entity.getDurCapterContent(); + String durCapterContent = entity.getDurCapterContent();// 获取durCapterContent属性值 if (durCapterContent != null) { //将章节内容绑定到SQL语句的第三个位置 - stmt.bindString(3, durCapterContent); + stmt.bindString(3, durCapterContent);// 将durCapterContent绑定到SQL语句的第三个参数 } //绑定tag字段到SQL语句的第四个位置 - String tag = entity.getTag(); + String tag = entity.getTag();// 获取tag属性值 if (tag != null) { //将标签绑定到SQL语句的第四个位置 - stmt.bindString(4, tag); + stmt.bindString(4, tag);// 将tag绑定到SQL语句的第四个参数 } } @Override protected final void bindValues(SQLiteStatement stmt, BookContentBean entity) { //清除绑定的值,确保每次绑定时都是干净的 - stmt.clearBindings(); + stmt.clearBindings();// 清除先前绑定的参数 //绑定durChapterUrl字段到SQL语句的第一个位置 - String durChapterUrl = entity.getDurChapterUrl(); + String durChapterUrl = entity.getDurChapterUrl();// 获取durChapterUrl属性值 if (durChapterUrl != null) { //将章节URL字符串绑定到SQL语句的第一个位置 - stmt.bindString(1, durChapterUrl); + stmt.bindString(1, durChapterUrl);// 将durChapterUrl绑定到SQL语句的第一个参数 } //绑定durChapterIndex字段到SQL语句的第二个位置 stmt.bindLong(2, entity.getDurChapterIndex()); //将章节索引绑定到SQL语句的第二个位置 //绑定durCapterContent字段到SQL语句的第三个位置 - String durCapterContent = entity.getDurCapterContent(); + String durCapterContent = entity.getDurCapterContent();// 获取durCapterContent属性值 if (durCapterContent != null) { //将章节内容绑定到SQL语句的第三个位置 - stmt.bindString(3, durCapterContent); + stmt.bindString(3, durCapterContent);// 将durCapterContent绑定到SQL语句的第三个参数 } //绑定tag字段到SQL语句的第四个位置 - String tag = entity.getTag(); + String tag = entity.getTag();// 获取tag属性值 if (tag != null) { //将标签绑定到SQL语句的第四个位置 - stmt.bindString(4, tag); + stmt.bindString(4, tag);// 将tag绑定到SQL语句的第四个参数 } } @Override public String readKey(Cursor cursor, int offset) { //从Cursor中读取主键(durChapterUrl),若为null则返回null - return cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0); + return cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0);// 根据游标读取主键值 } @Override @@ -140,38 +140,38 @@ public class BookContentBeanDao extends AbstractDao { cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // durCapterContent cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3) // tag ); - return entity; + return entity;// 返回创建的实体对象 } @Override public void readEntity(Cursor cursor, BookContentBean entity, int offset) { //从Cursor中读取值并设置到BookContentBean对象的相应属性中 - entity.setDurChapterUrl(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0)); - entity.setDurChapterIndex(cursor.getInt(offset + 1)); - entity.setDurCapterContent(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); - entity.setTag(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setDurChapterUrl(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));// 设置durChapterUrl属性 + entity.setDurChapterIndex(cursor.getInt(offset + 1));// 设置durChapterIndex属性 + entity.setDurCapterContent(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));// 设置durCapterContent属性 + entity.setTag(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));// 设置tag属性 } @Override protected final String updateKeyAfterInsert(BookContentBean entity, long rowId) { //返回更新时需要的主键字段,这里是durChapterUrl - return entity.getDurChapterUrl(); + return entity.getDurChapterUrl();// 返回用于更新的主键 } @Override public String getKey(BookContentBean entity) { //获取实体对象的主键值,返回durChapterUrl if(entity != null) { - return entity.getDurChapterUrl(); + return entity.getDurChapterUrl();// 返回实体的主键值 } else { - return null; + return null;// 如果实体为空,返回null } } @Override protected final boolean isEntityUpdateable() { //指示实体是否可以被更新,这里返回true,表示支持更新 - return true; + return true;// 表示该实体可被更新 } } diff --git a/app/src/main/java/com/monke/monkeybook/dao/BookInfoBeanDao.java b/app/src/main/java/com/monke/monkeybook/dao/BookInfoBeanDao.java index ac4edfb..d090565 100644 --- a/app/src/main/java/com/monke/monkeybook/dao/BookInfoBeanDao.java +++ b/app/src/main/java/com/monke/monkeybook/dao/BookInfoBeanDao.java @@ -44,12 +44,12 @@ public class BookInfoBeanDao extends AbstractDao { //构造函数,使用DaoConfig配置创建DAO对象 public BookInfoBeanDao(DaoConfig config) { - super(config); + super(config);// 调用父类的构造函数,传入DaoConfig配置 } //构造函数,使用DaoConfig和DaoSession配置创建DAO对象 public BookInfoBeanDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); + super(config, daoSession);// 调用父类的构造函数,传入DaoConfig和DaoSession配置 } /** Creates the underlying database table. @@ -85,64 +85,64 @@ public class BookInfoBeanDao extends AbstractDao { //将BookInfoBean实体对象的值绑定到DatabaseStatement对象中 protected final void bindValues(DatabaseStatement stmt, BookInfoBean entity) { //清除绑定的值,确保每次绑定时都是干净的 - stmt.clearBindings(); + stmt.clearBindings();// 清除之前的绑定值 //绑定name字段到SQL语句的第一个位置 - String name = entity.getName(); + String name = entity.getName();// 获取name属性值 if (name != null) { //将书名绑定到SQL语句的第一个位置 - stmt.bindString(1, name); + stmt.bindString(1, name);// 将name绑定到SQL语句的第一个位置 } //绑定tag字段到SQL语句的第二个位置 - String tag = entity.getTag(); + String tag = entity.getTag();// 获取tag属性值 if (tag != null) { //将标签绑定到SQL语句的第二个位置 - stmt.bindString(2, tag); + stmt.bindString(2, tag);// 将tag绑定到SQL语句的第二个位置 } //绑定noteUrl字段到SQL语句的第三个位置 - String noteUrl = entity.getNoteUrl(); + String noteUrl = entity.getNoteUrl(); // 获取noteUrl属性值 if (noteUrl != null) { //将书籍URL绑定到SQL语句的第三个位置 - stmt.bindString(3, noteUrl); + stmt.bindString(3, noteUrl);// 将noteUrl绑定到SQL语句的第三个位置 } //绑定chapterUrl字段到SQL语句的第四个位置 - String chapterUrl = entity.getChapterUrl(); + String chapterUrl = entity.getChapterUrl();// 获取chapterUrl属性值 if (chapterUrl != null) { //将章节URL绑定到SQL语句的第四个位置 - stmt.bindString(4, chapterUrl); + stmt.bindString(4, chapterUrl);// 将chapterUrl绑定到SQL语句的第四个位置 } //将最后刷新时间(long 类型)绑定到SQL语句的第五个位置 - stmt.bindLong(5, entity.getFinalRefreshData()); + stmt.bindLong(5, entity.getFinalRefreshData()); // 将finalRefreshData绑定到SQL语句的第五个位置 //绑定coverUrl字段到SQL语句的第六个位置 - String coverUrl = entity.getCoverUrl(); + String coverUrl = entity.getCoverUrl();// 获取coverUrl属性值 if (coverUrl != null) { //将封面图URL绑定到SQL语句的第六个位置 - stmt.bindString(6, coverUrl); + stmt.bindString(6, coverUrl);// 将coverUrl绑定到SQL语句的第六个位置 } //绑定author字段到SQL语句的第七个位置 - String author = entity.getAuthor(); + String author = entity.getAuthor();// 获取author属性值 if (author != null) { //将作者绑定到SQL语句的第七个位置 - stmt.bindString(7, author); + stmt.bindString(7, author);// 将author绑定到SQL语句的第七个位置 } //绑定introduce字段到SQL语句的第八个位置 - String introduce = entity.getIntroduce(); + String introduce = entity.getIntroduce();// 获取introduce属性值 if (introduce != null) { //将简介绑定到SQL语句的第八个位置 - stmt.bindString(8, introduce); + stmt.bindString(8, introduce);// 将introduce绑定到SQL语句的第八个位置 } //绑定origin字段到SQL语句的第九个位置 - String origin = entity.getOrigin(); + String origin = entity.getOrigin();// 获取origin属性值 if (origin != null) { //将来源绑定到SQL语句的第九个位置 - stmt.bindString(9, origin); + stmt.bindString(9, origin);// 将origin绑定到SQL语句的第九个位置 } } @@ -153,53 +153,53 @@ public class BookInfoBeanDao extends AbstractDao { stmt.clearBindings(); //绑定name字段值 - String name = entity.getName(); + String name = entity.getName();// 获取name属性值 if (name != null) { - stmt.bindString(1, name); + stmt.bindString(1, name);// 将name绑定到SQL语句的第一个位置 } //绑定tag字段值 - String tag = entity.getTag(); + String tag = entity.getTag();// 获取tag属性值 if (tag != null) { - stmt.bindString(2, tag); + stmt.bindString(2, tag);// 将tag绑定到SQL语句的第二个位置 } //绑定noteUrl字段值 - String noteUrl = entity.getNoteUrl(); + String noteUrl = entity.getNoteUrl();// 获取noteUrl属性值 if (noteUrl != null) { - stmt.bindString(3, noteUrl); + stmt.bindString(3, noteUrl);// 将noteUrl绑定到SQL语句的第三个位置 } //绑定chapterUrl字段值 - String chapterUrl = entity.getChapterUrl(); + String chapterUrl = entity.getChapterUrl();// 获取chapterUrl属性值 if (chapterUrl != null) { - stmt.bindString(4, chapterUrl); + stmt.bindString(4, chapterUrl);// 将chapterUrl绑定到SQL语句的第四个位置 } //绑定finalRefreshData字段值 - stmt.bindLong(5, entity.getFinalRefreshData()); + stmt.bindLong(5, entity.getFinalRefreshData());// 将finalRefreshData绑定到SQL语句的第五个位置 //绑定coverUrl字段值 - String coverUrl = entity.getCoverUrl(); + String coverUrl = entity.getCoverUrl();// 获取coverUrl属性值 if (coverUrl != null) { - stmt.bindString(6, coverUrl); + stmt.bindString(6, coverUrl);// 将coverUrl绑定到SQL语句的第六个位置 } //绑定author字段值 - String author = entity.getAuthor(); + String author = entity.getAuthor();// 获取author属性值 if (author != null) { - stmt.bindString(7, author); + stmt.bindString(7, author);// 将author绑定到SQL语句的第七个位置 } //绑定introduce字段值 - String introduce = entity.getIntroduce(); + String introduce = entity.getIntroduce();// 获取introduce属性值 if (introduce != null) { - stmt.bindString(8, introduce); + stmt.bindString(8, introduce);// 将introduce绑定到SQL语句的第八个参数 } //绑定origin字段值 - String origin = entity.getOrigin(); + String origin = entity.getOrigin();// 获取来源属性值 if (origin != null) { - stmt.bindString(9, origin); + stmt.bindString(9, origin);// 将来源绑定到SQL语句的第九个参数 } } @@ -207,7 +207,7 @@ public class BookInfoBeanDao extends AbstractDao { //从Cursor中读取主键 public String readKey(Cursor cursor, int offset) { //主键在第三列(offset + 2),如果为空返回null,否则返回字符串 - return cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2); + return cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2);// 读取主键noteUrl字段 } @Override @@ -226,28 +226,28 @@ public class BookInfoBeanDao extends AbstractDao { cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8) // origin ); //返回创建好的BookInfoBean对象 - return entity; + return entity;// 返回读取到的实体对象 } @Override //将Cursor中的数据读取到已存在的BookInfoBean实体中 public void readEntity(Cursor cursor, BookInfoBean entity, int offset) { - entity.setName(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));//name - entity.setTag(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));//tag - entity.setNoteUrl(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));//noteUrl - entity.setChapterUrl(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));//chapterUrl - entity.setFinalRefreshData(cursor.getLong(offset + 4));//finalRefreshData - entity.setCoverUrl(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));//coverUrl - entity.setAuthor(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));//author - entity.setIntroduce(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));//introduce - entity.setOrigin(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8));//origin + entity.setName(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));//设置name + entity.setTag(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));//设置tag + entity.setNoteUrl(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));//设置noteUrl + entity.setChapterUrl(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));//设置chapterUrl + entity.setFinalRefreshData(cursor.getLong(offset + 4));//设置finalRefreshData + entity.setCoverUrl(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));//设置coverUrl + entity.setAuthor(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));//设置author + entity.setIntroduce(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));//设置introduce + entity.setOrigin(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8));//设置origin } @Override //插入数据后更新主键 protected final String updateKeyAfterInsert(BookInfoBean entity, long rowId) { //使用noteUrl作为主键 - return entity.getNoteUrl(); + return entity.getNoteUrl();// 返回用于更新的主键 } @Override @@ -255,9 +255,9 @@ public class BookInfoBeanDao extends AbstractDao { public String getKey(BookInfoBean entity) { if(entity != null) { //返回noteUrl作为主键 - return entity.getNoteUrl(); + return entity.getNoteUrl();// 返回实体的主键noteUrl } else { - return null; + return null;// 如果实体为空,返回null } } @@ -265,7 +265,7 @@ public class BookInfoBeanDao extends AbstractDao { //是否可更新实体 protected final boolean isEntityUpdateable() { //可更新 - return true; + return true;// 表示该实体可更新 } } diff --git a/app/src/main/java/com/monke/monkeybook/dao/BookShelfBeanDao.java b/app/src/main/java/com/monke/monkeybook/dao/BookShelfBeanDao.java index b0eb9f3..b2afea4 100644 --- a/app/src/main/java/com/monke/monkeybook/dao/BookShelfBeanDao.java +++ b/app/src/main/java/com/monke/monkeybook/dao/BookShelfBeanDao.java @@ -36,12 +36,12 @@ public class BookShelfBeanDao extends AbstractDao { // 构造函数,使用DaoConfig配置初始化Dao public BookShelfBeanDao(DaoConfig config) { - super(config); + super(config);// 调用父类构造函数进行初始化 } // 构造函数,使用DaoConfig和DaoSession配置初始化Dao public BookShelfBeanDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); + super(config, daoSession);// 调用父类构造函数进行初始化 } /** Creates the underlying database table. @@ -66,27 +66,27 @@ public class BookShelfBeanDao extends AbstractDao { // 删除BOOK_SHELF_BEAN表的方法 public static void dropTable(Database db, boolean ifExists) { // 构造删除表的SQL语句 - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"BOOK_SHELF_BEAN\""; + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"BOOK_SHELF_BEAN\"";// 如果指定ifExists,则添加条件 // 执行SQL语句删除表 - db.execSQL(sql); + db.execSQL(sql);// 执行删除表的SQL语句 } @Override // 将BookShelfBean实体对象的值绑定到DatabaseStatement语句中 protected final void bindValues(DatabaseStatement stmt, BookShelfBean entity) { // 清除之前的绑定 - stmt.clearBindings(); + stmt.clearBindings();// 清除绑定,以保证每次都是干净的 - String noteUrl = entity.getNoteUrl(); + String noteUrl = entity.getNoteUrl(); // 获取noteUrl属性值 if (noteUrl != null) { // 绑定noteUrl值到第一个参数位置 - stmt.bindString(1, noteUrl); + stmt.bindString(1, noteUrl);// 将noteUrl绑定到SQL语句的第一个位置 } stmt.bindLong(2, entity.getDurChapter()); // 绑定durChapter值到第二个参数位置 stmt.bindLong(3, entity.getDurChapterPage()); // 绑定durChapterPage值到第三个参数位置 stmt.bindLong(4, entity.getFinalDate()); // 绑定finalDate值到第四个参数位置 - String tag = entity.getTag(); + String tag = entity.getTag();// 获取tag属性值 if (tag != null) { stmt.bindString(5, tag); // 绑定tag值到第五个参数位置 } @@ -96,21 +96,21 @@ public class BookShelfBeanDao extends AbstractDao { // 将BookShelfBean实体对象的值绑定到SQLiteStatement语句中,与上一个方法功能类似,只是对象不同 protected final void bindValues(SQLiteStatement stmt, BookShelfBean entity) { // 清除之前的绑定 - stmt.clearBindings(); + stmt.clearBindings();// 清除绑定,以保证每次都是干净的 - String noteUrl = entity.getNoteUrl(); + String noteUrl = entity.getNoteUrl();// 获取noteUrl属性值 if (noteUrl != null) { // 绑定noteUrl值到第一个参数位置 - stmt.bindString(1, noteUrl); + stmt.bindString(1, noteUrl);// 将noteUrl绑定到SQL语句的第一个位置 } stmt.bindLong(2, entity.getDurChapter()); // 绑定durChapter值到第二个参数位置 stmt.bindLong(3, entity.getDurChapterPage()); // 绑定durChapterPage值到第三个参数位置 stmt.bindLong(4, entity.getFinalDate()); // 绑定finalDate值到第四个参数位置 - String tag = entity.getTag(); + String tag = entity.getTag();// 获取tag属性值 if (tag != null) { // 绑定tag值到第五个参数位置 - stmt.bindString(5, tag); + stmt.bindString(5, tag);// 将tag绑定到SQL语句的第五个位置 } } @@ -118,7 +118,7 @@ public class BookShelfBeanDao extends AbstractDao { // 从游标中读取主键 public String readKey(Cursor cursor, int offset) { // 从偏移量offset+0的位置读取主键值,如果为空返回null,否则返回字符串 - return cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0); + return cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0);// noteUrl是主键 } @Override @@ -133,24 +133,24 @@ public class BookShelfBeanDao extends AbstractDao { cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4) // tag ); // 返回创建好的BookShelfBean对象 - return entity; + return entity;// 返回读取到的实体对象 } @Override // 将游标中的数据读取到已存在的BookShelfBean实体中 public void readEntity(Cursor cursor, BookShelfBean entity, int offset) { - entity.setNoteUrl(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0)); // noteUrl - entity.setDurChapter(cursor.getInt(offset + 1)); // durChapter - entity.setDurChapterPage(cursor.getInt(offset + 2)); // durChapterPage - entity.setFinalDate(cursor.getLong(offset + 3)); // finalDate - entity.setTag(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); // tag + entity.setNoteUrl(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0)); // 设置noteUrl + entity.setDurChapter(cursor.getInt(offset + 1)); // 设置durChapter + entity.setDurChapterPage(cursor.getInt(offset + 2)); // 设置durChapterPage + entity.setFinalDate(cursor.getLong(offset + 3)); // 设置finalDate + entity.setTag(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); // 设置tag } @Override // 插入数据后更新主键 protected final String updateKeyAfterInsert(BookShelfBean entity, long rowId) { // 返回noteUrl作为主键 - return entity.getNoteUrl(); + return entity.getNoteUrl();// 用于更新的主键值 } @Override @@ -158,9 +158,9 @@ public class BookShelfBeanDao extends AbstractDao { public String getKey(BookShelfBean entity) { if(entity != null) { // 返回noteUrl作为主键 - return entity.getNoteUrl(); + return entity.getNoteUrl();// 返回实体的主键值 } else { - return null; + return null;// 如果实体为空,则返回null } } @@ -168,7 +168,7 @@ public class BookShelfBeanDao extends AbstractDao { // 判断实体是否可更新 protected final boolean isEntityUpdateable() { // 返回true,表示实体可更新 - return true; + return true;// 该实体类型支持更新 } } diff --git a/app/src/main/java/com/monke/monkeybook/dao/ChapterListBeanDao.java b/app/src/main/java/com/monke/monkeybook/dao/ChapterListBeanDao.java index fc4de8e..ed45b20 100644 --- a/app/src/main/java/com/monke/monkeybook/dao/ChapterListBeanDao.java +++ b/app/src/main/java/com/monke/monkeybook/dao/ChapterListBeanDao.java @@ -11,22 +11,24 @@ import org.greenrobot.greendao.database.Database; // 导入Database类,GreenDa import org.greenrobot.greendao.database.DatabaseStatement; // 导入DatabaseStatement类,用于执行SQL语句 // 导入ChapterListBean类,这是数据库操作的对象 -import com.monke.monkeybook.bean.ChapterListBean; +import com.monke.monkeybook.bean.ChapterListBean;// 导入ChapterListBean实体类 // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. /** * DAO for table "CHAPTER_LIST_BEAN". + * 该类是用于操作"CHAPTER_LIST_BEAN"表的DAO类 */ // ChapterListBeanDao类继承AbstractDao,操作ChapterListBean对象,主键类型为String public class ChapterListBeanDao extends AbstractDao { // 数据库表名常量 - public static final String TABLENAME = "CHAPTER_LIST_BEAN"; + public static final String TABLENAME = "CHAPTER_LIST_BEAN";// 定义常量,表示数据库表的名称 /** * Properties of entity ChapterListBean.
* Can be used for QueryBuilder and for referencing column names. */ public static class Properties { + // 定义实体类属性映射,指向数据库表中的字段 public final static Property NoteUrl = new Property(0, String.class, "noteUrl", false, "NOTE_URL"); // 属性0:noteUrl,String类型,非主键,数据库列名NOTE_URL public final static Property DurChapterIndex = new Property(1, int.class, "durChapterIndex", false, "DUR_CHAPTER_INDEX"); // 属性1:durChapterIndex,int类型,非主键,数据库列名DUR_CHAPTER_INDEX public final static Property DurChapterUrl = new Property(2, String.class, "durChapterUrl", true, "DUR_CHAPTER_URL"); // 属性2:durChapterUrl,String类型,主键,数据库列名DUR_CHAPTER_URL @@ -37,19 +39,19 @@ public class ChapterListBeanDao extends AbstractDao { // 构造函数,使用DaoConfig配置初始化Dao public ChapterListBeanDao(DaoConfig config) { - super(config); + super(config);// 调用父类构造函数初始化DAO对象 } // 构造函数,使用DaoConfig和DaoSession配置初始化Dao public ChapterListBeanDao(DaoConfig config, DaoSession daoSession) { - super(config, daoSession); + super(config, daoSession);// 调用父类构造函数初始化DAO对象 } /** Creates the underlying database table. */ // 创建CHAPTER_LIST_BEAN表的方法 public static void createTable(Database db, boolean ifNotExists) { // 根据ifNotExists判断是否需要添加"IF NOT EXISTS"条件 - String constraint = ifNotExists? "IF NOT EXISTS ": ""; + String constraint = ifNotExists? "IF NOT EXISTS ": "";// 如果ifNotExists为真,则添加条件 // 执行SQL语句创建表 db.execSQL("CREATE TABLE " + constraint + "\"CHAPTER_LIST_BEAN\" (" + // "\"NOTE_URL\" TEXT," + // NOTE_URL字段,TEXT类型 @@ -66,47 +68,47 @@ public class ChapterListBeanDao extends AbstractDao { // 删除CHAPTER_LIST_BEAN表的方法 public static void dropTable(Database db, boolean ifExists) { // 构造删除表的SQL语句 - String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"CHAPTER_LIST_BEAN\""; + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"CHAPTER_LIST_BEAN\"";// 如果ifExists为真,则加上条件 // 执行SQL语句删除表 - db.execSQL(sql); + db.execSQL(sql);// 执行删除表的SQL语句 } @Override // 将ChapterListBean实体对象的值绑定到DatabaseStatement语句中 protected final void bindValues(DatabaseStatement stmt, ChapterListBean entity) { // 清除之前的绑定 - stmt.clearBindings(); + stmt.clearBindings();// 确保每次绑定之前清除旧的绑定 - String noteUrl = entity.getNoteUrl(); + String noteUrl = entity.getNoteUrl();// 获取noteUrl属性值 if (noteUrl != null) { // 绑定noteUrl值到第一个参数位置 - stmt.bindString(1, noteUrl); + stmt.bindString(1, noteUrl);// 将noteUrl绑定到SQL语句的第一个位置 } // 绑定durChapterIndex值到第二个参数位置 - stmt.bindLong(2, entity.getDurChapterIndex()); + stmt.bindLong(2, entity.getDurChapterIndex());// 将durChapterIndex绑定到SQL语句的第二个位置 - String durChapterUrl = entity.getDurChapterUrl(); + String durChapterUrl = entity.getDurChapterUrl();// 获取durChapterUrl属性值 if (durChapterUrl != null) { // 绑定durChapterUrl值到第三个参数位置 - stmt.bindString(3, durChapterUrl); + stmt.bindString(3, durChapterUrl);// 将durChapterUrl绑定到SQL语句的第三个位置 } - String durChapterName = entity.getDurChapterName(); + String durChapterName = entity.getDurChapterName();// 获取durChapterName属性值 if (durChapterName != null) { // 绑定durChapterName值到第四个参数位置 - stmt.bindString(4, durChapterName); + stmt.bindString(4, durChapterName);// 将durChapterName绑定到SQL语句的第四个位置 } - String tag = entity.getTag(); + String tag = entity.getTag();// 获取tag属性值 if (tag != null) { // 绑定tag值到第五个参数位置 - stmt.bindString(5, tag); + stmt.bindString(5, tag);// 将tag绑定到SQL语句的第五个位置 } - Boolean hasCache = entity.getHasCache(); + Boolean hasCache = entity.getHasCache();// 获取hasCache属性值 if (hasCache != null) { // 绑定hasCache值到第六个参数位置,true为1,false为0 - stmt.bindLong(6, hasCache ? 1L: 0L); + stmt.bindLong(6, hasCache ? 1L: 0L);// 将hasCache绑定到SQL语句的第六个位置(布尔值转为整数) } } @@ -114,38 +116,38 @@ public class ChapterListBeanDao extends AbstractDao { // 将ChapterListBean实体对象的值绑定到SQLiteStatement语句中,与上一个方法功能类似,只是对象不同 protected final void bindValues(SQLiteStatement stmt, ChapterListBean entity) { // 清除之前的绑定 - stmt.clearBindings(); + stmt.clearBindings();// 确保每次绑定之前清除旧的绑定 - String noteUrl = entity.getNoteUrl(); + String noteUrl = entity.getNoteUrl();// 获取noteUrl属性值 if (noteUrl != null) { // 绑定noteUrl值到第一个参数位置 - stmt.bindString(1, noteUrl); + stmt.bindString(1, noteUrl);// 将noteUrl绑定到SQL语句的第一个位置 } // 绑定durChapterIndex值到第二个参数位置 - stmt.bindLong(2, entity.getDurChapterIndex()); + stmt.bindLong(2, entity.getDurChapterIndex());// 将durChapterIndex绑定到SQL语句的第二个位置 - String durChapterUrl = entity.getDurChapterUrl(); + String durChapterUrl = entity.getDurChapterUrl();// 获取durChapterUrl属性值 if (durChapterUrl != null) { // 绑定durChapterUrl值到第三个参数位置 - stmt.bindString(3, durChapterUrl); + stmt.bindString(3, durChapterUrl);// 将durChapterUrl绑定到SQL语句的第三个位置 } - String durChapterName = entity.getDurChapterName(); + String durChapterName = entity.getDurChapterName();// 获取durChapterName属性值 if (durChapterName != null) { // 绑定durChapterName值到第四个参数位置 - stmt.bindString(4, durChapterName); + stmt.bindString(4, durChapterName);// 将durChapterName绑定到SQL语句的第四个位置 } - String tag = entity.getTag(); + String tag = entity.getTag();// 获取tag属性值 if (tag != null) { // 绑定tag值到第五个参数位置 - stmt.bindString(5, tag); + stmt.bindString(5, tag);// 将tag绑定到SQL语句的第五个位置 } - Boolean hasCache = entity.getHasCache(); + Boolean hasCache = entity.getHasCache();// 获取hasCache属性值 if (hasCache != null) { // 绑定hasCache值到第六个参数位置,true为1,false为0 - stmt.bindLong(6, hasCache ? 1L: 0L); + stmt.bindLong(6, hasCache ? 1L: 0L);// 将hasCache绑定到SQL语句的第六个位置(布尔值转为整数) } } @@ -153,7 +155,7 @@ public class ChapterListBeanDao extends AbstractDao { // 从游标中读取主键 public String readKey(Cursor cursor, int offset) { // 从偏移量offset+2的位置读取主键值,如果为空返回null,否则返回字符串 - return cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2); + return cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2);// 返回durChapterUrl作为主键 } @Override @@ -169,7 +171,7 @@ public class ChapterListBeanDao extends AbstractDao { cursor.isNull(offset + 5) ? null : cursor.getShort(offset + 5) != 0 // hasCache 将short转换为boolean ); // 返回创建好的ChapterListBean对象 - return entity; + return entity;// 返回读取到的实体对象 } @Override @@ -187,7 +189,7 @@ public class ChapterListBeanDao extends AbstractDao { // 插入数据后更新主键 protected final String updateKeyAfterInsert(ChapterListBean entity, long rowId) { // 返回durChapterUrl作为主键 - return entity.getDurChapterUrl(); + return entity.getDurChapterUrl();// 用于更新的主键值 } @Override @@ -195,9 +197,9 @@ public class ChapterListBeanDao extends AbstractDao { public String getKey(ChapterListBean entity) { if(entity != null) { // 返回durChapterUrl作为主键 - return entity.getDurChapterUrl(); + return entity.getDurChapterUrl();// 返回实体的主键值 } else { - return null; + return null; // 实体为空,返回null } } @@ -205,7 +207,7 @@ public class ChapterListBeanDao extends AbstractDao { // 判断实体是否可更新 protected final boolean isEntityUpdateable() { // 返回true,表示实体可更新 - return true; + return true;// 该实体类型支持更新 } } diff --git a/basemvplib/src/androidTest/java/com/monke/basemvplib/ApplicationTest.java b/basemvplib/src/androidTest/java/com/monke/basemvplib/ApplicationTest.java index 19307d1..0e47272 100644 --- a/basemvplib/src/androidTest/java/com/monke/basemvplib/ApplicationTest.java +++ b/basemvplib/src/androidTest/java/com/monke/basemvplib/ApplicationTest.java @@ -1,13 +1,14 @@ +// 声明包名,指明该类属于 com.monke.basemvplib 包 package com.monke.basemvplib; - -import android.app.Application; -import android.test.ApplicationTestCase; +// 导入需要的类 +import android.app.Application;// 导入 Android 的 Application 类,使得可以对应用程序进行测试 +import android.test.ApplicationTestCase;// 导入 ApplicationTestCase 类,这是用于测试 Application 的基类 /** * Testing Fundamentals */ -public class ApplicationTest extends ApplicationTestCase { - public ApplicationTest() { - super(Application.class); +public class ApplicationTest extends ApplicationTestCase {// 定义一个公共类 ApplicationTest,继承自 ApplicationTestCase,指定测试的类为 Application + public ApplicationTest() {// 定义构造函数 + super(Application.class);// 调用父类的构造函数,传入 Application.class,告知需要测试的应用类是 Application } } \ No newline at end of file