1 #2

Merged
psm26hr4y merged 4 commits from main into dev 1 year ago

@ -1,25 +1,25 @@
//Copyright (c) 2017. 章钦豪. All rights reserved.
//定义当前类所在的包路径为"com.monke.monkeybook.common",表明它属于"monkeybook"项目的公共部分
package com.monke.monkeybook.common;
//定义一个名为 RxBusTag 的公共类包含一组常量字符串用于标识RxBus事件
public class RxBusTag {
//定义一个静态常量字符串,表示添加书籍的事件
public final static String HAD_ADD_BOOK = "rxbus_add_book";
//定义一个静态常量字符串,表示移除书籍的事件
public final static String HAD_REMOVE_BOOK = "rxbus_remove_book";
//定义一个静态常量字符串,表示更新书籍进度的事件
public final static String UPDATE_BOOK_PROGRESS = "rxbus_update_book_progress";
//定义一个静态常量字符串,表示暂停下载的监听事件
public final static String PAUSE_DOWNLOAD_LISTENER = "rxbus_pause_download_listener";
//定义一个静态常量字符串,表示下载进度监听事件
public final static String PROGRESS_DOWNLOAD_LISTENER = "rxbus_progress_download_listener";
//定义一个静态常量字符串,表示下载完成监听事件
public final static String FINISH_DOWNLOAD_LISTENER = "rxbus_finish_download_listener";
//定义一个静态常量字符串,表示暂停下载的事件
public final static String PAUSE_DOWNLOAD = "rxbus_pause_download";
//定义一个静态常量字符串,表示开始下载的事件
public final static String START_DOWNLOAD = "rxbus_start_download";
//定义一个静态常量字符串,表示取消下载的事件
public final static String CANCEL_DOWNLOAD = "rxbus_cancel_download";
//定义一个静态常量字符串,表示添加下载任务的事件
public final static String ADD_DOWNLOAD_TASK = "rxbus_add_download_task";
}

@ -1,44 +1,59 @@
//Copyright (c) 2017. 章钦豪. All rights reserved.
//定义当前接口所在的包 com.monke.monkeybook.common.api
//这个包路径表示该接口用于应用程序的公共API部分。
package com.monke.monkeybook.common.api;
import io.reactivex.Observable;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.Url;
//引入所需要的库
import io.reactivex.Observable; //导入Observable类这是RxJava中的一个核心类表示一个可以发射数据的流
import retrofit2.http.GET; //导入Retrofit中的GET注解用于表示一个HTTP GET请求
import retrofit2.http.Headers; //导入Retrofit中的Headers注解用于向HTTP请求添加自定义头部信息。
import retrofit2.http.Url; //导入Retrofit中的Url注解用于动态传递URL。
/**
* API ( )
*/
//定义一个接口IEasouApi该接口包含了一些方法用于与宜搜小说的API进行交互。
public interface IEasouApi {
@GET
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
"Accept-Charset:UTF-8",
"Connection:close",
"Cache-Control:no-cache"})
//定义获取书籍信息的方法通过HTTP GET请求并添加自定义请求头
@GET //定义GET请求
//设置请求头
@Headers({"Accept:text/html,application/xhtml+xml,application/xml", //请求头:表示支持的响应类型
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3", //设置User-Agent模拟浏览器请求
"Accept-Charset:UTF-8", //请求头:指定字符集为 UTF-8
"Connection:close", //请求头:请求完成后关闭连接
"Cache-Control:no-cache"}) //禁用缓存
//返回值为Observable<String>这是一个异步操作最后会返回一个String类型的数据流
//@Url表示该方法接收一个动态URL作为参数
Observable<String> getBookInfo(@Url String url);
@GET
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
"Accept-Charset:UTF-8",
"Connection:close",
"Cache-Control:no-cache"})
//定义搜索书籍的方法类似getBookInfo
@GET //定义GET请求
//设置请求头
@Headers({"Accept:text/html,application/xhtml+xml,application/xml", //请求头:表示支持的响应类型
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3", //设置User-Agent模拟浏览器请求
"Accept-Charset:UTF-8", //请求头:指定字符集为 UTF-8
"Connection:close", //请求头:请求完成后关闭连接
"Cache-Control:no-cache"}) //禁用缓存
//该方法接受动态URL返回书籍搜索结果
Observable<String> searchBook(@Url String url);
@GET
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
"Accept-Charset:UTF-8",
"Connection:close",
"Cache-Control:no-cache"})
//定义获取书籍内容的方法,类似前两个方法
@GET //定义GET请求
//设置请求头
@Headers({"Accept:text/html,application/xhtml+xml,application/xml", //请求头:表示支持的响应类型
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3", //设置User-Agent模拟浏览器请求
"Accept-Charset:UTF-8", //请求头:指定字符集为 UTF-8
"Connection:close", //请求头:请求完成后关闭连接
"Cache-Control:no-cache"}) //禁用缓存
//该方法获取书籍的内容通过URL传递获取内容的地址
Observable<String> getBookContent(@Url String url);
@GET
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
"Accept-Charset:UTF-8",
"Connection:close",
"Cache-Control:no-cache"})
//定义获取章节列表的方法,同样类似上述方法
@GET //定义GET请求
//设置请求头
@Headers({"Accept:text/html,application/xhtml+xml,application/xml", //请求头:表示支持的响应类型
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3", //设置User-Agent模拟浏览器请求
"Accept-Charset:UTF-8", //请求头:指定字符集为 UTF-8
"Connection:close", //请求头:请求完成后关闭连接
"Cache-Control:no-cache"}) //禁用缓存
//该方法获取书籍的章节列表通过URL传递获取章节的地址
Observable<String> getChapterList(@Url String url);
}

