package model.daoModels;
import java.util.List;
import java.util.ArrayList;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;
import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.Property;
import de.greenrobot.dao.internal.SqlUtils;
import de.greenrobot.dao.internal.DaoConfig;
import de.greenrobot.dao.query.Query;
import de.greenrobot.dao.query.QueryBuilder;
import model.daoModels.AudioChapter;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* DAO for table "AUDIO_CHAPTER".
*/
public class AudioChapterDao extends AbstractDao<AudioChapter, Long> {
public static final String TABLENAME = "AUDIO_CHAPTER";
/**
* Properties of entity AudioChapter.<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 BitrateJson = new Property(1, String.class, "bitrateJson", false, "BITRATE_JSON");
public final static Property UniqueSlug = new Property(2, String.class, "uniqueSlug", false, "UNIQUE_SLUG");
public final static Property Source = new Property(3, String.class, "source", false, "SOURCE");
public final static Property SourceSignature = new Property(4, String.class, "sourceSignature", false, "SOURCE_SIGNATURE");
public final static Property Chapter = new Property(5, Integer.class, "chapter", false, "CHAPTER");
public final static Property Length = new Property(6, Integer.class, "length", false, "LENGTH");
public final static Property AudioBookId = new Property(7, long.class, "audioBookId", false, "AUDIO_BOOK_ID");
};
private DaoSession daoSession;
private Query<AudioChapter> audioBook_AudioChaptersQuery;
public AudioChapterDao(DaoConfig config) {
super(config);
}
public AudioChapterDao(DaoConfig config, DaoSession daoSession) {
super(config, daoSession);
this.daoSession = daoSession;
}
/** Creates the underlying database table. */
public static void createTable(SQLiteDatabase db, boolean ifNotExists) {
String constraint = ifNotExists? "IF NOT EXISTS ": "";
db.execSQL("CREATE TABLE " + constraint + "\"AUDIO_CHAPTER\" (" + //
"\"_id\" INTEGER PRIMARY KEY ," + // 0: id
"\"BITRATE_JSON\" TEXT," + // 1: bitrateJson
"\"UNIQUE_SLUG\" TEXT," + // 2: uniqueSlug
"\"SOURCE\" TEXT," + // 3: source
"\"SOURCE_SIGNATURE\" TEXT," + // 4: sourceSignature
"\"CHAPTER\" INTEGER," + // 5: chapter
"\"LENGTH\" INTEGER," + // 6: length
"\"AUDIO_BOOK_ID\" INTEGER NOT NULL );"); // 7: audioBookId
}
/** Drops the underlying database table. */
public static void dropTable(SQLiteDatabase db, boolean ifExists) {
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"AUDIO_CHAPTER\"";
db.execSQL(sql);
}
/** @inheritdoc */
@Override
protected void bindValues(SQLiteStatement stmt, AudioChapter entity) {
stmt.clearBindings();
Long id = entity.getId();
if (id != null) {
stmt.bindLong(1, id);
}
String bitrateJson = entity.getBitrateJson();
if (bitrateJson != null) {
stmt.bindString(2, bitrateJson);
}
String uniqueSlug = entity.getUniqueSlug();
if (uniqueSlug != null) {
stmt.bindString(3, uniqueSlug);
}
String source = entity.getSource();
if (source != null) {
stmt.bindString(4, source);
}
String sourceSignature = entity.getSourceSignature();
if (sourceSignature != null) {
stmt.bindString(5, sourceSignature);
}
Integer chapter = entity.getChapter();
if (chapter != null) {
stmt.bindLong(6, chapter);
}
Integer length = entity.getLength();
if (length != null) {
stmt.bindLong(7, length);
}
stmt.bindLong(8, entity.getAudioBookId());
}
@Override
protected void attachEntity(AudioChapter entity) {
super.attachEntity(entity);
entity.__setDaoSession(daoSession);
}
/** @inheritdoc */
@Override
public Long readKey(Cursor cursor, int offset) {
return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
}
/** @inheritdoc */
@Override
public AudioChapter readEntity(Cursor cursor, int offset) {
AudioChapter entity = new AudioChapter( //
cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // bitrateJson
cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // uniqueSlug
cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // source
cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // sourceSignature
cursor.isNull(offset + 5) ? null : cursor.getInt(offset + 5), // chapter
cursor.isNull(offset + 6) ? null : cursor.getInt(offset + 6), // length
cursor.getLong(offset + 7) // audioBookId
);
return entity;
}
/** @inheritdoc */
@Override
public void readEntity(Cursor cursor, AudioChapter entity, int offset) {
entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
entity.setBitrateJson(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
entity.setUniqueSlug(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
entity.setSource(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
entity.setSourceSignature(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
entity.setChapter(cursor.isNull(offset + 5) ? null : cursor.getInt(offset + 5));
entity.setLength(cursor.isNull(offset + 6) ? null : cursor.getInt(offset + 6));
entity.setAudioBookId(cursor.getLong(offset + 7));
}
/** @inheritdoc */
@Override
protected Long updateKeyAfterInsert(AudioChapter entity, long rowId) {
entity.setId(rowId);
return rowId;
}
/** @inheritdoc */
@Override
public Long getKey(AudioChapter entity) {
if(entity != null) {
return entity.getId();
} else {
return null;
}
}
/** @inheritdoc */
@Override
protected boolean isEntityUpdateable() {
return true;
}
/** Internal query to resolve the "audioChapters" to-many relationship of AudioBook. */
public List<AudioChapter> _queryAudioBook_AudioChapters(long audioBookId) {
synchronized (this) {
if (audioBook_AudioChaptersQuery == null) {
QueryBuilder<AudioChapter> queryBuilder = queryBuilder();
queryBuilder.where(Properties.AudioBookId.eq(null));
audioBook_AudioChaptersQuery = queryBuilder.build();
}
}
Query<AudioChapter> query = audioBook_AudioChaptersQuery.forCurrentThread();
query.setParameter(0, audioBookId);
return query.list();
}
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.getAudioBookDao().getAllColumns());
builder.append(" FROM AUDIO_CHAPTER T");
builder.append(" LEFT JOIN AUDIO_BOOK T0 ON T.\"AUDIO_BOOK_ID\"=T0.\"_id\"");
builder.append(' ');
selectDeep = builder.toString();
}
return selectDeep;
}
protected AudioChapter loadCurrentDeep(Cursor cursor, boolean lock) {
AudioChapter entity = loadCurrent(cursor, 0, lock);
int offset = getAllColumns().length;
AudioBook audioBook = loadCurrentOther(daoSession.getAudioBookDao(), cursor, offset);
if(audioBook != null) {
entity.setAudioBook(audioBook);
}
return entity;
}
public AudioChapter 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<AudioChapter> loadAllDeepFromCursor(Cursor cursor) {
int count = cursor.getCount();
List<AudioChapter> list = new ArrayList<AudioChapter>(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<AudioChapter> 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<AudioChapter> queryDeep(String where, String... selectionArg) {
Cursor cursor = db.rawQuery(getSelectDeep() + where, selectionArg);
return loadDeepAllAndCloseCursor(cursor);
}
}