diff options
author | David Development <david-dev@live.de> | 2014-07-28 13:52:21 +0400 |
---|---|---|
committer | David Development <david-dev@live.de> | 2014-07-28 13:53:03 +0400 |
commit | d378e2bba063852a463c8a554afe1566043502ac (patch) | |
tree | 6b85c4b258ccdd86bfad718101df2bd704532951 /News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model | |
parent | bffef458cb3079ef928486ab7e7b2fb4ef454b15 (diff) |
Update Backend to ORM/Remove abs -> appcompat
Diffstat (limited to 'News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model')
10 files changed, 1600 insertions, 0 deletions
diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/CurrentRssItemView.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/CurrentRssItemView.java new file mode 100644 index 00000000..c87a740b --- /dev/null +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/CurrentRssItemView.java @@ -0,0 +1,49 @@ +package de.luhmer.owncloudnewsreader.database.model; + +// THIS CODE IS GENERATED BY greenDAO, EDIT ONLY INSIDE THE "KEEP"-SECTIONS + +// KEEP INCLUDES - put your custom includes here +// KEEP INCLUDES END +/** + * Entity mapped to table CURRENT_RSS_ITEM_VIEW. + */ +public class CurrentRssItemView { + + private long id; + private long rssItemId; + + // KEEP FIELDS - put your custom fields here + // KEEP FIELDS END + + public CurrentRssItemView() { + } + + public CurrentRssItemView(long id) { + this.id = id; + } + + public CurrentRssItemView(long id, long rssItemId) { + this.id = id; + this.rssItemId = rssItemId; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public long getRssItemId() { + return rssItemId; + } + + public void setRssItemId(long rssItemId) { + this.rssItemId = rssItemId; + } + + // KEEP METHODS - put your custom methods here + // KEEP METHODS END + +} diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/CurrentRssItemViewDao.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/CurrentRssItemViewDao.java new file mode 100644 index 00000000..dc2a8680 --- /dev/null +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/CurrentRssItemViewDao.java @@ -0,0 +1,105 @@ +package de.luhmer.owncloudnewsreader.database.model; + +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.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. +/** + * DAO for table CURRENT_RSS_ITEM_VIEW. +*/ +public class CurrentRssItemViewDao extends AbstractDao<CurrentRssItemView, Long> { + + public static final String TABLENAME = "CURRENT_RSS_ITEM_VIEW"; + + /** + * Properties of entity CurrentRssItemView.<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 RssItemId = new Property(1, long.class, "rssItemId", false, "RSS_ITEM_ID"); + }; + + + public CurrentRssItemViewDao(DaoConfig config) { + super(config); + } + + public CurrentRssItemViewDao(DaoConfig config, DaoSession daoSession) { + super(config, 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 + "'CURRENT_RSS_ITEM_VIEW' (" + // + "'_id' INTEGER PRIMARY KEY NOT NULL ," + // 0: id + "'RSS_ITEM_ID' INTEGER NOT NULL );"); // 1: rssItemId + } + + /** Drops the underlying database table. */ + public static void dropTable(SQLiteDatabase db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "'CURRENT_RSS_ITEM_VIEW'"; + db.execSQL(sql); + } + + /** @inheritdoc */ + @Override + protected void bindValues(SQLiteStatement stmt, CurrentRssItemView entity) { + stmt.clearBindings(); + stmt.bindLong(1, entity.getId()); + stmt.bindLong(2, entity.getRssItemId()); + } + + /** @inheritdoc */ + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.getLong(offset + 0); + } + + /** @inheritdoc */ + @Override + public CurrentRssItemView readEntity(Cursor cursor, int offset) { + CurrentRssItemView entity = new CurrentRssItemView( // + cursor.getLong(offset + 0), // id + cursor.getLong(offset + 1) // rssItemId + ); + return entity; + } + + /** @inheritdoc */ + @Override + public void readEntity(Cursor cursor, CurrentRssItemView entity, int offset) { + entity.setId(cursor.getLong(offset + 0)); + entity.setRssItemId(cursor.getLong(offset + 1)); + } + + /** @inheritdoc */ + @Override + protected Long updateKeyAfterInsert(CurrentRssItemView entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + /** @inheritdoc */ + @Override + public Long getKey(CurrentRssItemView entity) { + if(entity != null) { + return entity.getId(); + } else { + return null; + } + } + + /** @inheritdoc */ + @Override + protected boolean isEntityUpdateable() { + return true; + } + +} diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/DaoMaster.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/DaoMaster.java new file mode 100644 index 00000000..af494042 --- /dev/null +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/DaoMaster.java @@ -0,0 +1,78 @@ +package de.luhmer.owncloudnewsreader.database.model; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteDatabase.CursorFactory; +import android.database.sqlite.SQLiteOpenHelper; +import android.util.Log; + +import de.greenrobot.dao.AbstractDaoMaster; +import de.greenrobot.dao.identityscope.IdentityScopeType; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. +/** + * Master of DAO (schema version 3): knows all DAOs. +*/ +public class DaoMaster extends AbstractDaoMaster { + public static final int SCHEMA_VERSION = 3; + + /** Creates underlying database table using DAOs. */ + public static void createAllTables(SQLiteDatabase db, boolean ifNotExists) { + FolderDao.createTable(db, ifNotExists); + FeedDao.createTable(db, ifNotExists); + RssItemDao.createTable(db, ifNotExists); + CurrentRssItemViewDao.createTable(db, ifNotExists); + } + + /** Drops underlying database table using DAOs. */ + public static void dropAllTables(SQLiteDatabase db, boolean ifExists) { + FolderDao.dropTable(db, ifExists); + FeedDao.dropTable(db, ifExists); + RssItemDao.dropTable(db, ifExists); + CurrentRssItemViewDao.dropTable(db, ifExists); + } + + public static abstract class OpenHelper extends SQLiteOpenHelper { + + public OpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory, SCHEMA_VERSION); + } + + @Override + public void onCreate(SQLiteDatabase db) { + Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); + createAllTables(db, false); + } + } + + /** WARNING: Drops all table on Upgrade! Use only during development. */ + public static class DevOpenHelper extends OpenHelper { + public DevOpenHelper(Context context, String name, CursorFactory factory) { + super(context, name, factory); + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } + } + + public DaoMaster(SQLiteDatabase db) { + super(db, SCHEMA_VERSION); + registerDaoClass(FolderDao.class); + registerDaoClass(FeedDao.class); + registerDaoClass(RssItemDao.class); + registerDaoClass(CurrentRssItemViewDao.class); + } + + public DaoSession newSession() { + return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); + } + + public DaoSession newSession(IdentityScopeType type) { + return new DaoSession(db, type, daoConfigMap); + } + +} diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/DaoSession.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/DaoSession.java new file mode 100644 index 00000000..12933605 --- /dev/null +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/DaoSession.java @@ -0,0 +1,81 @@ +package de.luhmer.owncloudnewsreader.database.model; + +import android.database.sqlite.SQLiteDatabase; + +import java.util.Map; + +import de.greenrobot.dao.AbstractDao; +import de.greenrobot.dao.AbstractDaoSession; +import de.greenrobot.dao.identityscope.IdentityScopeType; +import de.greenrobot.dao.internal.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + +/** + * {@inheritDoc} + * + * @see de.greenrobot.dao.AbstractDaoSession + */ +public class DaoSession extends AbstractDaoSession { + + private final DaoConfig folderDaoConfig; + private final DaoConfig feedDaoConfig; + private final DaoConfig rssItemDaoConfig; + private final DaoConfig currentRssItemViewDaoConfig; + + private final FolderDao folderDao; + private final FeedDao feedDao; + private final RssItemDao rssItemDao; + private final CurrentRssItemViewDao currentRssItemViewDao; + + public DaoSession(SQLiteDatabase db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>, DaoConfig> + daoConfigMap) { + super(db); + + folderDaoConfig = daoConfigMap.get(FolderDao.class).clone(); + folderDaoConfig.initIdentityScope(type); + + feedDaoConfig = daoConfigMap.get(FeedDao.class).clone(); + feedDaoConfig.initIdentityScope(type); + + rssItemDaoConfig = daoConfigMap.get(RssItemDao.class).clone(); + rssItemDaoConfig.initIdentityScope(type); + + currentRssItemViewDaoConfig = daoConfigMap.get(CurrentRssItemViewDao.class).clone(); + currentRssItemViewDaoConfig.initIdentityScope(type); + + folderDao = new FolderDao(folderDaoConfig, this); + feedDao = new FeedDao(feedDaoConfig, this); + rssItemDao = new RssItemDao(rssItemDaoConfig, this); + currentRssItemViewDao = new CurrentRssItemViewDao(currentRssItemViewDaoConfig, this); + + registerDao(Folder.class, folderDao); + registerDao(Feed.class, feedDao); + registerDao(RssItem.class, rssItemDao); + registerDao(CurrentRssItemView.class, currentRssItemViewDao); + } + + public void clear() { + folderDaoConfig.getIdentityScope().clear(); + feedDaoConfig.getIdentityScope().clear(); + rssItemDaoConfig.getIdentityScope().clear(); + currentRssItemViewDaoConfig.getIdentityScope().clear(); + } + + public FolderDao getFolderDao() { + return folderDao; + } + + public FeedDao getFeedDao() { + return feedDao; + } + + public RssItemDao getRssItemDao() { + return rssItemDao; + } + + public CurrentRssItemViewDao getCurrentRssItemViewDao() { + return currentRssItemViewDao; + } + +} diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/Feed.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/Feed.java new file mode 100644 index 00000000..ac60553e --- /dev/null +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/Feed.java @@ -0,0 +1,184 @@ +package de.luhmer.owncloudnewsreader.database.model; + +import java.util.List; + +import de.greenrobot.dao.DaoException; + +// THIS CODE IS GENERATED BY greenDAO, EDIT ONLY INSIDE THE "KEEP"-SECTIONS + +// KEEP INCLUDES - put your custom includes here +// KEEP INCLUDES END +/** + * Entity mapped to table FEED. + */ +public class Feed { + + private long id; + private Long folderId; + /** Not-null value. */ + private String feedTitle; + private String faviconUrl; + private String link; + private String avgColour; + + /** Used to resolve relations */ + private transient DaoSession daoSession; + + /** Used for active entity operations. */ + private transient FeedDao myDao; + + private Folder folder; + private Long folder__resolvedKey; + + private List<RssItem> rssItemList; + + // KEEP FIELDS - put your custom fields here + // KEEP FIELDS END + + public Feed() { + } + + public Feed(long id) { + this.id = id; + } + + public Feed(long id, Long folderId, String feedTitle, String faviconUrl, String link, String avgColour) { + this.id = id; + this.folderId = folderId; + this.feedTitle = feedTitle; + this.faviconUrl = faviconUrl; + this.link = link; + this.avgColour = avgColour; + } + + /** called by internal mechanisms, do not call yourself. */ + public void __setDaoSession(DaoSession daoSession) { + this.daoSession = daoSession; + myDao = daoSession != null ? daoSession.getFeedDao() : null; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public Long getFolderId() { + return folderId; + } + + public void setFolderId(Long folderId) { + this.folderId = folderId; + } + + /** Not-null value. */ + public String getFeedTitle() { + return feedTitle; + } + + /** Not-null value; ensure this value is available before it is saved to the database. */ + public void setFeedTitle(String feedTitle) { + this.feedTitle = feedTitle; + } + + public String getFaviconUrl() { + return faviconUrl; + } + + public void setFaviconUrl(String faviconUrl) { + this.faviconUrl = faviconUrl; + } + + public String getLink() { + return link; + } + + public void setLink(String link) { + this.link = link; + } + + public String getAvgColour() { + return avgColour; + } + + public void setAvgColour(String avgColour) { + this.avgColour = avgColour; + } + + /** To-one relationship, resolved on first access. */ + public Folder getFolder() { + Long __key = this.folderId; + if (folder__resolvedKey == null || !folder__resolvedKey.equals(__key)) { + if (daoSession == null) { + throw new DaoException("Entity is detached from DAO context"); + } + FolderDao targetDao = daoSession.getFolderDao(); + Folder folderNew = targetDao.load(__key); + synchronized (this) { + folder = folderNew; + folder__resolvedKey = __key; + } + } + return folder; + } + + public void setFolder(Folder folder) { + synchronized (this) { + this.folder = folder; + folderId = folder == null ? null : folder.getId(); + folder__resolvedKey = folderId; + } + } + + /** To-many relationship, resolved on first access (and after reset). Changes to to-many relations are not persisted, make changes to the target entity. */ + public List<RssItem> getRssItemList() { + if (rssItemList == null) { + if (daoSession == null) { + throw new DaoException("Entity is detached from DAO context"); + } + RssItemDao targetDao = daoSession.getRssItemDao(); + List<RssItem> rssItemListNew = targetDao._queryFeed_RssItemList(id); + synchronized (this) { + if(rssItemList == null) { + rssItemList = rssItemListNew; + } + } + } + return rssItemList; + } + + /** Resets a to-many relationship, making the next get call to query for a fresh result. */ + public synchronized void resetRssItemList() { + rssItemList = null; + } + + /** Convenient call for {@link AbstractDao#delete(Object)}. Entity must attached to an entity context. */ + public void delete() { + if (myDao == null) { + throw new DaoException("Entity is detached from DAO context"); + } + myDao.delete(this); + } + + /** Convenient call for {@link AbstractDao#update(Object)}. Entity must attached to an entity context. */ + public void update() { + if (myDao == null) { + throw new DaoException("Entity is detached from DAO context"); + } + myDao.update(this); + } + + /** Convenient call for {@link AbstractDao#refresh(Object)}. Entity must attached to an entity context. */ + public void refresh() { + if (myDao == null) { + throw new DaoException("Entity is detached from DAO context"); + } + myDao.refresh(this); + } + + // KEEP METHODS - put your custom methods here + // KEEP METHODS END + +} diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/FeedDao.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/FeedDao.java new file mode 100644 index 00000000..5b011d19 --- /dev/null +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/FeedDao.java @@ -0,0 +1,262 @@ +package de.luhmer.owncloudnewsreader.database.model; + +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteStatement; + +import java.util.ArrayList; +import java.util.List; + +import de.greenrobot.dao.AbstractDao; +import de.greenrobot.dao.Property; +import de.greenrobot.dao.internal.DaoConfig; +import de.greenrobot.dao.internal.SqlUtils; +import de.greenrobot.dao.query.Query; +import de.greenrobot.dao.query.QueryBuilder; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. +/** + * DAO for table FEED. +*/ +public class FeedDao extends AbstractDao<Feed, Long> { + + public static final String TABLENAME = "FEED"; + + /** + * Properties of entity Feed.<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 FolderId = new Property(1, Long.class, "folderId", false, "FOLDER_ID"); + public final static Property FeedTitle = new Property(2, String.class, "feedTitle", false, "FEED_TITLE"); + public final static Property FaviconUrl = new Property(3, String.class, "faviconUrl", false, "FAVICON_URL"); + public final static Property Link = new Property(4, String.class, "link", false, "LINK"); + public final static Property AvgColour = new Property(5, String.class, "avgColour", false, "AVG_COLOUR"); + }; + + private DaoSession daoSession; + + private Query<Feed> folder_FeedListQuery; + + public FeedDao(DaoConfig config) { + super(config); + } + + public FeedDao(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 + "'FEED' (" + // + "'_id' INTEGER PRIMARY KEY NOT NULL ," + // 0: id + "'FOLDER_ID' INTEGER," + // 1: folderId + "'FEED_TITLE' TEXT NOT NULL ," + // 2: feedTitle + "'FAVICON_URL' TEXT," + // 3: faviconUrl + "'LINK' TEXT," + // 4: link + "'AVG_COLOUR' TEXT);"); // 5: avgColour + } + + /** Drops the underlying database table. */ + public static void dropTable(SQLiteDatabase db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "'FEED'"; + db.execSQL(sql); + } + + /** @inheritdoc */ + @Override + protected void bindValues(SQLiteStatement stmt, Feed entity) { + stmt.clearBindings(); + stmt.bindLong(1, entity.getId()); + + Long folderId = entity.getFolderId(); + if (folderId != null) { + stmt.bindLong(2, folderId); + } + stmt.bindString(3, entity.getFeedTitle()); + + String faviconUrl = entity.getFaviconUrl(); + if (faviconUrl != null) { + stmt.bindString(4, faviconUrl); + } + + String link = entity.getLink(); + if (link != null) { + stmt.bindString(5, link); + } + + String avgColour = entity.getAvgColour(); + if (avgColour != null) { + stmt.bindString(6, avgColour); + } + } + + @Override + protected void attachEntity(Feed entity) { + super.attachEntity(entity); + entity.__setDaoSession(daoSession); + } + + /** @inheritdoc */ + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.getLong(offset + 0); + } + + /** @inheritdoc */ + @Override + public Feed readEntity(Cursor cursor, int offset) { + Feed entity = new Feed( // + cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1), // folderId + cursor.getString(offset + 2), // feedTitle + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // faviconUrl + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // link + cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5) // avgColour + ); + return entity; + } + + /** @inheritdoc */ + @Override + public void readEntity(Cursor cursor, Feed entity, int offset) { + entity.setId(cursor.getLong(offset + 0)); + entity.setFolderId(cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1)); + entity.setFeedTitle(cursor.getString(offset + 2)); + entity.setFaviconUrl(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setLink(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setAvgColour(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); + } + + /** @inheritdoc */ + @Override + protected Long updateKeyAfterInsert(Feed entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + /** @inheritdoc */ + @Override + public Long getKey(Feed entity) { + if(entity != null) { + return entity.getId(); + } else { + return null; + } + } + + /** @inheritdoc */ + @Override + protected boolean isEntityUpdateable() { + return true; + } + + /** Internal query to resolve the "feedList" to-many relationship of Folder. */ + public List<Feed> _queryFolder_FeedList(Long folderId) { + synchronized (this) { + if (folder_FeedListQuery == null) { + QueryBuilder<Feed> queryBuilder = queryBuilder(); + queryBuilder.where(Properties.FolderId.eq(null)); + folder_FeedListQuery = queryBuilder.build(); + } + } + Query<Feed> query = folder_FeedListQuery.forCurrentThread(); + query.setParameter(0, folderId); + 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.getFolderDao().getAllColumns()); + builder.append(" FROM FEED T"); + builder.append(" LEFT JOIN FOLDER T0 ON T.'FOLDER_ID'=T0.'_id'"); + builder.append(' '); + selectDeep = builder.toString(); + } + return selectDeep; + } + + protected Feed loadCurrentDeep(Cursor cursor, boolean lock) { + Feed entity = loadCurrent(cursor, 0, lock); + int offset = getAllColumns().length; + + Folder folder = loadCurrentOther(daoSession.getFolderDao(), cursor, offset); + entity.setFolder(folder); + + return entity; + } + + public Feed 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<Feed> loadAllDeepFromCursor(Cursor cursor) { + int count = cursor.getCount(); + List<Feed> list = new ArrayList<Feed>(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<Feed> 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<Feed> queryDeep(String where, String... selectionArg) { + Cursor cursor = db.rawQuery(getSelectDeep() + where, selectionArg); + return loadDeepAllAndCloseCursor(cursor); + } + +} diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/Folder.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/Folder.java new file mode 100644 index 00000000..ea5cf36d --- /dev/null +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/Folder.java @@ -0,0 +1,116 @@ +package de.luhmer.owncloudnewsreader.database.model; + +import java.util.List; + +import de.greenrobot.dao.DaoException; + +// THIS CODE IS GENERATED BY greenDAO, EDIT ONLY INSIDE THE "KEEP"-SECTIONS + +// KEEP INCLUDES - put your custom includes here +// KEEP INCLUDES END +/** + * Entity mapped to table FOLDER. + */ +public class Folder { + + private long id; + /** Not-null value. */ + private String label; + + /** Used to resolve relations */ + private transient DaoSession daoSession; + + /** Used for active entity operations. */ + private transient FolderDao myDao; + + private List<Feed> feedList; + + // KEEP FIELDS - put your custom fields here + // KEEP FIELDS END + + public Folder() { + } + + public Folder(long id) { + this.id = id; + } + + public Folder(long id, String label) { + this.id = id; + this.label = label; + } + + /** called by internal mechanisms, do not call yourself. */ + public void __setDaoSession(DaoSession daoSession) { + this.daoSession = daoSession; + myDao = daoSession != null ? daoSession.getFolderDao() : null; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + /** Not-null value. */ + public String getLabel() { + return label; + } + + /** Not-null value; ensure this value is available before it is saved to the database. */ + public void setLabel(String label) { + this.label = label; + } + + /** To-many relationship, resolved on first access (and after reset). Changes to to-many relations are not persisted, make changes to the target entity. */ + public List<Feed> getFeedList() { + if (feedList == null) { + if (daoSession == null) { + throw new DaoException("Entity is detached from DAO context"); + } + FeedDao targetDao = daoSession.getFeedDao(); + List<Feed> feedListNew = targetDao._queryFolder_FeedList(id); + synchronized (this) { + if(feedList == null) { + feedList = feedListNew; + } + } + } + return feedList; + } + + /** Resets a to-many relationship, making the next get call to query for a fresh result. */ + public synchronized void resetFeedList() { + feedList = null; + } + + /** Convenient call for {@link AbstractDao#delete(Object)}. Entity must attached to an entity context. */ + public void delete() { + if (myDao == null) { + throw new DaoException("Entity is detached from DAO context"); + } + myDao.delete(this); + } + + /** Convenient call for {@link AbstractDao#update(Object)}. Entity must attached to an entity context. */ + public void update() { + if (myDao == null) { + throw new DaoException("Entity is detached from DAO context"); + } + myDao.update(this); + } + + /** Convenient call for {@link AbstractDao#refresh(Object)}. Entity must attached to an entity context. */ + public void refresh() { + if (myDao == null) { + throw new DaoException("Entity is detached from DAO context"); + } + myDao.refresh(this); + } + + // KEEP METHODS - put your custom methods here + // KEEP METHODS END + +} diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/FolderDao.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/FolderDao.java new file mode 100644 index 00000000..f94c8ce0 --- /dev/null +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/FolderDao.java @@ -0,0 +1,114 @@ +package de.luhmer.owncloudnewsreader.database.model; + +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.DaoConfig; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. +/** + * DAO for table FOLDER. +*/ +public class FolderDao extends AbstractDao<Folder, Long> { + + public static final String TABLENAME = "FOLDER"; + + /** + * Properties of entity Folder.<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 Label = new Property(1, String.class, "label", false, "LABEL"); + }; + + private DaoSession daoSession; + + + public FolderDao(DaoConfig config) { + super(config); + } + + public FolderDao(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 + "'FOLDER' (" + // + "'_id' INTEGER PRIMARY KEY NOT NULL ," + // 0: id + "'LABEL' TEXT NOT NULL );"); // 1: label + } + + /** Drops the underlying database table. */ + public static void dropTable(SQLiteDatabase db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "'FOLDER'"; + db.execSQL(sql); + } + + /** @inheritdoc */ + @Override + protected void bindValues(SQLiteStatement stmt, Folder entity) { + stmt.clearBindings(); + stmt.bindLong(1, entity.getId()); + stmt.bindString(2, entity.getLabel()); + } + + @Override + protected void attachEntity(Folder entity) { + super.attachEntity(entity); + entity.__setDaoSession(daoSession); + } + + /** @inheritdoc */ + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.getLong(offset + 0); + } + + /** @inheritdoc */ + @Override + public Folder readEntity(Cursor cursor, int offset) { + Folder entity = new Folder( // + cursor.getLong(offset + 0), // id + cursor.getString(offset + 1) // label + ); + return entity; + } + + /** @inheritdoc */ + @Override + public void readEntity(Cursor cursor, Folder entity, int offset) { + entity.setId(cursor.getLong(offset + 0)); + entity.setLabel(cursor.getString(offset + 1)); + } + + /** @inheritdoc */ + @Override + protected Long updateKeyAfterInsert(Folder entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + /** @inheritdoc */ + @Override + public Long getKey(Folder entity) { + if(entity != null) { + return entity.getId(); + } else { + return null; + } + } + + /** @inheritdoc */ + @Override + protected boolean isEntityUpdateable() { + return true; + } + +} diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/RssItem.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/RssItem.java new file mode 100644 index 00000000..9bfb859b --- /dev/null +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/RssItem.java @@ -0,0 +1,269 @@ +package de.luhmer.owncloudnewsreader.database.model; + +import de.greenrobot.dao.DaoException; +import de.luhmer.owncloudnewsreader.adapter.HasId; + +// THIS CODE IS GENERATED BY greenDAO, EDIT ONLY INSIDE THE "KEEP"-SECTIONS + +// KEEP INCLUDES - put your custom includes here +// KEEP INCLUDES END +/** + * Entity mapped to table RSS_ITEM. + */ +public class RssItem implements HasId<Long> { + + private long id; + private long feedId; + private String link; + private String title; + private String body; + private Boolean read; + private Boolean starred; + /** Not-null value. */ + private String author; + /** Not-null value. */ + private String guid; + /** Not-null value. */ + private String guidHash; + private Boolean read_temp; + private Boolean starred_temp; + private java.util.Date lastModified; + private java.util.Date pubDate; + private String enclosureLink; + private String enclosureMime; + + /** Used to resolve relations */ + private transient DaoSession daoSession; + + /** Used for active entity operations. */ + private transient RssItemDao myDao; + + private Feed feed; + private Long feed__resolvedKey; + + + // KEEP FIELDS - put your custom fields here + // KEEP FIELDS END + + public RssItem() { + } + + public RssItem(long id) { + this.id = id; + } + + public RssItem(long id, long feedId, String link, String title, String body, Boolean read, Boolean starred, String author, String guid, String guidHash, Boolean read_temp, Boolean starred_temp, java.util.Date lastModified, java.util.Date pubDate, String enclosureLink, String enclosureMime) { + this.id = id; + this.feedId = feedId; + this.link = link; + this.title = title; + this.body = body; + this.read = read; + this.starred = starred; + this.author = author; + this.guid = guid; + this.guidHash = guidHash; + this.read_temp = read_temp; + this.starred_temp = starred_temp; + this.lastModified = lastModified; + this.pubDate = pubDate; + this.enclosureLink = enclosureLink; + this.enclosureMime = enclosureMime; + } + + /** called by internal mechanisms, do not call yourself. */ + public void __setDaoSession(DaoSession daoSession) { + this.daoSession = daoSession; + myDao = daoSession != null ? daoSession.getRssItemDao() : null; + } + + public Long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public long getFeedId() { + return feedId; + } + + public void setFeedId(long feedId) { + this.feedId = feedId; + } + + public String getLink() { + return link; + } + + public void setLink(String link) { + this.link = link; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getBody() { + return body; + } + + public void setBody(String body) { + this.body = body; + } + + public Boolean getRead() { + return read; + } + + public void setRead(Boolean read) { + this.read = read; + } + + public Boolean getStarred() { + return starred; + } + + public void setStarred(Boolean starred) { + this.starred = starred; + } + + /** Not-null value. */ + public String getAuthor() { + return author; + } + + /** Not-null value; ensure this value is available before it is saved to the database. */ + public void setAuthor(String author) { + this.author = author; + } + + /** Not-null value. */ + public String getGuid() { + return guid; + } + + /** Not-null value; ensure this value is available before it is saved to the database. */ + public void setGuid(String guid) { + this.guid = guid; + } + + /** Not-null value. */ + public String getGuidHash() { + return guidHash; + } + + /** Not-null value; ensure this value is available before it is saved to the database. */ + public void setGuidHash(String guidHash) { + this.guidHash = guidHash; + } + + public Boolean getRead_temp() { + return read_temp; + } + + public void setRead_temp(Boolean read_temp) { + this.read_temp = read_temp; + } + + public Boolean getStarred_temp() { + return starred_temp; + } + + public void setStarred_temp(Boolean starred_temp) { + this.starred_temp = starred_temp; + } + + public java.util.Date getLastModified() { + return lastModified; + } + + public void setLastModified(java.util.Date lastModified) { + this.lastModified = lastModified; + } + + public java.util.Date getPubDate() { + return pubDate; + } + + public void setPubDate(java.util.Date pubDate) { + this.pubDate = pubDate; + } + + public String getEnclosureLink() { + return enclosureLink; + } + + public void setEnclosureLink(String enclosureLink) { + this.enclosureLink = enclosureLink; + } + + public String getEnclosureMime() { + return enclosureMime; + } + + public void setEnclosureMime(String enclosureMime) { + this.enclosureMime = enclosureMime; + } + + /** To-one relationship, resolved on first access. */ + public Feed getFeed() { + long __key = this.feedId; + if (feed__resolvedKey == null || !feed__resolvedKey.equals(__key)) { + if (daoSession == null) { + throw new DaoException("Entity is detached from DAO context"); + } + FeedDao targetDao = daoSession.getFeedDao(); + Feed feedNew = targetDao.load(__key); + synchronized (this) { + feed = feedNew; + feed__resolvedKey = __key; + } + } + return feed; + } + + public void setFeed(Feed feed) { + if (feed == null) { + throw new DaoException("To-one property 'feedId' has not-null constraint; cannot set to-one to null"); + } + synchronized (this) { + this.feed = feed; + feedId = feed.getId(); + feed__resolvedKey = feedId; + } + } + + /** Convenient call for {@link AbstractDao#delete(Object)}. Entity must attached to an entity context. */ + public void delete() { + if (myDao == null) { + throw new DaoException("Entity is detached from DAO context"); + } + myDao.delete(this); + } + + /** Convenient call for {@link AbstractDao#update(Object)}. Entity must attached to an entity context. */ + public void update() { + if (myDao == null) { + throw new DaoException("Entity is detached from DAO context"); + } + myDao.update(this); + } + + /** Convenient call for {@link AbstractDao#refresh(Object)}. Entity must attached to an entity context. */ + public void refresh() { + if (myDao == null) { + throw new DaoException("Entity is detached from DAO context"); + } + myDao.refresh(this); + } + + // KEEP METHODS - put your custom methods here + // KEEP METHODS END + +} diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/RssItemDao.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/RssItemDao.java new file mode 100644 index 00000000..4739d5f9 --- /dev/null +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/RssItemDao.java @@ -0,0 +1,342 @@ +package de.luhmer.owncloudnewsreader.database.model; + +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteStatement; + +import java.util.ArrayList; +import java.util.List; + +import de.greenrobot.dao.AbstractDao; +import de.greenrobot.dao.Property; +import de.greenrobot.dao.internal.DaoConfig; +import de.greenrobot.dao.internal.SqlUtils; +import de.greenrobot.dao.query.Query; +import de.greenrobot.dao.query.QueryBuilder; + +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. +/** + * DAO for table RSS_ITEM. +*/ +public class RssItemDao extends AbstractDao<RssItem, Long> { + + public static final String TABLENAME = "RSS_ITEM"; + + /** + * Properties of entity RssItem.<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 FeedId = new Property(1, long.class, "feedId", false, "FEED_ID"); + public final static Property Link = new Property(2, String.class, "link", false, "LINK"); + public final static Property Title = new Property(3, String.class, "title", false, "TITLE"); + public final static Property Body = new Property(4, String.class, "body", false, "BODY"); + public final static Property Read = new Property(5, Boolean.class, "read", false, "READ"); + public final static Property Starred = new Property(6, Boolean.class, "starred", false, "STARRED"); + public final static Property Author = new Property(7, String.class, "author", false, "AUTHOR"); + public final static Property Guid = new Property(8, String.class, "guid", false, "GUID"); + public final static Property GuidHash = new Property(9, String.class, "guidHash", false, "GUID_HASH"); + public final static Property Read_temp = new Property(10, Boolean.class, "read_temp", false, "READ_TEMP"); + public final static Property Starred_temp = new Property(11, Boolean.class, "starred_temp", false, "STARRED_TEMP"); + public final static Property LastModified = new Property(12, java.util.Date.class, "lastModified", false, "LAST_MODIFIED"); + public final static Property PubDate = new Property(13, java.util.Date.class, "pubDate", false, "PUB_DATE"); + public final static Property EnclosureLink = new Property(14, String.class, "enclosureLink", false, "ENCLOSURE_LINK"); + public final static Property EnclosureMime = new Property(15, String.class, "enclosureMime", false, "ENCLOSURE_MIME"); + }; + + private DaoSession daoSession; + + private Query<RssItem> feed_RssItemListQuery; + + public RssItemDao(DaoConfig config) { + super(config); + } + + public RssItemDao(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 + "'RSS_ITEM' (" + // + "'_id' INTEGER PRIMARY KEY NOT NULL ," + // 0: id + "'FEED_ID' INTEGER NOT NULL ," + // 1: feedId + "'LINK' TEXT," + // 2: link + "'TITLE' TEXT," + // 3: title + "'BODY' TEXT," + // 4: body + "'READ' INTEGER," + // 5: read + "'STARRED' INTEGER," + // 6: starred + "'AUTHOR' TEXT NOT NULL ," + // 7: author + "'GUID' TEXT NOT NULL ," + // 8: guid + "'GUID_HASH' TEXT NOT NULL ," + // 9: guidHash + "'READ_TEMP' INTEGER," + // 10: read_temp + "'STARRED_TEMP' INTEGER," + // 11: starred_temp + "'LAST_MODIFIED' INTEGER," + // 12: lastModified + "'PUB_DATE' INTEGER," + // 13: pubDate + "'ENCLOSURE_LINK' TEXT," + // 14: enclosureLink + "'ENCLOSURE_MIME' TEXT);"); // 15: enclosureMime + } + + /** Drops the underlying database table. */ + public static void dropTable(SQLiteDatabase db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "'RSS_ITEM'"; + db.execSQL(sql); + } + + /** @inheritdoc */ + @Override + protected void bindValues(SQLiteStatement stmt, RssItem entity) { + stmt.clearBindings(); + stmt.bindLong(1, entity.getId()); + stmt.bindLong(2, entity.getFeedId()); + + String link = entity.getLink(); + if (link != null) { + stmt.bindString(3, link); + } + + String title = entity.getTitle(); + if (title != null) { + stmt.bindString(4, title); + } + + String body = entity.getBody(); + if (body != null) { + stmt.bindString(5, body); + } + + Boolean read = entity.getRead(); + if (read != null) { + stmt.bindLong(6, read ? 1l: 0l); + } + + Boolean starred = entity.getStarred(); + if (starred != null) { + stmt.bindLong(7, starred ? 1l: 0l); + } + stmt.bindString(8, entity.getAuthor()); + stmt.bindString(9, entity.getGuid()); + stmt.bindString(10, entity.getGuidHash()); + + Boolean read_temp = entity.getRead_temp(); + if (read_temp != null) { + stmt.bindLong(11, read_temp ? 1l: 0l); + } + + Boolean starred_temp = entity.getStarred_temp(); + if (starred_temp != null) { + stmt.bindLong(12, starred_temp ? 1l: 0l); + } + + java.util.Date lastModified = entity.getLastModified(); + if (lastModified != null) { + stmt.bindLong(13, lastModified.getTime()); + } + + java.util.Date pubDate = entity.getPubDate(); + if (pubDate != null) { + stmt.bindLong(14, pubDate.getTime()); + } + + String enclosureLink = entity.getEnclosureLink(); + if (enclosureLink != null) { + stmt.bindString(15, enclosureLink); + } + + String enclosureMime = entity.getEnclosureMime(); + if (enclosureMime != null) { + stmt.bindString(16, enclosureMime); + } + } + + @Override + protected void attachEntity(RssItem entity) { + super.attachEntity(entity); + entity.__setDaoSession(daoSession); + } + + /** @inheritdoc */ + @Override + public Long readKey(Cursor cursor, int offset) { + return cursor.getLong(offset + 0); + } + + /** @inheritdoc */ + @Override + public RssItem readEntity(Cursor cursor, int offset) { + RssItem entity = new RssItem( // + cursor.getLong(offset + 0), // id + cursor.getLong(offset + 1), // feedId + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // link + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // title + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // body + cursor.isNull(offset + 5) ? null : cursor.getShort(offset + 5) != 0, // read + cursor.isNull(offset + 6) ? null : cursor.getShort(offset + 6) != 0, // starred + cursor.getString(offset + 7), // author + cursor.getString(offset + 8), // guid + cursor.getString(offset + 9), // guidHash + cursor.isNull(offset + 10) ? null : cursor.getShort(offset + 10) != 0, // read_temp + cursor.isNull(offset + 11) ? null : cursor.getShort(offset + 11) != 0, // starred_temp + cursor.isNull(offset + 12) ? null : new java.util.Date(cursor.getLong(offset + 12)), // lastModified + cursor.isNull(offset + 13) ? null : new java.util.Date(cursor.getLong(offset + 13)), // pubDate + cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14), // enclosureLink + cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15) // enclosureMime + ); + return entity; + } + + /** @inheritdoc */ + @Override + public void readEntity(Cursor cursor, RssItem entity, int offset) { + entity.setId(cursor.getLong(offset + 0)); + entity.setFeedId(cursor.getLong(offset + 1)); + entity.setLink(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); + entity.setTitle(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); + entity.setBody(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); + entity.setRead(cursor.isNull(offset + 5) ? null : cursor.getShort(offset + 5) != 0); + entity.setStarred(cursor.isNull(offset + 6) ? null : cursor.getShort(offset + 6) != 0); + entity.setAuthor(cursor.getString(offset + 7)); + entity.setGuid(cursor.getString(offset + 8)); + entity.setGuidHash(cursor.getString(offset + 9)); + entity.setRead_temp(cursor.isNull(offset + 10) ? null : cursor.getShort(offset + 10) != 0); + entity.setStarred_temp(cursor.isNull(offset + 11) ? null : cursor.getShort(offset + 11) != 0); + entity.setLastModified(cursor.isNull(offset + 12) ? null : new java.util.Date(cursor.getLong(offset + 12))); + entity.setPubDate(cursor.isNull(offset + 13) ? null : new java.util.Date(cursor.getLong(offset + 13))); + entity.setEnclosureLink(cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14)); + entity.setEnclosureMime(cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15)); + } + + /** @inheritdoc */ + @Override + protected Long updateKeyAfterInsert(RssItem entity, long rowId) { + entity.setId(rowId); + return rowId; + } + + /** @inheritdoc */ + @Override + public Long getKey(RssItem entity) { + if(entity != null) { + return entity.getId(); + } else { + return null; + } + } + + /** @inheritdoc */ + @Override + protected boolean isEntityUpdateable() { + return true; + } + + /** Internal query to resolve the "rssItemList" to-many relationship of Feed. */ + public List<RssItem> _queryFeed_RssItemList(long feedId) { + synchronized (this) { + if (feed_RssItemListQuery == null) { + QueryBuilder<RssItem> queryBuilder = queryBuilder(); + queryBuilder.where(Properties.FeedId.eq(null)); + feed_RssItemListQuery = queryBuilder.build(); + } + } + Query<RssItem> query = feed_RssItemListQuery.forCurrentThread(); + query.setParameter(0, feedId); + 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.getFeedDao().getAllColumns()); + builder.append(" FROM RSS_ITEM T"); + builder.append(" LEFT JOIN FEED T0 ON T.'FEED_ID'=T0.'_id'"); + builder.append(' '); + selectDeep = builder.toString(); + } + return selectDeep; + } + + protected RssItem loadCurrentDeep(Cursor cursor, boolean lock) { + RssItem entity = loadCurrent(cursor, 0, lock); + int offset = getAllColumns().length; + + Feed feed = loadCurrentOther(daoSession.getFeedDao(), cursor, offset); + if(feed != null) { + entity.setFeed(feed); + } + + return entity; + } + + public RssItem 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<RssItem> loadAllDeepFromCursor(Cursor cursor) { + int count = cursor.getCount(); + List<RssItem> list = new ArrayList<RssItem>(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<RssItem> 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<RssItem> queryDeep(String where, String... selectionArg) { + Cursor cursor = db.rawQuery(getSelectDeep() + where, selectionArg); + return loadDeepAllAndCloseCursor(cursor); + } + +} |