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.StoryPage; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. /** * DAO for table "STORY_PAGE". */ public class StoryPageDao extends AbstractDao<StoryPage, Long> { public static final String TABLENAME = "STORY_PAGE"; /** * Properties of entity StoryPage.<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 UniqueSlug = new Property(1, String.class, "uniqueSlug", false, "UNIQUE_SLUG"); public final static Property Slug = new Property(2, String.class, "slug", false, "SLUG"); public final static Property Number = new Property(3, String.class, "number", false, "NUMBER"); public final static Property Text = new Property(4, String.class, "text", false, "TEXT"); public final static Property ImageUrl = new Property(5, String.class, "imageUrl", false, "IMAGE_URL"); public final static Property StoryChapterId = new Property(6, long.class, "storyChapterId", false, "STORY_CHAPTER_ID"); }; private DaoSession daoSession; private Query<StoryPage> storiesChapter_StoryPagesQuery; public StoryPageDao(DaoConfig config) { super(config); } public StoryPageDao(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 + "\"STORY_PAGE\" (" + // "\"_id\" INTEGER PRIMARY KEY ," + // 0: id "\"UNIQUE_SLUG\" TEXT," + // 1: uniqueSlug "\"SLUG\" TEXT," + // 2: slug "\"NUMBER\" TEXT," + // 3: number "\"TEXT\" TEXT," + // 4: text "\"IMAGE_URL\" TEXT," + // 5: imageUrl "\"STORY_CHAPTER_ID\" INTEGER NOT NULL );"); // 6: storyChapterId } /** Drops the underlying database table. */ public static void dropTable(SQLiteDatabase db, boolean ifExists) { String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"STORY_PAGE\""; db.execSQL(sql); } /** @inheritdoc */ @Override protected void bindValues(SQLiteStatement stmt, StoryPage entity) { stmt.clearBindings(); Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } String uniqueSlug = entity.getUniqueSlug(); if (uniqueSlug != null) { stmt.bindString(2, uniqueSlug); } String slug = entity.getSlug(); if (slug != null) { stmt.bindString(3, slug); } String number = entity.getNumber(); if (number != null) { stmt.bindString(4, number); } String text = entity.getText(); if (text != null) { stmt.bindString(5, text); } String imageUrl = entity.getImageUrl(); if (imageUrl != null) { stmt.bindString(6, imageUrl); } stmt.bindLong(7, entity.getStoryChapterId()); } @Override protected void attachEntity(StoryPage 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 StoryPage readEntity(Cursor cursor, int offset) { StoryPage entity = new StoryPage( // cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // uniqueSlug cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // slug cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // number cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // text cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // imageUrl cursor.getLong(offset + 6) // storyChapterId ); return entity; } /** @inheritdoc */ @Override public void readEntity(Cursor cursor, StoryPage entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); entity.setUniqueSlug(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); entity.setSlug(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); entity.setNumber(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); entity.setText(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); entity.setImageUrl(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); entity.setStoryChapterId(cursor.getLong(offset + 6)); } /** @inheritdoc */ @Override protected Long updateKeyAfterInsert(StoryPage entity, long rowId) { entity.setId(rowId); return rowId; } /** @inheritdoc */ @Override public Long getKey(StoryPage entity) { if(entity != null) { return entity.getId(); } else { return null; } } /** @inheritdoc */ @Override protected boolean isEntityUpdateable() { return true; } /** Internal query to resolve the "storyPages" to-many relationship of StoriesChapter. */ public List<StoryPage> _queryStoriesChapter_StoryPages(long storyChapterId) { synchronized (this) { if (storiesChapter_StoryPagesQuery == null) { QueryBuilder<StoryPage> queryBuilder = queryBuilder(); queryBuilder.where(Properties.StoryChapterId.eq(null)); storiesChapter_StoryPagesQuery = queryBuilder.build(); } } Query<StoryPage> query = storiesChapter_StoryPagesQuery.forCurrentThread(); query.setParameter(0, storyChapterId); 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.getStoriesChapterDao().getAllColumns()); builder.append(" FROM STORY_PAGE T"); builder.append(" LEFT JOIN STORIES_CHAPTER T0 ON T.\"STORY_CHAPTER_ID\"=T0.\"_id\""); builder.append(' '); selectDeep = builder.toString(); } return selectDeep; } protected StoryPage loadCurrentDeep(Cursor cursor, boolean lock) { StoryPage entity = loadCurrent(cursor, 0, lock); int offset = getAllColumns().length; StoriesChapter storiesChapter = loadCurrentOther(daoSession.getStoriesChapterDao(), cursor, offset); if(storiesChapter != null) { entity.setStoriesChapter(storiesChapter); } return entity; } public StoryPage 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<StoryPage> loadAllDeepFromCursor(Cursor cursor) { int count = cursor.getCount(); List<StoryPage> list = new ArrayList<StoryPage>(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<StoryPage> 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<StoryPage> queryDeep(String where, String... selectionArg) { Cursor cursor = db.rawQuery(getSelectDeep() + where, selectionArg); return loadDeepAllAndCloseCursor(cursor); } }