@ -1,61 +1,79 @@
//Copyright (c) 2017. 章钦豪. All rights reserved.
//定义包名,表明该接口属于 "monkeybook" 项目中的 API 部分
package com.monke.monkeybook.common.api;
//引入所需的库
import io.reactivex.Observable; //引入RxJava中的Observable用于定义响应式流
import retrofit2.http.Field; //引入Retrofit中的@Field 注解用于表示POST请求中的表单字段
import retrofit2.http.FormUrlEncoded; //引入Retrofit中的@FormUrlEncoded注解用于标记表单请求
import retrofit2.http.GET; //引入Retrofit中的@GET注解用于定义GET请求
import retrofit2.http.Headers; //引入Retrofit中的@Headers注解用于添加HTTP请求头
import retrofit2.http.Query; //引入Retrofit中的@Query注解用于在URL中添加查询参数
import retrofit2.http.Url; //引入Retrofit中的@Url注解用于动态传递URL
import io.reactivex.Observable;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.Query;
import retrofit2.http.Url;
//该API接口定义了与小说网站进行交互的方法用于获取书籍信息、搜索书籍、获取书籍内容等。
public interface IGxwztvApi {
@GET
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
"Accept-Charset:UTF-8",
"Connection:close",
"Cache-Control:no-cache"})
//获取书籍信息的请求
@GET //定义GET请求
//设置请求头
@Headers({"Accept:text/html,application/xhtml+xml,application/xml", //设置请求头:接受的响应类型
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3", //设置User-Agent模拟浏览器请求
"Accept-Charset:UTF-8", //设置字符集为 UTF-8
"Connection:close", //请求头:请求完成后关闭连接
"Cache-Control:no-cache"}) //禁用缓存
//该方法接收一个动态URL返回Observable<String>,表示异步的响应数据流
Observable<String> getBookInfo(@Url String url);
@GET("/search.htm")
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
"Accept-Charset:UTF-8",
"Connection:close",
"Cache-Control:no-cache"})
//搜索书籍的请求
@GET("/search.htm") //定义固定的GET请求路径为"/search.htm"
//设置请求头
@Headers({"Accept:text/html,application/xhtml+xml,application/xml", //设置请求头:接受的响应类型
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3", //设置User-Agent模拟浏览器请求
"Accept-Charset:UTF-8", //设置字符集为 UTF-8
"Connection:close", //请求头:请求完成后关闭连接
"Cache-Control:no-cache"}) //禁用缓存
//使用@Query注解传递查询参数表示关键词和页码
Observable<String> searchBook(@Query("keyword")String content, @Query("pn")int page);
@GET
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
"Accept-Charset:UTF-8",
"Connection:close",
"Cache-Control:no-cache"})
//获取书籍内容的请求
@GET //定义GET请求
//设置请求头
@Headers({"Accept:text/html,application/xhtml+xml,application/xml", //请求头:表示支持的响应类型
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3", //设置User-Agent模拟浏览器请求
"Accept-Charset:UTF-8", //设置字符集为 UTF-8
"Connection:close", //请求头:请求完成后关闭连接
"Cache-Control:no-cache"}) //禁用缓存
//该方法接收动态URL返回书籍的内容
Observable<String> getBookContent(@Url String url);
@GET
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
"Accept-Charset:UTF-8",
"Connection:close",
"Cache-Control:no-cache"})
//获取章节列表的请求
@GET //定义GET请求
//设置请求头
@Headers({"Accept:text/html,application/xhtml+xml,application/xml", //请求头:表示支持的响应类型
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3", //设置User-Agent模拟浏览器请求
"Accept-Charset:UTF-8", //设置字符集为 UTF-8
"Connection:close", //请求头:请求完成后关闭连接
"Cache-Control:no-cache"}) //禁用缓存
//该方法接收动态URL返回章节列表
Observable<String> getChapterList(@Url String url);
@GET
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
"Accept-Charset:UTF-8",
"Connection:close",
"Cache-Control:no-cache"})
//获取书籍类型相关书籍的请求
@GET //定义GET请求
//设置请求头
@Headers({"Accept:text/html,application/xhtml+xml,application/xml", //请求头:表示支持的响应类型
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3", //设置User-Agent模拟浏览器请求
"Accept-Charset:UTF-8", //设置字符集为 UTF-8
"Connection:close", //请求头:请求完成后关闭连接
"Cache-Control:no-cache"}) //禁用缓存
//该方法接收动态URL返回该类型的书籍
Observable<String> getKindBooks(@Url String url);
@GET
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
"Accept-Charset:UTF-8",
"Connection:close",
"Cache-Control:no-cache"})
// 获取图书馆数据的请求
@GET //定义GET请求
//设置请求头
@Headers({"Accept:text/html,application/xhtml+xml,application/xml", //请求头:表示支持的响应类型
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3", //设置User-Agent模拟浏览器请求
"Accept-Charset:UTF-8", //设置字符集为 UTF-8
"Connection:close", //请求头:请求完成后关闭连接
"Cache-Control:no-cache"}) //禁用缓存
//该方法接收动态URL返回图书馆相关的数据
Observable<String> getLibraryData(@Url String url);
}

