|
|
|
|
@ -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:名称(name),String类型,非主键,数据库列名NAME
|
|
|
|
|
public final static Property Tag = new Property(1, String.class, "tag", false, "TAG");//属性1:标签(tag),String类型,非主键,数据库列名TAG
|
|
|
|
|
public final static Property NoteUrl = new Property(2, String.class, "noteUrl", true, "NOTE_URL");// 属性2:笔记URL(noteUrl),String类型,主键,非空,数据库列名NOTE_URL
|
|
|
|
|
public final static Property ChapterUrl = new Property(3, String.class, "chapterUrl", false, "CHAPTER_URL");//属性3:章节URL(chapterUrl),String类型,非主键,数据库列名CHAPTER_URL
|
|
|
|
|
public final static Property FinalRefreshData = new Property(4, long.class, "finalRefreshData", false, "FINAL_REFRESH_DATA");//属性4:最后刷新时间(finalRefreshData),long类型,非主键,数据库列名FINAL_REFRESH_DATA
|
|
|
|
|
public final static Property CoverUrl = new Property(5, String.class, "coverUrl", false, "COVER_URL");//属性5:封面URL(coverUrl),String类型,非主键,数据库列名COVER_URL
|
|
|
|
|
public final static Property Author = new Property(6, String.class, "author", false, "AUTHOR");//属性6:作者(author),String类型,非主键,数据库列名AUTHOR
|
|
|
|
|
public final static Property Introduce = new Property(7, String.class, "introduce", false, "INTRODUCE");//属性7:简介(introduce),String类型,非主键,数据库列名INTRODUCE
|
|
|
|
|
public final static Property Origin = new Property(8, String.class, "origin", false, "ORIGIN");//属性8:来源(origin),String类型,非主键,数据库列名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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|