|
|
|
|
@ -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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|