pull/2/head
SYH 1 year ago
parent c71df4d60b
commit 6b84523ec0

@ -1,28 +1,30 @@
//指定了当前类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;
// 导入实体类 BookContentBean
import com.monke.monkeybook.bean.BookContentBean;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
/**
* DAO for table "BOOK_CONTENT_BEAN".
*/
*/
//继承自GreenDAO的AbstractDao类BookContentBean为实体类String为主键类型
public class BookContentBeanDao extends AbstractDao<BookContentBean, String> {
//定义常量TABLENAME表示该表的名称
public static final String TABLENAME = "BOOK_CONTENT_BEAN";
/**
* Properties of entity BookContentBean.<br/>
* Can be used for QueryBuilder and for referencing column names.
*/
* BookContentBeanQueryBuilder
*/
// 定义实体类属性映射:对应数据库表字段名的属性
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");
@ -30,18 +32,24 @@ public class BookContentBeanDao extends AbstractDao<BookContentBean, String> {
public final static Property Tag = new Property(3, String.class, "tag", false, "TAG");
};
//构造函数传入DaoConfig用于初始化DAO
public BookContentBeanDao(DaoConfig config) {
super(config);
super(config); //调用父类构造函数初始化Dao配置
}
// 构造函数传入DaoConfig和DaoSession用于初始化DAO和会话管理
public BookContentBeanDao(DaoConfig config, DaoSession daoSession) {
super(config, daoSession);
super(config, daoSession); //调用父类构造函数初始化Dao配置和会话
}
/** Creates the underlying database table. */
/**
* Creates the underlying database table.
*
*/
public static void createTable(Database db, boolean ifNotExists) {
//如果ifNotExists为true则在创建表时确保该表不存在
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
@ -49,85 +57,110 @@ public class BookContentBeanDao extends AbstractDao<BookContentBean, String> {
"\"TAG\" TEXT);"); // 3: tag
}
/** Drops the underlying database table. */
/** Drops the underlying database table.
*
*/
public static void dropTable(Database db, boolean ifExists) {
//使用SQL删除表确保表存在时删除
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"BOOK_CONTENT_BEAN\"";
db.execSQL(sql);
}
@Override
protected final void bindValues(DatabaseStatement stmt, BookContentBean entity) {
//清除绑定的值,确保每次绑定时都是干净的
stmt.clearBindings();
//绑定durChapterUrl字段到SQL语句的第一个位置
String durChapterUrl = entity.getDurChapterUrl();
if (durChapterUrl != null) {
//将章节URL字符串绑定到SQL语句的第一个位置
stmt.bindString(1, durChapterUrl);
}
stmt.bindLong(2, entity.getDurChapterIndex());
//绑定durChapterIndex字段到SQL语句的第二个位置
stmt.bindLong(2, entity.getDurChapterIndex());//将章节索引绑定到SQL语句的第二个位置
//绑定durCapterContent字段到SQL语句的第三个位置
String durCapterContent = entity.getDurCapterContent();
if (durCapterContent != null) {
//将章节内容绑定到SQL语句的第三个位置
stmt.bindString(3, durCapterContent);
}
//绑定tag字段到SQL语句的第四个位置
String tag = entity.getTag();
if (tag != null) {
//将标签绑定到SQL语句的第四个位置
stmt.bindString(4, tag);
}
}
@Override
protected final void bindValues(SQLiteStatement stmt, BookContentBean entity) {
//清除绑定的值,确保每次绑定时都是干净的
stmt.clearBindings();
//绑定durChapterUrl字段到SQL语句的第一个位置
String durChapterUrl = entity.getDurChapterUrl();
if (durChapterUrl != null) {
//将章节URL字符串绑定到SQL语句的第一个位置
stmt.bindString(1, durChapterUrl);
}
stmt.bindLong(2, entity.getDurChapterIndex());
//绑定durChapterIndex字段到SQL语句的第二个位置
stmt.bindLong(2, entity.getDurChapterIndex()); //将章节索引绑定到SQL语句的第二个位置
//绑定durCapterContent字段到SQL语句的第三个位置
String durCapterContent = entity.getDurCapterContent();
if (durCapterContent != null) {
//将章节内容绑定到SQL语句的第三个位置
stmt.bindString(3, durCapterContent);
}
//绑定tag字段到SQL语句的第四个位置
String tag = entity.getTag();
if (tag != null) {
//将标签绑定到SQL语句的第四个位置
stmt.bindString(4, tag);
}
}
@Override
public String readKey(Cursor cursor, int offset) {
//从Cursor中读取主键(durChapterUrl)若为null则返回null
return cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0);
}
}
@Override
public BookContentBean readEntity(Cursor cursor, int offset) {
//根据Cursor数据构建一个BookContentBean实体类对象并返回
BookContentBean entity = new BookContentBean( //
cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // durChapterUrl
cursor.getInt(offset + 1), // durChapterIndex
cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // durCapterContent
cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3) // tag
cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // durChapterUrl
cursor.getInt(offset + 1), // durChapterIndex
cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // durCapterContent
cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3) // tag
);
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));
}
}
@Override
protected final String updateKeyAfterInsert(BookContentBean entity, long rowId) {
//返回更新时需要的主键字段这里是durChapterUrl
return entity.getDurChapterUrl();
}
@Override
public String getKey(BookContentBean entity) {
//获取实体对象的主键值返回durChapterUrl
if(entity != null) {
return entity.getDurChapterUrl();
} else {
@ -137,7 +170,8 @@ public class BookContentBeanDao extends AbstractDao<BookContentBean, String> {
@Override
protected final boolean isEntityUpdateable() {
//指示实体是否可以被更新这里返回true表示支持更新
return true;
}
}

@ -1,156 +1,202 @@
//定义类所在的包路径,表示该文件属于com.monke.monkeybook.dao包
package com.monke.monkeybook.dao;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;
//导入必要的类包含GreenDAO和Android数据库操作的相关类
import android.database.Cursor;// 导入Cursor类用于数据库查询结果的处理
import android.database.sqlite.SQLiteStatement;//导入SQLiteStatement类用于执行SQL语句
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 org.greenrobot.greendao.AbstractDao;//导入AbstractDao类这是一个GreenDao框架的抽象类用于定义数据库操作的基类
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;//导入BookInfoBean实体类
import com.monke.monkeybook.bean.BookInfoBean;
import com.monke.monkeybook.bean.BookInfoBean;//导入BookInfoBean类这是数据库中要操作的实体类
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
/**
* DAO for table "BOOK_INFO_BEAN".
*/
public class BookInfoBeanDao extends AbstractDao<BookInfoBean, String> {
* DAO "BOOK_INFO_BEAN"
*/
//BookInfoBeanDao继承自AbstractDao操作BookInfoBean对象主键类型为String
public class BookInfoBeanDao extends AbstractDao<BookInfoBean, String> {
//定义常量TABLENAME表示数据库表名
public static final String TABLENAME = "BOOK_INFO_BEAN";
/**
* Properties of entity BookInfoBean.<br/>
* Can be used for QueryBuilder and for referencing column names.
*/
* BookInfoBean QueryBuilder
*/
public static class Properties {
public final static Property Name = new Property(0, String.class, "name", false, "NAME");
public final static Property Tag = new Property(1, String.class, "tag", false, "TAG");
public final static Property NoteUrl = new Property(2, String.class, "noteUrl", true, "NOTE_URL");
public final static Property ChapterUrl = new Property(3, String.class, "chapterUrl", false, "CHAPTER_URL");
public final static Property FinalRefreshData = new Property(4, long.class, "finalRefreshData", false, "FINAL_REFRESH_DATA");
public final static Property CoverUrl = new Property(5, String.class, "coverUrl", false, "COVER_URL");
public final static Property Author = new Property(6, String.class, "author", false, "AUTHOR");
public final static Property Introduce = new Property(7, String.class, "introduce", false, "INTRODUCE");
public final static Property Origin = new Property(8, String.class, "origin", false, "ORIGIN");
//定义实体类属性映射:对应数据库表字段名的属性
public final static Property Name = new Property(0, String.class, "name", false, "NAME");//属性0名称nameString类型非主键数据库列名NAME
public final static Property Tag = new Property(1, String.class, "tag", false, "TAG");//属性1标签tagString类型非主键数据库列名TAG
public final static Property NoteUrl = new Property(2, String.class, "noteUrl", true, "NOTE_URL");// 属性2笔记URLnoteUrlString类型主键非空数据库列名NOTE_URL
public final static Property ChapterUrl = new Property(3, String.class, "chapterUrl", false, "CHAPTER_URL");//属性3章节URLchapterUrlString类型非主键数据库列名CHAPTER_URL
public final static Property FinalRefreshData = new Property(4, long.class, "finalRefreshData", false, "FINAL_REFRESH_DATA");//属性4最后刷新时间finalRefreshDatalong类型非主键数据库列名FINAL_REFRESH_DATA
public final static Property CoverUrl = new Property(5, String.class, "coverUrl", false, "COVER_URL");//属性5封面URLcoverUrlString类型非主键数据库列名COVER_URL
public final static Property Author = new Property(6, String.class, "author", false, "AUTHOR");//属性6作者authorString类型非主键数据库列名AUTHOR
public final static Property Introduce = new Property(7, String.class, "introduce", false, "INTRODUCE");//属性7简介introduceString类型非主键数据库列名INTRODUCE
public final static Property Origin = new Property(8, String.class, "origin", false, "ORIGIN");//属性8来源originString类型非主键数据库列名ORIGIN
};
//构造函数使用DaoConfig配置创建DAO对象
public BookInfoBeanDao(DaoConfig config) {
super(config);
}
//构造函数使用DaoConfig和DaoSession配置创建DAO对象
public BookInfoBeanDao(DaoConfig config, DaoSession daoSession) {
super(config, daoSession);
}
/** Creates the underlying database table. */
/** Creates the underlying database table.
*
*/
//创建数据库表的方法
public static void createTable(Database db, boolean ifNotExists) {
//判断是否需要添加IF NOT EXISTS条件
String constraint = ifNotExists? "IF NOT EXISTS ": "";
db.execSQL("CREATE TABLE " + constraint + "\"BOOK_INFO_BEAN\" (" + //
"\"NAME\" TEXT," + // 0: name
"\"TAG\" TEXT," + // 1: tag
"\"NOTE_URL\" TEXT PRIMARY KEY NOT NULL ," + // 2: noteUrl
"\"CHAPTER_URL\" TEXT," + // 3: chapterUrl
"\"FINAL_REFRESH_DATA\" INTEGER NOT NULL ," + // 4: finalRefreshData
"\"COVER_URL\" TEXT," + // 5: coverUrl
"\"AUTHOR\" TEXT," + // 6: author
"\"INTRODUCE\" TEXT," + // 7: introduce
"\"ORIGIN\" TEXT);"); // 8: origin
//使用SQL执行表创建语句
db.execSQL("CREATE TABLE " + constraint + "\"BOOK_INFO_BEAN\" (" +
"\"NAME\" TEXT," + //NAME字段TEXT类型
"\"TAG\" TEXT," + //TAG字段TEXT类型
"\"NOTE_URL\" TEXT PRIMARY KEY NOT NULL ," + //NOTE_URL字段TEXT类型主键非空
"\"CHAPTER_URL\" TEXT," + //CHAPTER_URL字段TEXT类型
"\"FINAL_REFRESH_DATA\" INTEGER NOT NULL ," + //FINAL_REFRESH_DATA字段INTEGER类型非空
"\"COVER_URL\" TEXT," + //COVER_URL字段TEXT类型
"\"AUTHOR\" TEXT," + //AUTHOR字段TEXT类型
"\"INTRODUCE\" TEXT," + //INTRODUCE字段TEXT类型
"\"ORIGIN\" TEXT);"); //ORIGIN字段TEXT类型
}
/** Drops the underlying database table. */
/** Drops the underlying database table.
*
*/
public static void dropTable(Database db, boolean ifExists) {
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"BOOK_INFO_BEAN\"";
db.execSQL(sql);
//使用SQL删除表确保表存在时删除
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"BOOK_INFO_BEAN\"";//构造删除表的SQL语句
db.execSQL(sql);//执行删除表的SQL语句
}
@Override
//将BookInfoBean实体对象的值绑定到DatabaseStatement对象中
protected final void bindValues(DatabaseStatement stmt, BookInfoBean entity) {
//清除绑定的值,确保每次绑定时都是干净的
stmt.clearBindings();
//绑定name字段到SQL语句的第一个位置
String name = entity.getName();
if (name != null) {
//将书名绑定到SQL语句的第一个位置
stmt.bindString(1, name);
}
//绑定tag字段到SQL语句的第二个位置
String tag = entity.getTag();
if (tag != null) {
//将标签绑定到SQL语句的第二个位置
stmt.bindString(2, tag);
}
//绑定noteUrl字段到SQL语句的第三个位置
String noteUrl = entity.getNoteUrl();
if (noteUrl != null) {
//将书籍URL绑定到SQL语句的第三个位置
stmt.bindString(3, noteUrl);
}
//绑定chapterUrl字段到SQL语句的第四个位置
String chapterUrl = entity.getChapterUrl();
if (chapterUrl != null) {
//将章节URL绑定到SQL语句的第四个位置
stmt.bindString(4, chapterUrl);
}
//将最后刷新时间long 类型绑定到SQL语句的第五个位置
stmt.bindLong(5, entity.getFinalRefreshData());
//绑定coverUrl字段到SQL语句的第六个位置
String coverUrl = entity.getCoverUrl();
if (coverUrl != null) {
//将封面图URL绑定到SQL语句的第六个位置
stmt.bindString(6, coverUrl);
}
//绑定author字段到SQL语句的第七个位置
String author = entity.getAuthor();
if (author != null) {
//将作者绑定到SQL语句的第七个位置
stmt.bindString(7, author);
}
//绑定introduce字段到SQL语句的第八个位置
String introduce = entity.getIntroduce();
if (introduce != null) {
//将简介绑定到SQL语句的第八个位置
stmt.bindString(8, introduce);
}
//绑定origin字段到SQL语句的第九个位置
String origin = entity.getOrigin();
if (origin != null) {
//将来源绑定到SQL语句的第九个位置
stmt.bindString(9, origin);
}
}
@Override
//将BookInfoBean实体对象的值绑定到SQLiteStatement对象中与上一个方法功能类似只是对象不同
protected final void bindValues(SQLiteStatement stmt, BookInfoBean entity) {
//清除绑定的值,确保每次绑定时都是干净的
stmt.clearBindings();
//绑定name字段值
String name = entity.getName();
if (name != null) {
stmt.bindString(1, name);
}
//绑定tag字段值
String tag = entity.getTag();
if (tag != null) {
stmt.bindString(2, tag);
}
//绑定noteUrl字段值
String noteUrl = entity.getNoteUrl();
if (noteUrl != null) {
stmt.bindString(3, noteUrl);
}
//绑定chapterUrl字段值
String chapterUrl = entity.getChapterUrl();
if (chapterUrl != null) {
stmt.bindString(4, chapterUrl);
}
//绑定finalRefreshData字段值
stmt.bindLong(5, entity.getFinalRefreshData());
//绑定coverUrl字段值
String coverUrl = entity.getCoverUrl();
if (coverUrl != null) {
stmt.bindString(6, coverUrl);
}
//绑定author字段值
String author = entity.getAuthor();
if (author != null) {
stmt.bindString(7, author);
}
//绑定introduce字段值
String introduce = entity.getIntroduce();
if (introduce != null) {
stmt.bindString(8, introduce);
}
//绑定origin字段值
String origin = entity.getOrigin();
if (origin != null) {
stmt.bindString(9, origin);
@ -158,47 +204,57 @@ public class BookInfoBeanDao extends AbstractDao<BookInfoBean, String> {
}
@Override
//从Cursor中读取主键
public String readKey(Cursor cursor, int offset) {
//主键在第三列(offset + 2)如果为空返回null否则返回字符串
return cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2);
}
}
@Override
//从Cursor中读取BookInfoBean实体
public BookInfoBean readEntity(Cursor cursor, int offset) {
//创建BookInfoBean对象
BookInfoBean entity = new BookInfoBean( //
cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // name
cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // tag
cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // noteUrl
cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // chapterUrl
cursor.getLong(offset + 4), // finalRefreshData
cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // coverUrl
cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // author
cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // introduce
cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8) // origin
cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // name
cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // tag
cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // noteUrl
cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // chapterUrl
cursor.getLong(offset + 4), // finalRefreshData
cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // coverUrl
cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // author
cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // introduce
cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8) // origin
);
//返回创建好的BookInfoBean对象
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));
entity.setTag(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
entity.setNoteUrl(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
entity.setChapterUrl(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
entity.setFinalRefreshData(cursor.getLong(offset + 4));
entity.setCoverUrl(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
entity.setAuthor(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
entity.setIntroduce(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
entity.setOrigin(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8));
}
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();
}
@Override
//获取主键
public String getKey(BookInfoBean entity) {
if(entity != null) {
//返回noteUrl作为主键
return entity.getNoteUrl();
} else {
return null;
@ -206,8 +262,10 @@ public class BookInfoBeanDao extends AbstractDao<BookInfoBean, String> {
}
@Override
//是否可更新实体
protected final boolean isEntityUpdateable() {
//可更新
return true;
}
}

@ -1,132 +1,163 @@
// 包声明声明该类位于com.monke.monkeybook.dao包下
package com.monke.monkeybook.dao;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;
import android.database.Cursor; // 导入Cursor类用于从数据库游标中读取数据
import android.database.sqlite.SQLiteStatement; // 导入SQLiteStatement类用于执行预编译的SQL语句
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 org.greenrobot.greendao.AbstractDao; // 导入AbstractDao类GreenDao框架中用于数据库操作的抽象基类
import org.greenrobot.greendao.Property; // 导入Property类用于定义数据库表字段的属性
import org.greenrobot.greendao.internal.DaoConfig; // 导入DaoConfig类用于配置Dao对象的配置信息
import org.greenrobot.greendao.database.Database; // 导入Database类GreenDao框架中用于数据库操作的类
import org.greenrobot.greendao.database.DatabaseStatement; // 导入DatabaseStatement类用于执行SQL语句
// 导入BookShelfBean类这是数据库操作的对象
import com.monke.monkeybook.bean.BookShelfBean;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
/**
* DAO for table "BOOK_SHELF_BEAN".
*/
*/
// BookShelfBeanDao类继承AbstractDao操作BookShelfBean对象主键类型为String
public class BookShelfBeanDao extends AbstractDao<BookShelfBean, String> {
// 数据库表名常量
public static final String TABLENAME = "BOOK_SHELF_BEAN";
/**
* Properties of entity BookShelfBean.<br/>
* 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", true, "NOTE_URL");
public final static Property DurChapter = new Property(1, int.class, "durChapter", false, "DUR_CHAPTER");
public final static Property DurChapterPage = new Property(2, int.class, "durChapterPage", false, "DUR_CHAPTER_PAGE");
public final static Property FinalDate = new Property(3, long.class, "finalDate", false, "FINAL_DATE");
public final static Property Tag = new Property(4, String.class, "tag", false, "TAG");
public final static Property NoteUrl = new Property(0, String.class, "noteUrl", true, "NOTE_URL"); // 属性0noteUrlString类型主键数据库列名NOTE_URL
public final static Property DurChapter = new Property(1, int.class, "durChapter", false, "DUR_CHAPTER"); // 属性1durChapterint类型非主键数据库列名DUR_CHAPTER
public final static Property DurChapterPage = new Property(2, int.class, "durChapterPage", false, "DUR_CHAPTER_PAGE"); // 属性2durChapterPageint类型非主键数据库列名DUR_CHAPTER_PAGE
public final static Property FinalDate = new Property(3, long.class, "finalDate", false, "FINAL_DATE"); // 属性3finalDatelong类型非主键数据库列名FINAL_DATE
public final static Property Tag = new Property(4, String.class, "tag", false, "TAG"); // 属性4tagString类型非主键数据库列名TAG
};
// 构造函数使用DaoConfig配置初始化Dao
public BookShelfBeanDao(DaoConfig config) {
super(config);
}
// 构造函数使用DaoConfig和DaoSession配置初始化Dao
public BookShelfBeanDao(DaoConfig config, DaoSession daoSession) {
super(config, daoSession);
}
/** Creates the underlying database table. */
/** Creates the underlying database table.
*
*/
// 创建BOOK_SHELF_BEAN表的方法
public static void createTable(Database db, boolean ifNotExists) {
// 根据ifNotExists判断是否需要添加"IF NOT EXISTS"条件
String constraint = ifNotExists? "IF NOT EXISTS ": "";
// 执行SQL语句创建表
db.execSQL("CREATE TABLE " + constraint + "\"BOOK_SHELF_BEAN\" (" + //
"\"NOTE_URL\" TEXT PRIMARY KEY NOT NULL ," + // 0: noteUrl
"\"DUR_CHAPTER\" INTEGER NOT NULL ," + // 1: durChapter
"\"DUR_CHAPTER_PAGE\" INTEGER NOT NULL ," + // 2: durChapterPage
"\"FINAL_DATE\" INTEGER NOT NULL ," + // 3: finalDate
"\"TAG\" TEXT);"); // 4: tag
"\"NOTE_URL\" TEXT PRIMARY KEY NOT NULL ," + //NOTE_URL字段TEXT类型主键非空
"\"DUR_CHAPTER\" INTEGER NOT NULL ," + // DUR_CHAPTER字段INTEGER类型非空
"\"DUR_CHAPTER_PAGE\" INTEGER NOT NULL ," + // DUR_CHAPTER_PAGE字段INTEGER类型非空
"\"FINAL_DATE\" INTEGER NOT NULL ," + // FINAL_DATE字段INTEGER类型非空
"\"TAG\" TEXT);"); // TAG字段TEXT类型
}
/** Drops the underlying database table. */
/** Drops the underlying database table.
*
*/
// 删除BOOK_SHELF_BEAN表的方法
public static void dropTable(Database db, boolean ifExists) {
// 构造删除表的SQL语句
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"BOOK_SHELF_BEAN\"";
// 执行SQL语句删除表
db.execSQL(sql);
}
@Override
// 将BookShelfBean实体对象的值绑定到DatabaseStatement语句中
protected final void bindValues(DatabaseStatement stmt, BookShelfBean entity) {
// 清除之前的绑定
stmt.clearBindings();
String noteUrl = entity.getNoteUrl();
if (noteUrl != null) {
// 绑定noteUrl值到第一个参数位置
stmt.bindString(1, noteUrl);
}
stmt.bindLong(2, entity.getDurChapter());
stmt.bindLong(3, entity.getDurChapterPage());
stmt.bindLong(4, entity.getFinalDate());
stmt.bindLong(2, entity.getDurChapter()); // 绑定durChapter值到第二个参数位置
stmt.bindLong(3, entity.getDurChapterPage()); // 绑定durChapterPage值到第三个参数位置
stmt.bindLong(4, entity.getFinalDate()); // 绑定finalDate值到第四个参数位置
String tag = entity.getTag();
if (tag != null) {
stmt.bindString(5, tag);
stmt.bindString(5, tag); // 绑定tag值到第五个参数位置
}
}
@Override
// 将BookShelfBean实体对象的值绑定到SQLiteStatement语句中与上一个方法功能类似只是对象不同
protected final void bindValues(SQLiteStatement stmt, BookShelfBean entity) {
// 清除之前的绑定
stmt.clearBindings();
String noteUrl = entity.getNoteUrl();
if (noteUrl != null) {
// 绑定noteUrl值到第一个参数位置
stmt.bindString(1, noteUrl);
}
stmt.bindLong(2, entity.getDurChapter());
stmt.bindLong(3, entity.getDurChapterPage());
stmt.bindLong(4, entity.getFinalDate());
stmt.bindLong(2, entity.getDurChapter()); // 绑定durChapter值到第二个参数位置
stmt.bindLong(3, entity.getDurChapterPage()); // 绑定durChapterPage值到第三个参数位置
stmt.bindLong(4, entity.getFinalDate()); // 绑定finalDate值到第四个参数位置
String tag = entity.getTag();
if (tag != null) {
// 绑定tag值到第五个参数位置
stmt.bindString(5, tag);
}
}
@Override
// 从游标中读取主键
public String readKey(Cursor cursor, int offset) {
// 从偏移量offset+0的位置读取主键值如果为空返回null否则返回字符串
return cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0);
}
}
@Override
// 从游标中读取BookShelfBean实体
public BookShelfBean readEntity(Cursor cursor, int offset) {
// 创建BookShelfBean对象
BookShelfBean entity = new BookShelfBean( //
cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // noteUrl
cursor.getInt(offset + 1), // durChapter
cursor.getInt(offset + 2), // durChapterPage
cursor.getLong(offset + 3), // finalDate
cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4) // tag
cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // noteUrl
cursor.getInt(offset + 1), // durChapter
cursor.getInt(offset + 2), // durChapterPage
cursor.getLong(offset + 3), // finalDate
cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4) // tag
);
// 返回创建好的BookShelfBean对象
return entity;
}
@Override
// 将游标中的数据读取到已存在的BookShelfBean实体中
public void readEntity(Cursor cursor, BookShelfBean entity, int offset) {
entity.setNoteUrl(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
entity.setDurChapter(cursor.getInt(offset + 1));
entity.setDurChapterPage(cursor.getInt(offset + 2));
entity.setFinalDate(cursor.getLong(offset + 3));
entity.setTag(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
}
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();
}
@Override
// 获取主键
public String getKey(BookShelfBean entity) {
if(entity != null) {
// 返回noteUrl作为主键
return entity.getNoteUrl();
} else {
return null;
@ -134,8 +165,10 @@ public class BookShelfBeanDao extends AbstractDao<BookShelfBean, String> {
}
@Override
// 判断实体是否可更新
protected final boolean isEntityUpdateable() {
// 返回true表示实体可更新
return true;
}
}

@ -1,162 +1,200 @@
// 包声明
package com.monke.monkeybook.dao;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;
import android.database.Cursor; // 导入Cursor类用于从数据库游标中读取数据
import android.database.sqlite.SQLiteStatement; // 导入SQLiteStatement类用于执行预编译的SQL语句
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 org.greenrobot.greendao.AbstractDao; // 导入AbstractDao类GreenDao框架中用于数据库操作的抽象基类
import org.greenrobot.greendao.Property; // 导入Property类用于定义数据库表字段的属性
import org.greenrobot.greendao.internal.DaoConfig; // 导入DaoConfig类用于配置Dao对象的配置信息
import org.greenrobot.greendao.database.Database; // 导入Database类GreenDao框架中用于数据库操作的类
import org.greenrobot.greendao.database.DatabaseStatement; // 导入DatabaseStatement类用于执行SQL语句
// 导入ChapterListBean类这是数据库操作的对象
import com.monke.monkeybook.bean.ChapterListBean;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
/**
* DAO for table "CHAPTER_LIST_BEAN".
*/
*/
// ChapterListBeanDao类继承AbstractDao操作ChapterListBean对象主键类型为String
public class ChapterListBeanDao extends AbstractDao<ChapterListBean, String> {
// 数据库表名常量
public static final String TABLENAME = "CHAPTER_LIST_BEAN";
/**
* Properties of entity ChapterListBean.<br/>
* 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");
public final static Property DurChapterIndex = new Property(1, int.class, "durChapterIndex", false, "DUR_CHAPTER_INDEX");
public final static Property DurChapterUrl = new Property(2, String.class, "durChapterUrl", true, "DUR_CHAPTER_URL");
public final static Property DurChapterName = new Property(3, String.class, "durChapterName", false, "DUR_CHAPTER_NAME");
public final static Property Tag = new Property(4, String.class, "tag", false, "TAG");
public final static Property HasCache = new Property(5, Boolean.class, "hasCache", false, "HAS_CACHE");
public final static Property NoteUrl = new Property(0, String.class, "noteUrl", false, "NOTE_URL"); // 属性0noteUrlString类型非主键数据库列名NOTE_URL
public final static Property DurChapterIndex = new Property(1, int.class, "durChapterIndex", false, "DUR_CHAPTER_INDEX"); // 属性1durChapterIndexint类型非主键数据库列名DUR_CHAPTER_INDEX
public final static Property DurChapterUrl = new Property(2, String.class, "durChapterUrl", true, "DUR_CHAPTER_URL"); // 属性2durChapterUrlString类型主键数据库列名DUR_CHAPTER_URL
public final static Property DurChapterName = new Property(3, String.class, "durChapterName", false, "DUR_CHAPTER_NAME"); // 属性3durChapterNameString类型非主键数据库列名DUR_CHAPTER_NAME
public final static Property Tag = new Property(4, String.class, "tag", false, "TAG"); // 属性4tagString类型非主键数据库列名TAG
public final static Property HasCache = new Property(5, Boolean.class, "hasCache", false, "HAS_CACHE"); // 属性5hasCacheBoolean类型非主键数据库列名HAS_CACHE
};
// 构造函数使用DaoConfig配置初始化Dao
public ChapterListBeanDao(DaoConfig config) {
super(config);
}
// 构造函数使用DaoConfig和DaoSession配置初始化Dao
public ChapterListBeanDao(DaoConfig config, DaoSession daoSession) {
super(config, daoSession);
}
/** 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 ": "";
// 执行SQL语句创建表
db.execSQL("CREATE TABLE " + constraint + "\"CHAPTER_LIST_BEAN\" (" + //
"\"NOTE_URL\" TEXT," + // 0: noteUrl
"\"DUR_CHAPTER_INDEX\" INTEGER NOT NULL ," + // 1: durChapterIndex
"\"DUR_CHAPTER_URL\" TEXT PRIMARY KEY NOT NULL ," + // 2: durChapterUrl
"\"DUR_CHAPTER_NAME\" TEXT," + // 3: durChapterName
"\"TAG\" TEXT," + // 4: tag
"\"HAS_CACHE\" INTEGER);"); // 5: hasCache
"\"NOTE_URL\" TEXT," + // NOTE_URL字段TEXT类型
"\"DUR_CHAPTER_INDEX\" INTEGER NOT NULL ," + // DUR_CHAPTER_INDEX字段INTEGER类型非空
"\"DUR_CHAPTER_URL\" TEXT PRIMARY KEY NOT NULL ," + // DUR_CHAPTER_URL字段TEXT类型主键非空
"\"DUR_CHAPTER_NAME\" TEXT," + // DUR_CHAPTER_NAME字段TEXT类型
"\"TAG\" TEXT," + // TAG字段TEXT类型
"\"HAS_CACHE\" INTEGER);"); // HAS_CACHE字段INTEGER类型
}
/** Drops the underlying database table. */
/** Drops the underlying database table.
*
*/
// 删除CHAPTER_LIST_BEAN表的方法
public static void dropTable(Database db, boolean ifExists) {
// 构造删除表的SQL语句
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"CHAPTER_LIST_BEAN\"";
// 执行SQL语句删除表
db.execSQL(sql);
}
@Override
// 将ChapterListBean实体对象的值绑定到DatabaseStatement语句中
protected final void bindValues(DatabaseStatement stmt, ChapterListBean entity) {
// 清除之前的绑定
stmt.clearBindings();
String noteUrl = entity.getNoteUrl();
if (noteUrl != null) {
// 绑定noteUrl值到第一个参数位置
stmt.bindString(1, noteUrl);
}
// 绑定durChapterIndex值到第二个参数位置
stmt.bindLong(2, entity.getDurChapterIndex());
String durChapterUrl = entity.getDurChapterUrl();
if (durChapterUrl != null) {
// 绑定durChapterUrl值到第三个参数位置
stmt.bindString(3, durChapterUrl);
}
String durChapterName = entity.getDurChapterName();
if (durChapterName != null) {
// 绑定durChapterName值到第四个参数位置
stmt.bindString(4, durChapterName);
}
String tag = entity.getTag();
if (tag != null) {
// 绑定tag值到第五个参数位置
stmt.bindString(5, tag);
}
Boolean hasCache = entity.getHasCache();
if (hasCache != null) {
// 绑定hasCache值到第六个参数位置true为1false为0
stmt.bindLong(6, hasCache ? 1L: 0L);
}
}
@Override
// 将ChapterListBean实体对象的值绑定到SQLiteStatement语句中与上一个方法功能类似只是对象不同
protected final void bindValues(SQLiteStatement stmt, ChapterListBean entity) {
// 清除之前的绑定
stmt.clearBindings();
String noteUrl = entity.getNoteUrl();
if (noteUrl != null) {
// 绑定noteUrl值到第一个参数位置
stmt.bindString(1, noteUrl);
}
// 绑定durChapterIndex值到第二个参数位置
stmt.bindLong(2, entity.getDurChapterIndex());
String durChapterUrl = entity.getDurChapterUrl();
if (durChapterUrl != null) {
// 绑定durChapterUrl值到第三个参数位置
stmt.bindString(3, durChapterUrl);
}
String durChapterName = entity.getDurChapterName();
if (durChapterName != null) {
// 绑定durChapterName值到第四个参数位置
stmt.bindString(4, durChapterName);
}
String tag = entity.getTag();
if (tag != null) {
// 绑定tag值到第五个参数位置
stmt.bindString(5, tag);
}
Boolean hasCache = entity.getHasCache();
if (hasCache != null) {
// 绑定hasCache值到第六个参数位置true为1false为0
stmt.bindLong(6, hasCache ? 1L: 0L);
}
}
@Override
// 从游标中读取主键
public String readKey(Cursor cursor, int offset) {
// 从偏移量offset+2的位置读取主键值如果为空返回null否则返回字符串
return cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2);
}
}
@Override
// 从游标中读取ChapterListBean实体
public ChapterListBean readEntity(Cursor cursor, int offset) {
// 创建ChapterListBean对象
ChapterListBean entity = new ChapterListBean( //
cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // noteUrl
cursor.getInt(offset + 1), // durChapterIndex
cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // durChapterUrl
cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // durChapterName
cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // tag
cursor.isNull(offset + 5) ? null : cursor.getShort(offset + 5) != 0 // hasCache
cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // noteUrl
cursor.getInt(offset + 1), // durChapterIndex
cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // durChapterUrl
cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // durChapterName
cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // tag
cursor.isNull(offset + 5) ? null : cursor.getShort(offset + 5) != 0 // hasCache 将short转换为boolean
);
// 返回创建好的ChapterListBean对象
return entity;
}
@Override
// 将游标中的数据读取到已存在的ChapterListBean实体中
public void readEntity(Cursor cursor, ChapterListBean entity, int offset) {
entity.setNoteUrl(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
entity.setDurChapterIndex(cursor.getInt(offset + 1));
entity.setDurChapterUrl(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
entity.setDurChapterName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
entity.setTag(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
entity.setHasCache(cursor.isNull(offset + 5) ? null : cursor.getShort(offset + 5) != 0);
}
entity.setNoteUrl(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0)); // noteUrl
entity.setDurChapterIndex(cursor.getInt(offset + 1)); // durChapterIndex
entity.setDurChapterUrl(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); // durChapterUrl
entity.setDurChapterName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); // durChapterName
entity.setTag(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); // tag
entity.setHasCache(cursor.isNull(offset + 5) ? null : cursor.getShort(offset + 5) != 0); // hasCache 将short转换为boolean
}
@Override
// 插入数据后更新主键
protected final String updateKeyAfterInsert(ChapterListBean entity, long rowId) {
// 返回durChapterUrl作为主键
return entity.getDurChapterUrl();
}
@Override
// 获取主键
public String getKey(ChapterListBean entity) {
if(entity != null) {
// 返回durChapterUrl作为主键
return entity.getDurChapterUrl();
} else {
return null;
@ -164,8 +202,10 @@ public class ChapterListBeanDao extends AbstractDao<ChapterListBean, String> {
}
@Override
// 判断实体是否可更新
protected final boolean isEntityUpdateable() {
// 返回true表示实体可更新
return true;
}
}

@ -1,109 +1,142 @@
// 包名声明
package com.monke.monkeybook.dao;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.util.Log;
import android.content.Context; // 导入Context类用于获取应用程序上下文
import android.database.sqlite.SQLiteDatabase; // 导入SQLiteDatabase类用于操作数据库
import android.database.sqlite.SQLiteDatabase.CursorFactory; // 导入CursorFactory类用于创建游标工厂
import android.util.Log; // 导入Log类用于输出日志信息
import org.greenrobot.greendao.AbstractDaoMaster;
import org.greenrobot.greendao.database.StandardDatabase;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseOpenHelper;
import org.greenrobot.greendao.identityscope.IdentityScopeType;
import org.greenrobot.greendao.AbstractDaoMaster; // 导入AbstractDaoMaster类GreenDao框架中用于管理DAO的抽象基类
import org.greenrobot.greendao.database.StandardDatabase; // 导入StandardDatabase类GreenDao框架中基于SQLite的数据库实现
import org.greenrobot.greendao.database.Database; // 导入Database类GreenDao框架中用于数据库操作的接口
import org.greenrobot.greendao.database.DatabaseOpenHelper; // 导入DatabaseOpenHelper类GreenDao框架中用于打开和管理数据库的帮助类
import org.greenrobot.greendao.identityscope.IdentityScopeType; // 导入IdentityScopeType类GreenDao框架中用于指定标识符作用域类型的枚举
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* Master of DAO (schema version 1): knows all DAOs.
*/
// DaoMaster类继承AbstractDaoMaster是所有DAO的管理者
public class DaoMaster extends AbstractDaoMaster {
// 数据库模式版本号
public static final int SCHEMA_VERSION = 1;
/** Creates underlying database table using DAOs. */
// 创建所有数据库表的方法
public static void createAllTables(Database db, boolean ifNotExists) {
BookContentBeanDao.createTable(db, ifNotExists);
BookInfoBeanDao.createTable(db, ifNotExists);
BookShelfBeanDao.createTable(db, ifNotExists);
ChapterListBeanDao.createTable(db, ifNotExists);
DownloadChapterBeanDao.createTable(db, ifNotExists);
SearchHistoryBeanDao.createTable(db, ifNotExists);
BookContentBeanDao.createTable(db, ifNotExists); // 创建BookContentBean表
BookInfoBeanDao.createTable(db, ifNotExists); // 创建BookInfoBean表
BookShelfBeanDao.createTable(db, ifNotExists); // 创建BookShelfBean表
ChapterListBeanDao.createTable(db, ifNotExists); // 创建ChapterListBean表
DownloadChapterBeanDao.createTable(db, ifNotExists); // 创建DownloadChapterBean表
SearchHistoryBeanDao.createTable(db, ifNotExists); // 创建SearchHistoryBean表
}
/** Drops underlying database table using DAOs. */
// 删除所有数据库表的方法
public static void dropAllTables(Database db, boolean ifExists) {
BookContentBeanDao.dropTable(db, ifExists);
BookInfoBeanDao.dropTable(db, ifExists);
BookShelfBeanDao.dropTable(db, ifExists);
ChapterListBeanDao.dropTable(db, ifExists);
DownloadChapterBeanDao.dropTable(db, ifExists);
SearchHistoryBeanDao.dropTable(db, ifExists);
BookContentBeanDao.dropTable(db, ifExists); // 删除BookContentBean表
BookInfoBeanDao.dropTable(db, ifExists); // 删除BookInfoBean表
BookShelfBeanDao.dropTable(db, ifExists); // 删除BookShelfBean表
ChapterListBeanDao.dropTable(db, ifExists); // 删除ChapterListBean表
DownloadChapterBeanDao.dropTable(db, ifExists); // 删除DownloadChapterBean表
SearchHistoryBeanDao.dropTable(db, ifExists); // 删除SearchHistoryBean表
}
/**
* WARNING: Drops all table on Upgrade! Use only during development.
* Convenience method using a {@link DevOpenHelper}.
*/
// 创建一个开发模式的DaoSession
public static DaoSession newDevSession(Context context, String name) {
// 获取可写的数据库
Database db = new DevOpenHelper(context, name).getWritableDb();
// 创建DaoMaster实例
DaoMaster daoMaster = new DaoMaster(db);
// 创建DaoSession实例并返回
return daoMaster.newSession();
}
// 构造函数使用SQLiteDatabase对象初始化DaoMaster
public DaoMaster(SQLiteDatabase db) {
// 使用StandardDatabase包装SQLiteDatabase
this(new StandardDatabase(db));
}
// 构造函数使用Database对象初始化DaoMaster
public DaoMaster(Database db) {
// 调用父类的构造函数
super(db, SCHEMA_VERSION);
registerDaoClass(BookContentBeanDao.class);
registerDaoClass(BookInfoBeanDao.class);
registerDaoClass(BookShelfBeanDao.class);
registerDaoClass(ChapterListBeanDao.class);
registerDaoClass(DownloadChapterBeanDao.class);
registerDaoClass(SearchHistoryBeanDao.class);
registerDaoClass(BookContentBeanDao.class); // 注册BookContentBeanDao
registerDaoClass(BookInfoBeanDao.class); // 注册BookInfoBeanDao
registerDaoClass(BookShelfBeanDao.class); // 注册BookShelfBeanDao
registerDaoClass(ChapterListBeanDao.class); // 注册ChapterListBeanDao
registerDaoClass(DownloadChapterBeanDao.class); // 注册DownloadChapterBeanDao
registerDaoClass(SearchHistoryBeanDao.class); // 注册SearchHistoryBeanDao
}
// 创建一个新的DaoSession使用默认的IdentityScopeType.Session
public DaoSession newSession() {
// 创建DaoSession实例
return new DaoSession(db, IdentityScopeType.Session, daoConfigMap);
}
// 创建一个新的DaoSession使用指定的IdentityScopeType
public DaoSession newSession(IdentityScopeType type) {
// 创建DaoSession实例
return new DaoSession(db, type, daoConfigMap);
}
/**
* Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} -
*/
// OpenHelper抽象类继承DatabaseOpenHelper用于创建和打开数据库
public static abstract class OpenHelper extends DatabaseOpenHelper {
// 构造函数,指定上下文和数据库名称
public OpenHelper(Context context, String name) {
// 调用父类的构造函数
super(context, name, SCHEMA_VERSION);
}
// 构造函数,指定上下文、数据库名称和游标工厂
public OpenHelper(Context context, String name, CursorFactory factory) {
// 调用父类的构造函数
super(context, name, factory, SCHEMA_VERSION);
}
@Override
// 创建数据库时调用
public void onCreate(Database db) {
// 输出日志信息
Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION);
// 创建所有数据库表
createAllTables(db, false);
}
}
/** WARNING: Drops all table on Upgrade! Use only during development. */
// DevOpenHelper类继承OpenHelper用于开发阶段的数据库升级
public static class DevOpenHelper extends OpenHelper {
// 构造函数,指定上下文和数据库名称
public DevOpenHelper(Context context, String name) {
// 调用父类的构造函数
super(context, name);
}
// 构造函数,指定上下文、数据库名称和游标工厂
public DevOpenHelper(Context context, String name, CursorFactory factory) {
// 调用父类的构造函数
super(context, name, factory);
}
@Override
// 数据库升级时调用
public void onUpgrade(Database db, int oldVersion, int newVersion) {
// 输出日志信息
Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables");
// 删除所有数据库表
dropAllTables(db, true);
// 重新创建数据库表
onCreate(db);
}
}

@ -1,118 +1,121 @@
// 包名声明
package com.monke.monkeybook.dao;
// 导入Map接口用于存储键值对
import java.util.Map;
import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.AbstractDaoSession;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.identityscope.IdentityScopeType;
import org.greenrobot.greendao.internal.DaoConfig;
import com.monke.monkeybook.bean.BookContentBean;
import com.monke.monkeybook.bean.BookInfoBean;
import com.monke.monkeybook.bean.BookShelfBean;
import com.monke.monkeybook.bean.ChapterListBean;
import com.monke.monkeybook.bean.DownloadChapterBean;
import com.monke.monkeybook.bean.SearchHistoryBean;
import com.monke.monkeybook.dao.BookContentBeanDao;
import com.monke.monkeybook.dao.BookInfoBeanDao;
import com.monke.monkeybook.dao.BookShelfBeanDao;
import com.monke.monkeybook.dao.ChapterListBeanDao;
import com.monke.monkeybook.dao.DownloadChapterBeanDao;
import com.monke.monkeybook.dao.SearchHistoryBeanDao;
import org.greenrobot.greendao.AbstractDao; // 导入AbstractDao类GreenDao框架中数据库操作的抽象基类
import org.greenrobot.greendao.AbstractDaoSession; // 导入AbstractDaoSession类GreenDao框架中DAO会话的抽象基类
import org.greenrobot.greendao.database.Database; // 导入Database类GreenDao框架中数据库操作的接口
import org.greenrobot.greendao.identityscope.IdentityScopeType; // 导入IdentityScopeType类GreenDao框架中用于指定标识符作用域类型的枚举
import org.greenrobot.greendao.internal.DaoConfig; // 导入DaoConfig类GreenDao框架中用于配置Dao对象的配置信息
import com.monke.monkeybook.bean.BookContentBean; // 导入BookContentBean类书籍内容Bean
import com.monke.monkeybook.bean.BookInfoBean; // 导入BookInfoBean类书籍信息Bean
import com.monke.monkeybook.bean.BookShelfBean; // 导入BookShelfBean类书架Bean
import com.monke.monkeybook.bean.ChapterListBean; // 导入ChapterListBean类章节列表Bean
import com.monke.monkeybook.bean.DownloadChapterBean; // 导入DownloadChapterBean类下载章节Bean
import com.monke.monkeybook.bean.SearchHistoryBean; // 导入SearchHistoryBean类搜索历史Bean
import com.monke.monkeybook.dao.BookContentBeanDao; // 导入BookContentBeanDao类
import com.monke.monkeybook.dao.BookInfoBeanDao; // 导入BookInfoBeanDao类
import com.monke.monkeybook.dao.BookShelfBeanDao; // 导入BookShelfBeanDao类
import com.monke.monkeybook.dao.ChapterListBeanDao; // 导入ChapterListBeanDao类
import com.monke.monkeybook.dao.DownloadChapterBeanDao; // 导入DownloadChapterBeanDao类
import com.monke.monkeybook.dao.SearchHistoryBeanDao; // 导入SearchHistoryBeanDao类
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* {@inheritDoc}
*
*
* @see org.greenrobot.greendao.AbstractDaoSession
*/
// DaoSession类继承AbstractDaoSession管理数据库会话
public class DaoSession extends AbstractDaoSession {
private final DaoConfig bookContentBeanDaoConfig;
private final DaoConfig bookInfoBeanDaoConfig;
private final DaoConfig bookShelfBeanDaoConfig;
private final DaoConfig chapterListBeanDaoConfig;
private final DaoConfig downloadChapterBeanDaoConfig;
private final DaoConfig searchHistoryBeanDaoConfig;
private final DaoConfig bookContentBeanDaoConfig; // BookContentBeanDao的配置信息
private final DaoConfig bookInfoBeanDaoConfig; // BookInfoBeanDao的配置信息
private final DaoConfig bookShelfBeanDaoConfig; // BookShelfBeanDao的配置信息
private final DaoConfig chapterListBeanDaoConfig; // ChapterListBeanDao的配置信息
private final DaoConfig downloadChapterBeanDaoConfig; // DownloadChapterBeanDao的配置信息
private final DaoConfig searchHistoryBeanDaoConfig; // SearchHistoryBeanDao的配置信息
private final BookContentBeanDao bookContentBeanDao;
private final BookInfoBeanDao bookInfoBeanDao;
private final BookShelfBeanDao bookShelfBeanDao;
private final ChapterListBeanDao chapterListBeanDao;
private final DownloadChapterBeanDao downloadChapterBeanDao;
private final SearchHistoryBeanDao searchHistoryBeanDao;
private final BookContentBeanDao bookContentBeanDao; // BookContentBeanDao实例
private final BookInfoBeanDao bookInfoBeanDao; // BookInfoBeanDao实例
private final BookShelfBeanDao bookShelfBeanDao; // BookShelfBeanDao实例
private final ChapterListBeanDao chapterListBeanDao; // ChapterListBeanDao实例
private final DownloadChapterBeanDao downloadChapterBeanDao; // DownloadChapterBeanDao实例
private final SearchHistoryBeanDao searchHistoryBeanDao; // SearchHistoryBeanDao实例
public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>, DaoConfig>
daoConfigMap) {
daoConfigMap) {// DaoSession的构造函数传入Database、IdentityScopeType和DaoConfig Map
// 调用父类的构造函数
super(db);
bookContentBeanDaoConfig = daoConfigMap.get(BookContentBeanDao.class).clone();
bookContentBeanDaoConfig.initIdentityScope(type);
bookContentBeanDaoConfig = daoConfigMap.get(BookContentBeanDao.class).clone(); // 从map中获取BookContentBeanDao的配置信息并克隆
bookContentBeanDaoConfig.initIdentityScope(type); // 初始化BookContentBeanDao的标识符作用域
bookInfoBeanDaoConfig = daoConfigMap.get(BookInfoBeanDao.class).clone();
bookInfoBeanDaoConfig.initIdentityScope(type);
bookInfoBeanDaoConfig = daoConfigMap.get(BookInfoBeanDao.class).clone(); // 从map中获取BookInfoBeanDao的配置信息并克隆
bookInfoBeanDaoConfig.initIdentityScope(type); // 初始化BookInfoBeanDao的标识符作用域
bookShelfBeanDaoConfig = daoConfigMap.get(BookShelfBeanDao.class).clone();
bookShelfBeanDaoConfig.initIdentityScope(type);
bookShelfBeanDaoConfig = daoConfigMap.get(BookShelfBeanDao.class).clone(); // 从map中获取BookShelfBeanDao的配置信息并克隆
bookShelfBeanDaoConfig.initIdentityScope(type); // 初始化BookShelfBeanDao的标识符作用域
chapterListBeanDaoConfig = daoConfigMap.get(ChapterListBeanDao.class).clone();
chapterListBeanDaoConfig.initIdentityScope(type);
chapterListBeanDaoConfig = daoConfigMap.get(ChapterListBeanDao.class).clone(); // 从map中获取ChapterListBeanDao的配置信息并克隆
chapterListBeanDaoConfig.initIdentityScope(type); // 初始化ChapterListBeanDao的标识符作用域
downloadChapterBeanDaoConfig = daoConfigMap.get(DownloadChapterBeanDao.class).clone();
downloadChapterBeanDaoConfig.initIdentityScope(type);
downloadChapterBeanDaoConfig = daoConfigMap.get(DownloadChapterBeanDao.class).clone(); // 从map中获取DownloadChapterBeanDao的配置信息并克隆
downloadChapterBeanDaoConfig.initIdentityScope(type); // 初始化DownloadChapterBeanDao的标识符作用域
searchHistoryBeanDaoConfig = daoConfigMap.get(SearchHistoryBeanDao.class).clone();
searchHistoryBeanDaoConfig.initIdentityScope(type);
searchHistoryBeanDaoConfig = daoConfigMap.get(SearchHistoryBeanDao.class).clone(); // 从map中获取SearchHistoryBeanDao的配置信息并克隆
searchHistoryBeanDaoConfig.initIdentityScope(type); // 初始化SearchHistoryBeanDao的标识符作用域
bookContentBeanDao = new BookContentBeanDao(bookContentBeanDaoConfig, this);
bookInfoBeanDao = new BookInfoBeanDao(bookInfoBeanDaoConfig, this);
bookShelfBeanDao = new BookShelfBeanDao(bookShelfBeanDaoConfig, this);
chapterListBeanDao = new ChapterListBeanDao(chapterListBeanDaoConfig, this);
downloadChapterBeanDao = new DownloadChapterBeanDao(downloadChapterBeanDaoConfig, this);
searchHistoryBeanDao = new SearchHistoryBeanDao(searchHistoryBeanDaoConfig, this);
bookContentBeanDao = new BookContentBeanDao(bookContentBeanDaoConfig, this); // 创建BookContentBeanDao实例
bookInfoBeanDao = new BookInfoBeanDao(bookInfoBeanDaoConfig, this); // 创建BookInfoBeanDao实例
bookShelfBeanDao = new BookShelfBeanDao(bookShelfBeanDaoConfig, this); // 创建BookShelfBeanDao实例
chapterListBeanDao = new ChapterListBeanDao(chapterListBeanDaoConfig, this); // 创建ChapterListBeanDao实例
downloadChapterBeanDao = new DownloadChapterBeanDao(downloadChapterBeanDaoConfig, this); // 创建DownloadChapterBeanDao实例
searchHistoryBeanDao = new SearchHistoryBeanDao(searchHistoryBeanDaoConfig, this); // 创建SearchHistoryBeanDao实例
registerDao(BookContentBean.class, bookContentBeanDao);
registerDao(BookInfoBean.class, bookInfoBeanDao);
registerDao(BookShelfBean.class, bookShelfBeanDao);
registerDao(ChapterListBean.class, chapterListBeanDao);
registerDao(DownloadChapterBean.class, downloadChapterBeanDao);
registerDao(SearchHistoryBean.class, searchHistoryBeanDao);
registerDao(BookContentBean.class, bookContentBeanDao); // 注册BookContentBeanDao
registerDao(BookInfoBean.class, bookInfoBeanDao); // 注册BookInfoBeanDao
registerDao(BookShelfBean.class, bookShelfBeanDao); // 注册BookShelfBeanDao
registerDao(ChapterListBean.class, chapterListBeanDao); // 注册ChapterListBeanDao
registerDao(DownloadChapterBean.class, downloadChapterBeanDao); // 注册DownloadChapterBeanDao
registerDao(SearchHistoryBean.class, searchHistoryBeanDao); // 注册SearchHistoryBeanDao
}
public void clear() {
bookContentBeanDaoConfig.getIdentityScope().clear();
bookInfoBeanDaoConfig.getIdentityScope().clear();
bookShelfBeanDaoConfig.getIdentityScope().clear();
chapterListBeanDaoConfig.getIdentityScope().clear();
downloadChapterBeanDaoConfig.getIdentityScope().clear();
searchHistoryBeanDaoConfig.getIdentityScope().clear();
public void clear() {// 清除所有DAO的标识符作用域
bookContentBeanDaoConfig.getIdentityScope().clear(); // 清除BookContentBeanDao的标识符作用域
bookInfoBeanDaoConfig.getIdentityScope().clear(); // 清除BookInfoBeanDao的标识符作用域
bookShelfBeanDaoConfig.getIdentityScope().clear(); // 清除BookShelfBeanDao的标识符作用域
chapterListBeanDaoConfig.getIdentityScope().clear(); // 清除ChapterListBeanDao的标识符作用域
downloadChapterBeanDaoConfig.getIdentityScope().clear(); // 清除DownloadChapterBeanDao的标识符作用域
searchHistoryBeanDaoConfig.getIdentityScope().clear(); // 清除SearchHistoryBeanDao的标识符作用域
}
public BookContentBeanDao getBookContentBeanDao() {
return bookContentBeanDao;
public BookContentBeanDao getBookContentBeanDao() {// 获取BookContentBeanDao实例
return bookContentBeanDao;// 返回BookContentBeanDao实例
}
public BookInfoBeanDao getBookInfoBeanDao() {
return bookInfoBeanDao;
public BookInfoBeanDao getBookInfoBeanDao() {// 获取BookInfoBeanDao实例
return bookInfoBeanDao;// 返回BookInfoBeanDao实例
}
public BookShelfBeanDao getBookShelfBeanDao() {
return bookShelfBeanDao;
public BookShelfBeanDao getBookShelfBeanDao() {// 获取BookShelfBeanDao实例
return bookShelfBeanDao;// 返回BookShelfBeanDao实例
}
public ChapterListBeanDao getChapterListBeanDao() {
return chapterListBeanDao;
public ChapterListBeanDao getChapterListBeanDao() {// 获取ChapterListBeanDao实例
return chapterListBeanDao;// 返回ChapterListBeanDao实例
}
public DownloadChapterBeanDao getDownloadChapterBeanDao() {
return downloadChapterBeanDao;
public DownloadChapterBeanDao getDownloadChapterBeanDao() {// 获取DownloadChapterBeanDao实例
return downloadChapterBeanDao;// 返回DownloadChapterBeanDao实例
}
public SearchHistoryBeanDao getSearchHistoryBeanDao() {
return searchHistoryBeanDao;
public SearchHistoryBeanDao getSearchHistoryBeanDao() {// 获取SearchHistoryBeanDao实例
return searchHistoryBeanDao;// 返回SearchHistoryBeanDao实例
}
}

Loading…
Cancel
Save