@ -1,43 +1,54 @@
//Copyright (c) 2017. 章钦豪. All rights reserved.
//定义包路径,表示该接口属于"monkeybook"项目中的公共API部分
package com.monke.monkeybook.common.api;
//引入所需的库
import io.reactivex.Observable; //引入RxJava中的Observable类表示异步流
import retrofit2.http.GET; //引入Retrofit中的@GET注解定义GET请求
import retrofit2.http.Headers; //引入Retrofit中的 @Headers 注解,用于添加自定义请求头
import retrofit2.http.Query; //引入Retrofit中的@Query注解用于在URL中添加查询参数
import retrofit2.http.Url; //引入Retrofit中的@Url注解表示动态传递URL
import io.reactivex.Observable;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.Query;
import retrofit2.http.Url;
//该API接口定义了与零点看书小说网站进行交互的方法用于获取书籍信息、搜索书籍、获取书籍内容等。
public interface ILingdiankanshuApi {
@GET
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
"Accept-Charset:UTF-8",
"Connection:close",
"Cache-Control:no-cache"})
//获取书籍信息的请求
@GET //定义GET请求
//设置自定义的HTTP请求头
@Headers({"Accept:text/html,application/xhtml+xml,application/xml", //请求头:表示支持的响应类型
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3", //模拟浏览器的User-Agent
"Accept-Charset:UTF-8", //请求头:指定字符集为 UTF-8
"Connection:close", //请求头:请求完成后关闭连接
"Cache-Control:no-cache"}) //请求头:禁用缓存
//该方法接受一个动态URL返回一个Observable<String>类型的响应流,表示书籍信息
Observable<String> getBookInfo(@Url String url);
@GET("/cse/search")
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
"Accept-Charset:UTF-8",
"Connection:close",
"Cache-Control:no-cache"})
//搜索书籍的请求
@GET("/cse/search") //定义GET请求的URL路径"/cse/search"
//设置请求头
@Headers({"Accept:text/html,application/xhtml+xml,application/xml", //请求头:表示支持的响应类型
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3", //模拟浏览器的User-Agent
"Accept-Charset:UTF-8", //请求头:指定字符集为 UTF-8
"Connection:close", //请求头:请求完成后关闭连接
"Cache-Control:no-cache"}) //请求头:禁用缓存
//该方法接受三个查询参数:书籍关键词`q`,页码`p`,以及时间`s`,返回书籍搜索结果
Observable<String> searchBook(@Query("q") String content, @Query("p") int page, @Query("s") String time);
@GET
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
"Accept-Charset:UTF-8",
"Connection:close",
"Cache-Control:no-cache"})
//获取书籍内容的请求
@GET //定义GET请求
//设置请求头
@Headers({"Accept:text/html,application/xhtml+xml,application/xml", //请求头:表示支持的响应类型
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3", //模拟浏览器的User-Agent
"Accept-Charset:UTF-8", //请求头:指定字符集为 UTF-8
"Connection:close", //请求头:请求完成后关闭连接
"Cache-Control:no-cache"}) //请求头:禁用缓存
//该方法接受一个动态URL返回书籍内容
Observable<String> getBookContent(@Url String url);
@GET
@Headers({"Accept:text/html,application/xhtml+xml,application/xml",
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3",
"Accept-Charset:UTF-8",
"Connection:close",
"Cache-Control:no-cache"})
@GET //定义GET请求
//设置请求头
@Headers({"Accept:text/html,application/xhtml+xml,application/xml", //请求头:表示支持的响应类型
"User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3", //模拟浏览器的User-Agent
"Accept-Charset:UTF-8", //请求头:指定字符集为 UTF-8
"Connection:close", //请求头:请求完成后关闭连接
"Cache-Control:no-cache"}) //请求头:禁用缓存
//该方法接受一个动态URL返回书籍的章节列表
Observable<String> getChapterList(@Url String url);
}

