package com.codingbingo.fastreader.dao;
import java.util.List;
import java.util.ArrayList;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;
import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.SqlUtils;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* DAO for table "CHAPTER".
*/
public class ChapterDao extends AbstractDao<Chapter, Long> {
public static final String TABLENAME = "CHAPTER";
/**
* Properties of entity Chapter.<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 Title = new Property(1, String.class, "title", false, "TITLE");
public final static Property Position = new Property(2, int.class, "position", false, "POSITION");
public final static Property PageCount = new Property(3, Integer.class, "pageCount", false, "PAGE_COUNT");
public final static Property IsRead = new Property(4, Boolean.class, "isRead", false, "IS_READ");
public final static Property BookId = new Property(5, long.class, "bookId", false, "BOOK_ID");
}
private DaoSession daoSession;
public ChapterDao(DaoConfig config) {
super(config);
}
public ChapterDao(DaoConfig config, DaoSession daoSession) {
super(config, daoSession);
this.daoSession = daoSession;
}
/** Creates the underlying database table. */
public static void createTable(Database db, boolean ifNotExists) {
String constraint = ifNotExists? "IF NOT EXISTS ": "";
db.execSQL("CREATE TABLE " + constraint + "\"CHAPTER\" (" + //
"\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
"\"TITLE\" TEXT," + // 1: title
"\"POSITION\" INTEGER NOT NULL ," + // 2: position
"\"PAGE_COUNT\" INTEGER," + // 3: pageCount
"\"IS_READ\" INTEGER," + // 4: isRead
"\"BOOK_ID\" INTEGER NOT NULL );"); // 5: bookId
}
/** Drops the underlying database table. */
public static void dropTable(Database db, boolean ifExists) {
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"CHAPTER\"";
db.execSQL(sql);
}
@Override
protected final void bindValues(DatabaseStatement stmt, Chapter entity) {
stmt.clearBindings();
Long id = entity.getId();
if (id != null) {
stmt.bindLong(1, id);
}
String title = entity.getTitle();
if (title != null) {
stmt.bindString(2, title);
}
stmt.bindLong(3, entity.getPosition());
Integer pageCount = entity.getPageCount();
if (pageCount != null) {
stmt.bindLong(4, pageCount);
}
Boolean isRead = entity.getIsRead();
if (isRead != null) {
stmt.bindLong(5, isRead ? 1L: 0L);
}
stmt.bindLong(6, entity.getBookId());
}
@Override
protected final void bindValues(SQLiteStatement stmt, Chapter entity) {
stmt.clearBindings();
Long id = entity.getId();
if (id != null) {
stmt.bindLong(1, id);
}
String title = entity.getTitle();
if (title != null) {
stmt.bindString(2, title);
}
stmt.bindLong(3, entity.getPosition());
Integer pageCount = entity.getPageCount();
if (pageCount != null) {
stmt.bindLong(4, pageCount);
}
Boolean isRead = entity.getIsRead();
if (isRead != null) {
stmt.bindLong(5, isRead ? 1L: 0L);
}
stmt.bindLong(6, entity.getBookId());
}
@Override
protected final void attachEntity(Chapter entity) {
super.attachEntity(entity);
entity.__setDaoSession(daoSession);
}
@Override
public Long readKey(Cursor cursor, int offset) {
return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
}
@Override
public Chapter readEntity(Cursor cursor, int offset) {
Chapter entity = new Chapter( //
cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // title
cursor.getInt(offset + 2), // position
cursor.isNull(offset + 3) ? null : cursor.getInt(offset + 3), // pageCount
cursor.isNull(offset + 4) ? null : cursor.getShort(offset + 4) != 0, // isRead
cursor.getLong(offset + 5) // bookId
);
return entity;
}
@Override
public void readEntity(Cursor cursor, Chapter entity, int offset) {
entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
entity.setTitle(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
entity.setPosition(cursor.getInt(offset + 2));
entity.setPageCount(cursor.isNull(offset + 3) ? null : cursor.getInt(offset + 3));
entity.setIsRead(cursor.isNull(offset + 4) ? null : cursor.getShort(offset + 4) != 0);
entity.setBookId(cursor.getLong(offset + 5));
}
@Override
protected final Long updateKeyAfterInsert(Chapter entity, long rowId) {
entity.setId(rowId);
return rowId;
}
@Override
public Long getKey(Chapter entity) {
if(entity != null) {
return entity.getId();
} else {
return null;
}
}
@Override
public boolean hasKey(Chapter entity) {
return entity.getId() != null;
}
@Override
protected final boolean isEntityUpdateable() {
return true;
}
private String selectDeep;
protected String getSelectDeep() {
if (selectDeep == null) {
StringBuilder builder = new StringBuilder("SELECT ");
SqlUtils.appendColumns(builder, "T", getAllColumns());
builder.append(',');
SqlUtils.appendColumns(builder, "T0", daoSession.getBookDao().getAllColumns());
builder.append(" FROM CHAPTER T");
builder.append(" LEFT JOIN BOOK T0 ON T.\"BOOK_ID\"=T0.\"_id\"");
builder.append(' ');
selectDeep = builder.toString();
}
return selectDeep;
}
protected Chapter loadCurrentDeep(Cursor cursor, boolean lock) {
Chapter entity = loadCurrent(cursor, 0, lock);
int offset = getAllColumns().length;
Book book = loadCurrentOther(daoSession.getBookDao(), cursor, offset);
if(book != null) {
entity.setBook(book);
}
return entity;
}
public Chapter loadDeep(Long key) {
assertSinglePk();
if (key == null) {
return null;
}
StringBuilder builder = new StringBuilder(getSelectDeep());
builder.append("WHERE ");
SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns());
String sql = builder.toString();
String[] keyArray = new String[] { key.toString() };
Cursor cursor = db.rawQuery(sql, keyArray);
try {
boolean available = cursor.moveToFirst();
if (!available) {
return null;
} else if (!cursor.isLast()) {
throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount());
}
return loadCurrentDeep(cursor, true);
} finally {
cursor.close();
}
}
/** Reads all available rows from the given cursor and returns a list of new ImageTO objects. */
public List<Chapter> loadAllDeepFromCursor(Cursor cursor) {
int count = cursor.getCount();
List<Chapter> list = new ArrayList<Chapter>(count);
if (cursor.moveToFirst()) {
if (identityScope != null) {
identityScope.lock();
identityScope.reserveRoom(count);
}
try {
do {
list.add(loadCurrentDeep(cursor, false));
} while (cursor.moveToNext());
} finally {
if (identityScope != null) {
identityScope.unlock();
}
}
}
return list;
}
protected List<Chapter> loadDeepAllAndCloseCursor(Cursor cursor) {
try {
return loadAllDeepFromCursor(cursor);
} finally {
cursor.close();
}
}
/** A raw-style query where you can pass any WHERE clause and arguments. */
public List<Chapter> queryDeep(String where, String... selectionArg) {
Cursor cursor = db.rawQuery(getSelectDeep() + where, selectionArg);
return loadDeepAllAndCloseCursor(cursor);
}
}