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

@ -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表示实体可更新
}
}

Loading…
Cancel
Save