@ -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实例
}
}

@ -1,41 +1,48 @@
//Copyright (c) 2017. 章钦豪. All rights reserved.
// 包名声明
package com.monke.monkeybook.dao;
// 导入SQLiteDatabase类用于操作数据库
import android.database.sqlite.SQLiteDatabase;
// 导入MApplication类用于获取应用上下文
import com.monke.monkeybook.MApplication;
public class DbHelper {
private DaoMaster.DevOpenHelper mHelper;
private SQLiteDatabase db;
private DaoMaster mDaoMaster;
private DaoSession mDaoSession;
public class DbHelper {// DbHelper类用于管理GreenDao数据库连接
private DaoMaster.DevOpenHelper mHelper; // DaoMaster.DevOpenHelper实例用于创建和管理数据库
private SQLiteDatabase db; // SQLiteDatabase实例用于数据库操作
private DaoMaster mDaoMaster; // DaoMaster实例用于管理DAO
private DaoSession mDaoSession; // DaoSession实例用于数据库会话
private DbHelper(){
private DbHelper(){// 私有构造方法,采用单例模式
// 创建DaoMaster.DevOpenHelper实例指定数据库名称为"monkebook_db"游标工厂为null
mHelper = new DaoMaster.DevOpenHelper(MApplication.getInstance(), "monkebook_db", null);
// 获取可写的SQLiteDatabase实例
db = mHelper.getWritableDatabase();
// 注意:该数据库连接属于 DaoMaster所以多个 Session 指的是相同的数据库连接。
mDaoMaster = new DaoMaster(db);
mDaoSession = mDaoMaster.newSession();
mDaoMaster = new DaoMaster(db);// 创建DaoMaster实例使用获取的SQLiteDatabase实例
mDaoSession = mDaoMaster.newSession();// 创建DaoSession实例
}
// DbHelper的单例实例
private static DbHelper instance;
public static DbHelper getInstance(){
if(null == instance){
synchronized (DbHelper.class){
if(null == instance){
instance = new DbHelper();
public static DbHelper getInstance(){// 获取DbHelper单例实例的方法
if(null == instance){// 判断单例实例是否为空
synchronized (DbHelper.class){// 同步块,保证线程安全
if(null == instance){// 再次判断单例实例是否为空,避免重复创建
instance = new DbHelper();// 创建DbHelper实例
}
}
}
// 返回单例实例
return instance;
}
public DaoSession getmDaoSession() {
public DaoSession getmDaoSession() {// 获取DaoSession实例的方法
// 返回DaoSession实例
return mDaoSession;
}
public SQLiteDatabase getDb() {
public SQLiteDatabase getDb() { // 获取SQLiteDatabase实例的方法
// 返回SQLiteDatabase实例
return db;
}
}

@ -1,185 +1,241 @@
// 包名声明
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类GreenDao框架中数据库字段的属性类
import org.greenrobot.greendao.internal.DaoConfig; // 导入DaoConfig类GreenDao框架中用于配置Dao对象的配置信息
import org.greenrobot.greendao.database.Database; // 导入Database类GreenDao框架中数据库操作的接口
import org.greenrobot.greendao.database.DatabaseStatement; // 导入DatabaseStatement类GreenDao框架中用于执行SQL语句的接口
// 导入DownloadChapterBean类
import com.monke.monkeybook.bean.DownloadChapterBean;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
/**
* DAO for table "DOWNLOAD_CHAPTER_BEAN".
*/
public class DownloadChapterBeanDao extends AbstractDao<DownloadChapterBean, String> {
*/
public class DownloadChapterBeanDao extends AbstractDao<DownloadChapterBean, String> { // DownloadChapterBeanDao类继承AbstractDao主键类型为String
// 表名常量,表示数据库表的名称
public static final String TABLENAME = "DOWNLOAD_CHAPTER_BEAN";
/**
* Properties of entity DownloadChapterBean.<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 BookName = new Property(5, String.class, "bookName", false, "BOOK_NAME");
public final static Property CoverUrl = new Property(6, String.class, "coverUrl", false, "COVER_URL");
*/
public static class Properties {// 属性类定义DownloadChapterBean实体类的属性
public final static Property NoteUrl = new Property(0, String.class, "noteUrl", false, "NOTE_URL");// noteUrl属性
public final static Property DurChapterIndex = new Property(1, int.class, "durChapterIndex", false, "DUR_CHAPTER_INDEX");// durChapterIndex属性
public final static Property DurChapterUrl = new Property(2, String.class, "durChapterUrl", true, "DUR_CHAPTER_URL");// durChapterUrl属性主键
public final static Property DurChapterName = new Property(3, String.class, "durChapterName", false, "DUR_CHAPTER_NAME");// durChapterName属性
public final static Property Tag = new Property(4, String.class, "tag", false, "TAG");// tag属性
public final static Property BookName = new Property(5, String.class, "bookName", false, "BOOK_NAME");// bookName属性
public final static Property CoverUrl = new Property(6, String.class, "coverUrl", false, "COVER_URL");// coverUrl属性
};
public DownloadChapterBeanDao(DaoConfig config) {
super(config);
public DownloadChapterBeanDao(DaoConfig config) {// 构造函数传入DaoConfig配置初始化父类
super(config);// 调用父类构造函数
}
public DownloadChapterBeanDao(DaoConfig config, DaoSession daoSession) {
super(config, daoSession);
public DownloadChapterBeanDao(DaoConfig config, DaoSession daoSession) {// 传入DaoConfig和DaoSession对象初始化父类
super(config, daoSession);// 调用父类构造函数
}
/** Creates the underlying database table. */
public static void createTable(Database db, boolean ifNotExists) {
public static void createTable(Database db, boolean ifNotExists) {// 创建表的方法传入Database对象和是否忽略表已存在的标志
// 判断是否忽略表已存在构造SQL语句的一部分
String constraint = ifNotExists? "IF NOT EXISTS ": "";
db.execSQL("CREATE TABLE " + constraint + "\"DOWNLOAD_CHAPTER_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
"\"BOOK_NAME\" TEXT," + // 5: bookName
"\"COVER_URL\" TEXT);"); // 6: coverUrl
db.execSQL("CREATE TABLE " + constraint + "\"DOWNLOAD_CHAPTER_BEAN\" (" + //执行创建表的SQL语句
"\"NOTE_URL\" TEXT," + // 0: noteUrl.表中字段NOTE_URL数据类型为TEXT
"\"DUR_CHAPTER_INDEX\" INTEGER NOT NULL ," + // 1: durChapterIndex.DUR_CHAPTER_INDEX字段整型非空
"\"DUR_CHAPTER_URL\" TEXT PRIMARY KEY NOT NULL ," + // 2: durChapterUrl.DUR_CHAPTER_URL字段文本类型主键非空
"\"DUR_CHAPTER_NAME\" TEXT," + // 3: durChapterName.DUR_CHAPTER_NAME字段文本类型
"\"TAG\" TEXT," + // 4: tag.TAG字段文本类型
"\"BOOK_NAME\" TEXT," + // 5: bookName.BOOK_NAME字段文本类型
"\"COVER_URL\" TEXT);"); // 6: coverUrl.COVER_URL字段文本类型
}
/** Drops the underlying database table. */
public static void dropTable(Database db, boolean ifExists) {
/** Drops the underlying database table.
*
*/
public static void dropTable(Database db, boolean ifExists) {// 删除表的方法传入Database对象和是否忽略表不存在的标志
// 构造删除表的SQL语句
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"DOWNLOAD_CHAPTER_BEAN\"";
// 执行删除表的SQL语句
db.execSQL(sql);
}
@Override
// 将实体对象绑定到DatabaseStatement语句中
protected final void bindValues(DatabaseStatement stmt, DownloadChapterBean entity) {
// 清空绑定
stmt.clearBindings();
// 获取noteUrl值
String noteUrl = entity.getNoteUrl();
// 判断noteUrl是否为空
if (noteUrl != null) {
// 绑定noteUrl值到第一个参数位置
stmt.bindString(1, noteUrl);
}
// 绑定durChapterIndex值到第二个参数位置
stmt.bindLong(2, entity.getDurChapterIndex());
// 获取durChapterUrl值
String durChapterUrl = entity.getDurChapterUrl();
// 判断durChapterUrl是否为空
if (durChapterUrl != null) {
// 绑定durChapterUrl值到第三个参数位置
stmt.bindString(3, durChapterUrl);
}
// 获取durChapterName值
String durChapterName = entity.getDurChapterName();
// 判断durChapterName是否为空
if (durChapterName != null) {
// 绑定durChapterName值到第四个参数位置
stmt.bindString(4, durChapterName);
}
// 获取tag值
String tag = entity.getTag();
// 判断tag是否为空
if (tag != null) {
// 绑定tag值到第五个参数位置
stmt.bindString(5, tag);
}
// 获取bookName值
String bookName = entity.getBookName();
// 判断bookName是否为空
if (bookName != null) {
// 绑定bookName值到第六个参数位置
stmt.bindString(6, bookName);
}
// 获取coverUrl值
String coverUrl = entity.getCoverUrl();
// 判断coverUrl是否为空
if (coverUrl != null) {
// 绑定coverUrl值到第七个参数位置
stmt.bindString(7, coverUrl);
}
}
@Override
// 将实体对象绑定到SQLiteStatement语句中.与上面的方法基本一致只是使用的Statement类型不同
protected final void bindValues(SQLiteStatement stmt, DownloadChapterBean entity) {
// 清空绑定
stmt.clearBindings();
// 获取noteUrl值
String noteUrl = entity.getNoteUrl();
// 判断noteUrl是否为空
if (noteUrl != null) {
stmt.bindString(1, noteUrl);
stmt.bindString(1, noteUrl);// 绑定noteUrl值到第一个参数位置
}
stmt.bindLong(2, entity.getDurChapterIndex());
stmt.bindLong(2, entity.getDurChapterIndex());// 绑定durChapterIndex值到第二个参数位置
// 获取durChapterUrl值
String durChapterUrl = entity.getDurChapterUrl();
// 判断durChapterUrl是否为空
if (durChapterUrl != null) {
stmt.bindString(3, durChapterUrl);
stmt.bindString(3, durChapterUrl);// 绑定durChapterUrl值到第三个参数位置
}
// 获取durChapterName值
String durChapterName = entity.getDurChapterName();
// 判断durChapterName是否为空
if (durChapterName != null) {
stmt.bindString(4, durChapterName);
stmt.bindString(4, durChapterName);// 绑定durChapterName值到第四个参数位置
}
// 获取tag值
String tag = entity.getTag();
// 判断tag是否为空
if (tag != null) {
stmt.bindString(5, tag);
stmt.bindString(5, tag); // 绑定tag值到第五个参数位置
}
// 获取bookName值
String bookName = entity.getBookName();
// 判断bookName是否为空
if (bookName != null) {
stmt.bindString(6, bookName);
stmt.bindString(6, bookName);// 绑定bookName值到第六个参数位置
}
// 获取coverUrl值
String coverUrl = entity.getCoverUrl();
// 判断coverUrl是否为空
if (coverUrl != null) {
stmt.bindString(7, coverUrl);
stmt.bindString(7, coverUrl);// 绑定coverUrl值到第七个参数位置
}
}
@Override
// 从游标读取主键
public String readKey(Cursor cursor, int offset) {
// 读取第三列索引为2如果为空返回null否则返回字符串
return cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2);
}
}
@Override
// 从游标读取实体对象
public DownloadChapterBean readEntity(Cursor cursor, int offset) {
// 创建DownloadChapterBean对象
DownloadChapterBean entity = new DownloadChapterBean( //
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.getString(offset + 5), // bookName
cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6) // coverUrl
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.getString(offset + 5), // bookName
cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6) // coverUrl
);
// 返回创建的DownloadChapterBean对象
return entity;
}
@Override
// 将游标数据读取到实体对象中
public void readEntity(Cursor cursor, DownloadChapterBean 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.setBookName(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
entity.setCoverUrl(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
}
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.setBookName(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));// 设置bookName
entity.setCoverUrl(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));// 设置coverUrl
}
@Override
// 插入后更新主键
protected final String updateKeyAfterInsert(DownloadChapterBean entity, long rowId) {
// 返回durChapterUrl作为主键
return entity.getDurChapterUrl();
}
@Override
// 获取主键
public String getKey(DownloadChapterBean entity) {
// 判断实体对象是否为空
if(entity != null) {
// 返回durChapterUrl作为主键
return entity.getDurChapterUrl();
} else {
// 实体对象为空返回null
return null;
}
}
@Override
// 判断实体是否可更新
protected final boolean isEntityUpdateable() {
// 返回true表示实体可更新
return true;
}
}

@ -1,136 +1,171 @@
// 包名声明
package com.monke.monkeybook.dao;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;
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 org.greenrobot.greendao.AbstractDao;// GreenDao框架提供的抽象DAO类
import org.greenrobot.greendao.Property;// GreenDao框架提供的属性类用于定义数据库表的字段属性
import org.greenrobot.greendao.internal.DaoConfig;// GreenDao框架提供的DAO配置类
import org.greenrobot.greendao.database.Database;// GreenDao框架提供的数据库操作接口
import org.greenrobot.greendao.database.DatabaseStatement;// GreenDao框架提供的数据库语句执行接口
import com.monke.monkeybook.bean.SearchHistoryBean;
import com.monke.monkeybook.bean.SearchHistoryBean;// 搜索历史Bean类
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
/**
* DAO for table "SEARCH_HISTORY_BEAN".
*/
public class SearchHistoryBeanDao extends AbstractDao<SearchHistoryBean, Long> {
*/
public class SearchHistoryBeanDao extends AbstractDao<SearchHistoryBean, Long> {// 继承AbstractDao主键类型为Long
// 数据库表名
public static final String TABLENAME = "SEARCH_HISTORY_BEAN";
/**
* Properties of entity SearchHistoryBean.<br/>
* Can be used for QueryBuilder and for referencing column names.
*/
*/
public static class Properties {
public final static Property Id = new Property(0, Long.class, "id", true, "_id");
public final static Property Type = new Property(1, int.class, "type", false, "TYPE");
public final static Property Content = new Property(2, String.class, "content", false, "CONTENT");
public final static Property Date = new Property(3, long.class, "date", false, "DATE");
// 定义SearchHistoryBean实体类的属性
public final static Property Id = new Property(0, Long.class, "id", true, "_id");// id属性主键自增
public final static Property Type = new Property(1, int.class, "type", false, "TYPE");// type属性整型
public final static Property Content = new Property(2, String.class, "content", false, "CONTENT");// content属性字符串
public final static Property Date = new Property(3, long.class, "date", false, "DATE");// date属性长整型
};
public SearchHistoryBeanDao(DaoConfig config) {
public SearchHistoryBeanDao(DaoConfig config) {// 构造函数传入DAO配置
// 调用父类构造函数
super(config);
}
public SearchHistoryBeanDao(DaoConfig config, DaoSession daoSession) {
public SearchHistoryBeanDao(DaoConfig config, DaoSession daoSession) {// 构造函数传入DAO配置和DAO会话
// 调用父类构造函数
super(config, daoSession);
}
/** Creates the underlying database table. */
public static void createTable(Database db, boolean ifNotExists) {
/** Creates the underlying database table.
*
*/
public static void createTable(Database db, boolean ifNotExists) {// 创建表的静态方法
// 判断是否需要检查表是否存在构建SQL语句
String constraint = ifNotExists? "IF NOT EXISTS ": "";
// 执行创建表语句
db.execSQL("CREATE TABLE " + constraint + "\"SEARCH_HISTORY_BEAN\" (" + //
"\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
"\"TYPE\" INTEGER NOT NULL ," + // 1: type
"\"CONTENT\" TEXT," + // 2: content
"\"DATE\" INTEGER NOT NULL );"); // 3: date
"\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id _id列主键自增
"\"TYPE\" INTEGER NOT NULL ," + // 1: type TYPE列整型非空
"\"CONTENT\" TEXT," + // 2: content CONTENT列文本类型
"\"DATE\" INTEGER NOT NULL );"); // 3: date DATE列整型非空
}
/** Drops the underlying database table. */
public static void dropTable(Database db, boolean ifExists) {
/** Drops the underlying database table.
*
*/
public static void dropTable(Database db, boolean ifExists) {// 删除表的静态方法
// 构建删除表语句
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"SEARCH_HISTORY_BEAN\"";
// 执行删除表语句
db.execSQL(sql);
}
@Override
// 将实体对象绑定到DatabaseStatement语句
protected final void bindValues(DatabaseStatement stmt, SearchHistoryBean entity) {
// 清除之前的绑定
stmt.clearBindings();
// 获取实体对象的id
Long id = entity.getId();
// 判断id是否为空
if (id != null) {
stmt.bindLong(1, id);
stmt.bindLong(1, id);// 绑定id到第一个参数
}
stmt.bindLong(2, entity.getType());
stmt.bindLong(2, entity.getType());// 绑定type到第二个参数
// 获取实体对象的content
String content = entity.getContent();
// 判断content是否为空
if (content != null) {
// 绑定content到第三个参数
stmt.bindString(3, content);
}
stmt.bindLong(4, entity.getDate());
stmt.bindLong(4, entity.getDate());// 绑定date到第四个参数
}
@Override
@Override// 将实体对象绑定到SQLiteStatement语句, 和上面方法类似只是Statement类型不同
protected final void bindValues(SQLiteStatement stmt, SearchHistoryBean entity) {
// 清除之前的绑定
stmt.clearBindings();
// 获取实体对象的id
Long id = entity.getId();
// 判断id是否为空
if (id != null) {
stmt.bindLong(1, id);
stmt.bindLong(1, id);// 绑定id到第一个参数
}
stmt.bindLong(2, entity.getType());
stmt.bindLong(2, entity.getType());// 绑定type到第二个参数
// 获取实体对象的content
String content = entity.getContent();
// 判断content是否为空
if (content != null) {
stmt.bindString(3, content);
stmt.bindString(3, content);// 绑定content到第三个参数
}
stmt.bindLong(4, entity.getDate());
stmt.bindLong(4, entity.getDate());// 绑定date到第四个参数
}
@Override
// 从Cursor读取主键
public Long readKey(Cursor cursor, int offset) {
// 从Cursor的第offset+0列读取Long类型的主键如果为空则返回null
return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
}
}
@Override
// 从Cursor读取实体对象
public SearchHistoryBean readEntity(Cursor cursor, int offset) {
SearchHistoryBean entity = new SearchHistoryBean( //
cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
cursor.getInt(offset + 1), // type
cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // content
cursor.getLong(offset + 3) // date
cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
cursor.getInt(offset + 1), // type
cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // content
cursor.getLong(offset + 3) // date
);
// 返回创建的SearchHistoryBean对象
return entity;
}
@Override
// 将Cursor数据读入到实体对象中
public void readEntity(Cursor cursor, SearchHistoryBean entity, int offset) {
entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
entity.setType(cursor.getInt(offset + 1));
entity.setContent(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
entity.setDate(cursor.getLong(offset + 3));
}
entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));// 设置id
entity.setType(cursor.getInt(offset + 1));// 设置type
entity.setContent(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));// 设置content
entity.setDate(cursor.getLong(offset + 3));// 设置date
}
@Override
// 插入数据后更新主键
protected final Long updateKeyAfterInsert(SearchHistoryBean entity, long rowId) {
// 设置主键为rowId
entity.setId(rowId);
// 返回rowId
return rowId;
}
@Override
// 获取主键
public Long getKey(SearchHistoryBean entity) {
// 判断实体对象是否为空
if(entity != null) {
return entity.getId();
return entity.getId();// 返回实体对象的id
} else {
return null;
return null;// 返回null
}
}
@Override
// 判断实体是否可更新
protected final boolean isEntityUpdateable() {
return true;
return true;// 返回true表示实体可更新
}
}

@ -1,9 +1,11 @@
//Copyright (c) 2017. 章钦豪. All rights reserved.
// 包名声明
package com.monke.monkeybook.listener;
import com.monke.monkeybook.bean.BookShelfBean;
import com.monke.monkeybook.bean.BookShelfBean;// 导入BookShelfBean类
public interface OnGetChapterListListener {
public void success(BookShelfBean bookShelfBean);
public void error();
public interface OnGetChapterListListener {// 定义一个接口,用于监听获取章节列表的结果
public void success(BookShelfBean bookShelfBean); // 获取章节列表成功时的回调方法参数为BookShelfBean对象
// 表示获取章节列表操作成功并传入包含章节信息的BookShelfBean对象。
public void error();// 获取章节列表失败时的回调方法
// 表示获取章节列表操作失败
}

Loading…
Cancel
Save