Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/news-android.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Development <david-dev@live.de>2014-07-28 13:52:21 +0400
committerDavid Development <david-dev@live.de>2014-07-28 13:53:03 +0400
commitd378e2bba063852a463c8a554afe1566043502ac (patch)
tree6b85c4b258ccdd86bfad718101df2bd704532951 /News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database
parentbffef458cb3079ef928486ab7e7b2fb4ef454b15 (diff)
Update Backend to ORM/Remove abs -> appcompat
Diffstat (limited to 'News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database')
-rw-r--r--News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnection.java6
-rw-r--r--News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnectionOrm.java616
-rw-r--r--News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseHelperOrm.java51
-rw-r--r--News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/generator/DatabaseOrmGenerator.java76
-rw-r--r--News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/generator/SchemaVersion.java51
-rw-r--r--News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/generator/Version3.java96
-rw-r--r--News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/CurrentRssItemView.java49
-rw-r--r--News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/CurrentRssItemViewDao.java105
-rw-r--r--News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/DaoMaster.java78
-rw-r--r--News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/DaoSession.java81
-rw-r--r--News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/Feed.java184
-rw-r--r--News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/FeedDao.java262
-rw-r--r--News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/Folder.java116
-rw-r--r--News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/FolderDao.java114
-rw-r--r--News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/RssItem.java269
-rw-r--r--News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model/RssItemDao.java342
16 files changed, 2494 insertions, 2 deletions
diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnection.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnection.java
index a5085f5c..b776e36d 100644
--- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnection.java
+++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnection.java
@@ -145,7 +145,7 @@ public class DatabaseConnection {
return openHelper;
}
- public void clearDatabaseOverSize()
+ public void getAllItemsIdsForFeedSQL()
{
//If i have 9023 rows in the database, when i run that query it should delete 8023 rows and leave me with 1000
//database.execSQL("DELETE FROM " + RSS_ITEM_TABLE + " WHERE " + + "ORDER BY rowid DESC LIMIT 1000 *
@@ -952,11 +952,13 @@ public class DatabaseConnection {
{
cursor.moveToFirst();
do {
+ /*
PodcastFeedItem podcastItem = new PodcastFeedItem();
podcastItem.itemId = cursor.getString(0);
podcastItem.title = cursor.getString(1);
podcastItem.count = cursor.getInt(2);
result.add(podcastItem);
+ */
} while(cursor.moveToNext());
}
}
@@ -1018,7 +1020,7 @@ public class DatabaseConnection {
public static PodcastItem ParsePodcastItemFromCursor(Context context, Cursor cursor) {
PodcastItem podcastItem = new PodcastItem();
- podcastItem.itemId = cursor.getString(0);
+ podcastItem.itemId = cursor.getLong(0);
podcastItem.title = cursor.getString(cursor.getColumnIndex(RSS_ITEM_TITLE)); //cursor.getString(1);
podcastItem.link = cursor.getString(cursor.getColumnIndex(RSS_ITEM_ENC_LINK)); //cursor.getString(2);
podcastItem.mimeType = cursor.getString(cursor.getColumnIndex(RSS_ITEM_ENC_MIME)); //cursor.getString(3);
diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnectionOrm.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnectionOrm.java
new file mode 100644
index 00000000..94cf4d7c
--- /dev/null
+++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnectionOrm.java
@@ -0,0 +1,616 @@
+package de.luhmer.owncloudnewsreader.database;
+
+import android.content.Context;
+import android.database.Cursor;
+import android.util.SparseArray;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import de.greenrobot.dao.query.LazyList;
+import de.greenrobot.dao.query.WhereCondition;
+import de.luhmer.owncloudnewsreader.Constants;
+import de.luhmer.owncloudnewsreader.database.model.CurrentRssItemViewDao;
+import de.luhmer.owncloudnewsreader.database.model.DaoSession;
+import de.luhmer.owncloudnewsreader.database.model.Feed;
+import de.luhmer.owncloudnewsreader.database.model.FeedDao;
+import de.luhmer.owncloudnewsreader.database.model.Folder;
+import de.luhmer.owncloudnewsreader.database.model.FolderDao;
+import de.luhmer.owncloudnewsreader.database.model.RssItem;
+import de.luhmer.owncloudnewsreader.database.model.RssItemDao;
+import de.luhmer.owncloudnewsreader.model.PodcastFeedItem;
+import de.luhmer.owncloudnewsreader.model.PodcastItem;
+import de.luhmer.owncloudnewsreader.services.PodcastDownloadService;
+
+import static de.luhmer.owncloudnewsreader.ListView.SubscriptionExpandableListAdapter.SPECIAL_FOLDERS;
+import static de.luhmer.owncloudnewsreader.ListView.SubscriptionExpandableListAdapter.SPECIAL_FOLDERS.ALL_ITEMS;
+import static de.luhmer.owncloudnewsreader.ListView.SubscriptionExpandableListAdapter.SPECIAL_FOLDERS.ALL_STARRED_ITEMS;
+import static de.luhmer.owncloudnewsreader.ListView.SubscriptionExpandableListAdapter.SPECIAL_FOLDERS.ALL_UNREAD_ITEMS;
+
+/**
+ * Created by David on 15.07.2014.
+ */
+public class DatabaseConnectionOrm {
+
+ private static final List<String> ALLOWED_PODCASTS_TYPES = new ArrayList<String>() {
+ {
+ this.add("audio/mp3");
+ this.add("audio/mpeg");
+ this.add("audio/ogg");
+ this.add("audio/opus");
+ this.add("audio/ogg;codecs=opus");
+ this.add("youtube");
+ }
+ };
+
+
+
+ DaoSession daoSession;
+
+ public void resetDatabase() {
+ daoSession.getRssItemDao().deleteAll();
+ daoSession.getFeedDao().deleteAll();
+ daoSession.getFolderDao().deleteAll();
+ }
+
+ public DatabaseConnectionOrm(Context context) {
+ daoSession = DatabaseHelperOrm.getDaoSession(context);
+ }
+
+ public void insertNewFolder (Folder folder) {
+ daoSession.getFolderDao().insertOrReplace(folder);
+ }
+
+ public void insertNewFeed (Feed feed) {
+ daoSession.getFeedDao().insertOrReplace(feed);
+ }
+
+ public void insertNewItems(RssItem... items) {
+ daoSession.getRssItemDao().insertOrReplaceInTx(items);
+ }
+
+ public List<Folder> getListOfFolders() {
+ return daoSession.getFolderDao().loadAll();
+ }
+
+ public List<Folder> getListOfFoldersWithUnreadItems() {
+ return daoSession.getFolderDao().queryBuilder().where(
+ new WhereCondition.StringCondition(FolderDao.Properties.Id.columnName + " IN "
+ + "(SELECT " + FeedDao.Properties.FolderId.columnName + " FROM " + FeedDao.TABLENAME + " feed "
+ + " JOIN " + RssItemDao.TABLENAME + " rss ON feed." + FeedDao.Properties.Id.columnName + " = rss." + RssItemDao.Properties.FeedId.columnName
+ + " WHERE rss." + RssItemDao.Properties.Read_temp.columnName + " != 1)")
+ ).list();
+ }
+
+ public List<Feed> getListOfFeeds() {
+ return daoSession.getFeedDao().loadAll();
+ }
+
+ public List<Feed> getListOfFeedsWithUnreadItems() {
+ List<Feed> feedsWithUnreadItems = new ArrayList<Feed>();
+
+ for(Feed feed : getListOfFeeds()) {
+ for(RssItem rssItem : feed.getRssItemList()) {
+ if (!rssItem.getRead_temp()) {
+ feedsWithUnreadItems.add(feed);
+ break;
+ }
+ }
+ }
+ return feedsWithUnreadItems;
+ }
+
+ public Folder getFolderById(long folderId) {
+ return daoSession.getFolderDao().queryBuilder().where(FolderDao.Properties.Id.eq(folderId)).unique();
+ }
+
+ public Feed getFeedById(long feedId) {
+ return daoSession.getFeedDao().queryBuilder().where(FeedDao.Properties.Id.eq(feedId)).unique();
+ }
+
+ public List<Feed> getListOfFeedsWithFolders() {
+ return daoSession.getFeedDao().queryBuilder().where(FeedDao.Properties.FolderId.isNotNull()).list();
+ }
+
+ public List<Feed> getListOfFeedsWithoutFolders(boolean onlyWithUnreadRssItems) {
+ if(onlyWithUnreadRssItems) {
+ return daoSession.getFeedDao().queryBuilder().where(FeedDao.Properties.FolderId.eq(0L),
+ new WhereCondition.StringCondition(FeedDao.Properties.Id.columnName + " IN " + "(SELECT " + RssItemDao.Properties.FeedId.columnName + " FROM " + RssItemDao.TABLENAME + " WHERE " + RssItemDao.Properties.Read_temp.columnName + " != 1)")).list();
+ } else {
+ return daoSession.getFeedDao().queryBuilder().where(FeedDao.Properties.FolderId.eq(0L)).list();
+ }
+ }
+
+ public List<Feed> getAllFeedsWithUnreadRssItems() {
+ return daoSession.getFeedDao().queryBuilder().where(
+ new WhereCondition.StringCondition(FeedDao.Properties.Id.columnName + " IN " + "(SELECT " + RssItemDao.Properties.FeedId.columnName + " FROM " + RssItemDao.TABLENAME + " WHERE " + RssItemDao.Properties.Read_temp.columnName + " != 1)")).list();
+ }
+
+ public List<Feed> getAllFeedsWithUnreadRssItemsForFolder(long folderId, boolean onlyUnread) {
+ if(onlyUnread) {
+ String whereConditionString = " IN " + "(SELECT " + RssItemDao.Properties.FeedId.columnName + " FROM " + RssItemDao.TABLENAME + " WHERE " + RssItemDao.Properties.Read_temp.columnName + " != 1)";
+ WhereCondition whereCondition = new WhereCondition.StringCondition(FeedDao.Properties.Id.columnName + whereConditionString);
+ return daoSession.getFeedDao().queryBuilder().where(whereCondition, FeedDao.Properties.FolderId.eq(folderId)).list();
+ } else {
+ return daoSession.getFeedDao().queryBuilder().where(FeedDao.Properties.FolderId.eq(folderId)).list();
+ }
+ }
+
+ public List<Feed> getAllFeedsWithStarredRssItems() {
+ return daoSession.getFeedDao().queryBuilder().where(
+ new WhereCondition.StringCondition(FeedDao.Properties.Id.columnName + " IN " + "(SELECT " + RssItemDao.Properties.FeedId.columnName + " FROM " + RssItemDao.TABLENAME + " WHERE " + RssItemDao.Properties.Starred_temp.columnName + " = 1)")).list();
+ }
+
+ public List<PodcastFeedItem> getListOfFeedsWithAudioPodcasts() {
+ WhereCondition whereCondition = new WhereCondition.StringCondition(FeedDao.Properties.Id.columnName + " IN " + "(SELECT " + RssItemDao.Properties.FeedId.columnName + " FROM " + RssItemDao.TABLENAME + " WHERE " + RssItemDao.Properties.EnclosureMime.columnName + " IN(\"" + join(ALLOWED_PODCASTS_TYPES, "\",\"") + "\"))");
+ List<Feed> feedsWithPodcast = daoSession.getFeedDao().queryBuilder().where(whereCondition).list();
+
+ List<PodcastFeedItem> podcastFeedItemsList = new ArrayList<PodcastFeedItem>(feedsWithPodcast.size());
+ for(Feed feed : feedsWithPodcast) {
+ int podcastCount = 0;
+ for(RssItem rssItem : feed.getRssItemList()) {
+ if(ALLOWED_PODCASTS_TYPES.contains(rssItem.getEnclosureMime()))
+ podcastCount++;
+ }
+
+ podcastFeedItemsList.add(new PodcastFeedItem(feed, podcastCount));
+ }
+ return podcastFeedItemsList;
+ }
+
+ public List<PodcastItem> getListOfAudioPodcastsForFeed(Context context, long feedId) {
+ List<PodcastItem> result = new ArrayList<PodcastItem>();
+
+ for(RssItem rssItem : daoSession.getRssItemDao().queryBuilder()
+ .where(RssItemDao.Properties.EnclosureMime.in(ALLOWED_PODCASTS_TYPES), RssItemDao.Properties.FeedId.eq(feedId))
+ .orderDesc(RssItemDao.Properties.PubDate).list()) {
+ PodcastItem podcastItem = ParsePodcastItemFromRssItem(context, rssItem);
+ result.add(podcastItem);
+ }
+
+ return result;
+ }
+
+ public boolean areThereAnyUnsavedChangesInDatabase() {
+ long countUnreadRead = daoSession.getRssItemDao().queryBuilder().where(RssItemDao.Properties.Read_temp.notEq(RssItemDao.Properties.Read)).count();
+ long countStarredUnstarred = daoSession.getRssItemDao().queryBuilder().where(RssItemDao.Properties.Starred_temp.notEq(RssItemDao.Properties.Starred)).count();
+
+ return (countUnreadRead + countStarredUnstarred) > 0 ? true : false;
+ }
+
+
+ public void updateFeed(Feed feed) {
+ daoSession.getFeedDao().update(feed);
+ }
+
+
+ public long getLowestRssItemIdUnread() {
+ return daoSession.getRssItemDao().queryBuilder().where(RssItemDao.Properties.Read_temp.eq(false)).orderAsc(RssItemDao.Properties.Id).limit(1).unique().getId();
+ }
+
+ public RssItem getLowestRssItemIdByFeed(long idFeed) {
+ return daoSession.getRssItemDao().queryBuilder().where(RssItemDao.Properties.FeedId.eq(idFeed)).orderAsc(RssItemDao.Properties.Id).limit(1).unique();
+ }
+
+ public RssItem getRssItemById(long rssItemId) {
+ return daoSession.getRssItemDao().queryBuilder().where(RssItemDao.Properties.Id.eq(rssItemId)).unique();
+ }
+
+
+ /**
+ * Changes the read unread state of the item. This is NOT the temp value!!!
+ * @param itemIds
+ * @param markAsRead
+ */
+ public void change_readUnreadStateOfItem(List<String> itemIds, boolean markAsRead)
+ {
+ if(itemIds != null)
+ for(String idItem : itemIds)
+ updateIsReadOfRssItem(idItem, markAsRead);
+ }
+
+ /**
+ * Changes the starred unstarred state of the item. This is NOT the temp value!!!
+ * @param itemIds
+ * @param markAsStarred
+ */
+ public void change_starrUnstarrStateOfItem(List<String> itemIds, boolean markAsStarred)
+ {
+ if(itemIds != null)
+ for(String idItem : itemIds)
+ updateIsStarredOfRssItem(idItem, markAsStarred);
+ }
+
+ public void updateIsReadOfRssItem(String ITEM_ID, Boolean isRead) {
+ RssItem rssItem = daoSession.getRssItemDao().queryBuilder().where(RssItemDao.Properties.Id.eq(ITEM_ID)).unique();
+
+ rssItem.setRead(isRead);
+ rssItem.setRead_temp(isRead);
+
+ daoSession.getRssItemDao().update(rssItem);
+ }
+
+ public void updateIsStarredOfRssItem(String ITEM_ID, Boolean isStarred) {
+ RssItem rssItem = daoSession.getRssItemDao().queryBuilder().where(RssItemDao.Properties.Id.eq(ITEM_ID)).unique();
+
+ rssItem.setStarred(isStarred);
+ rssItem.setStarred_temp(isStarred);
+
+ daoSession.getRssItemDao().update(rssItem);
+ }
+
+ public List<String> getRssItemsIdsFromList(List<RssItem> rssItemList) {
+ List<String> itemIds = new ArrayList<String>();
+ for(RssItem rssItem : rssItemList) {
+ itemIds.add(String.valueOf(rssItem.getId()));
+ }
+ return itemIds;
+ }
+
+ public List<RssItem> getAllNewReadRssItems() {
+ return daoSession.getRssItemDao().queryBuilder().where(RssItemDao.Properties.Read.eq(false), RssItemDao.Properties.Read_temp.eq(true)).list();
+ }
+
+ public List<RssItem> getAllNewUnreadRssItems() {
+ return daoSession.getRssItemDao().queryBuilder().where(RssItemDao.Properties.Read.eq(true), RssItemDao.Properties.Read_temp.eq(false)).list();
+ }
+
+ public List<RssItem> getAllNewStarredRssItems() {
+ return daoSession.getRssItemDao().queryBuilder().where(RssItemDao.Properties.Starred.eq(false), RssItemDao.Properties.Starred_temp.eq(true)).list();
+ }
+
+ public List<RssItem> getAllNewUnstarredRssItems() {
+ return daoSession.getRssItemDao().queryBuilder().where(RssItemDao.Properties.Starred.eq(true), RssItemDao.Properties.Starred_temp.eq(false)).list();
+ }
+
+
+
+
+
+ public int getCountOfAllItems(boolean execludeStarred) {//TODO needs testing!
+ long count;
+ if(execludeStarred)
+ count = daoSession.getRssItemDao().queryBuilder().where(RssItemDao.Properties.Starred_temp.notEq(true)).count();
+ else
+ count = daoSession.getRssItemDao().count();
+ return (int) count;
+ }
+
+ public List<RssItem> getAllItemsWithIdHigher(long id) {//TODO needs testing!
+ return daoSession.getRssItemDao().queryBuilder().where(RssItemDao.Properties.Id.ge(id)).list();
+ }
+
+ public void updateRssItem(RssItem rssItem) {
+ daoSession.getRssItemDao().update(rssItem);
+ }
+
+ public boolean doesRssItemAlreadyExsists (long feedId) {
+ List<RssItem> feeds = daoSession.getRssItemDao().queryBuilder().where(RssItemDao.Properties.Id.eq(feedId)).list();
+ return (feeds.size() <= 0) ? false : true;
+ }
+
+
+ public void removeFeedById(long feedId) {
+ daoSession.getFeedDao().deleteByKey(feedId);
+ }
+
+
+
+
+ public SparseArray<String> getUrlsToFavIcons() {
+ SparseArray<String> favIconUrls = new SparseArray<String>();
+
+ for(Feed feed : getListOfFeeds())
+ favIconUrls.put((int) feed.getId(), feed.getFaviconUrl());
+
+ return favIconUrls;
+ }
+
+
+ public LazyList<RssItem> getCurrentRssItemView(DatabaseConnection.SORT_DIRECTION sortDirection) {
+ WhereCondition whereCondition = new WhereCondition.StringCondition(RssItemDao.Properties.Id.columnName + " IN " +
+ "(SELECT " + CurrentRssItemViewDao.Properties.RssItemId.columnName + " FROM " + CurrentRssItemViewDao.TABLENAME + ")");
+
+ if(sortDirection.equals(DatabaseConnection.SORT_DIRECTION.asc))
+ return daoSession.getRssItemDao().queryBuilder().where(whereCondition).orderAsc(RssItemDao.Properties.PubDate).listLazy();
+ else
+ return daoSession.getRssItemDao().queryBuilder().where(whereCondition).orderDesc(RssItemDao.Properties.PubDate).listLazy();
+ }
+
+ /*
+ public void markAllItemsAsReadForCurrentView()
+ {
+ String sql = "UPDATE " + RssItemDao.TABLENAME + " SET " + RssItemDao.Properties.Read_temp.columnName + " = 1 WHERE " + RssItemDao.Properties.Id.columnName +
+ " IN (SELECT " + CurrentRssItemViewDao.Properties.RssItemId.columnName + " FROM " + CurrentRssItemViewDao.TABLENAME + ")";
+ daoSession.getDatabase().execSQL(sql);
+ }
+ */
+
+ public static PodcastItem ParsePodcastItemFromRssItem(Context context, RssItem rssItem) {
+ PodcastItem podcastItem = new PodcastItem();
+ podcastItem.itemId = rssItem.getId();
+ podcastItem.title = rssItem.getTitle();
+ podcastItem.link = rssItem.getEnclosureLink();
+ podcastItem.mimeType = rssItem.getEnclosureMime();
+
+ File file = new File(PodcastDownloadService.getUrlToPodcastFile(context, podcastItem.link, false));
+ podcastItem.offlineCached = file.exists();
+
+ return podcastItem;
+ }
+
+
+ public String getAllItemsIdsForFeedSQL(long idFeed, boolean onlyUnread, boolean onlyStarredItems, DatabaseConnection.SORT_DIRECTION sortDirection) {
+
+ String buildSQL = "SELECT " + RssItemDao.Properties.Id.columnName +
+ " FROM " + RssItemDao.TABLENAME +
+ " WHERE " + RssItemDao.Properties.FeedId.columnName + " IN " +
+ "(SELECT " + FeedDao.Properties.Id.columnName +
+ " FROM " + FeedDao.TABLENAME +
+ " WHERE " + FeedDao.Properties.Id.columnName + " = " + idFeed + ")";
+
+ if(onlyUnread && !onlyStarredItems)
+ buildSQL += " AND " + RssItemDao.Properties.Read_temp.columnName + " != 1";
+ else if(onlyStarredItems)
+ buildSQL += " AND " + RssItemDao.Properties.Starred_temp.columnName + " = 1";
+
+ buildSQL += " ORDER BY " + RssItemDao.Properties.PubDate.columnName + " " + sortDirection.toString();
+
+ return buildSQL;
+ }
+
+
+ public Long getLowestItemIdByFolder(Long id_folder) {
+ WhereCondition whereCondition = new WhereCondition.StringCondition(RssItemDao.Properties.FeedId.columnName + " IN " +
+ "(SELECT " + FeedDao.Properties.Id.columnName +
+ " FROM " + FeedDao.TABLENAME +
+ " WHERE " + FeedDao.Properties.FolderId.columnName + " = " + id_folder + ")");
+
+ RssItem rssItem = daoSession.getRssItemDao().queryBuilder().orderAsc(RssItemDao.Properties.Id).where(whereCondition).limit(1).unique();
+ return (rssItem != null) ? rssItem.getId() : 0;
+ }
+
+ public List<RssItem> getListOfAllItemsForFolder(long ID_FOLDER, boolean onlyUnread, DatabaseConnection.SORT_DIRECTION sortDirection) {//TODO needs testing!
+ String whereStatement = getAllItemsIdsForFolderSQL(ID_FOLDER, onlyUnread, sortDirection);
+ whereStatement = whereStatement.replace("SELECT " + RssItemDao.Properties.Id.columnName + " FROM " + RssItemDao.TABLENAME, "");
+ return daoSession.getRssItemDao().queryRaw(whereStatement, null);
+ }
+
+ public String getAllItemsIdsForFolderSQL(long ID_FOLDER, boolean onlyUnread, DatabaseConnection.SORT_DIRECTION sortDirection) {
+ String buildSQL = "SELECT " + RssItemDao.Properties.Id.columnName +
+ " FROM " + RssItemDao.TABLENAME;
+
+ if(!(ID_FOLDER == ALL_UNREAD_ITEMS.getValue() || ID_FOLDER == ALL_STARRED_ITEMS.getValue()) || ID_FOLDER == ALL_ITEMS.getValue())//Wenn nicht Alle Artikel ausgewaehlt wurde (-10) oder (-11) fuer Starred Feeds
+ {
+ buildSQL += " WHERE " + RssItemDao.Properties.FeedId.columnName + " IN " +
+ "(SELECT sc." + FeedDao.Properties.Id.columnName +
+ " FROM " + FeedDao.TABLENAME + " sc " +
+ " JOIN " + FolderDao.TABLENAME + " f ON sc." + FeedDao.Properties.FolderId.columnName + " = f." + FolderDao.Properties.Id.columnName +
+ " WHERE f." + FolderDao.Properties.Id.columnName + " = " + ID_FOLDER + ")";
+
+ if(onlyUnread)
+ buildSQL += " AND " + RssItemDao.Properties.Read_temp.columnName + " != 1";
+ }
+ else if(ID_FOLDER == ALL_UNREAD_ITEMS.getValue())
+ buildSQL += " WHERE " + RssItemDao.Properties.Read_temp.columnName + " != 1";
+ else if(ID_FOLDER == ALL_STARRED_ITEMS.getValue())
+ buildSQL += " WHERE " + RssItemDao.Properties.Starred_temp.columnName + " = 1";
+
+
+ buildSQL += " ORDER BY " + RssItemDao.Properties.PubDate.columnName + " " + sortDirection.toString();
+
+
+ return buildSQL;
+ }
+
+ public void insertIntoRssCurrentViewTable(String SQL_SELECT) {
+ SQL_SELECT = "INSERT INTO " + CurrentRssItemViewDao.TABLENAME +
+ " (" + CurrentRssItemViewDao.Properties.RssItemId.columnName + ") " + SQL_SELECT;
+ daoSession.getCurrentRssItemViewDao().deleteAll();
+ daoSession.getDatabase().execSQL(SQL_SELECT);
+ }
+
+ public SparseArray<String> getUnreadItemCountForFolder() {
+ String buildSQL = "SELECT f." + FolderDao.Properties.Id.columnName + ", COUNT(rss." + RssItemDao.Properties.Id.columnName + ")" +
+ " FROM " + RssItemDao.TABLENAME + " rss " +
+ " JOIN " + FeedDao.TABLENAME + " feed ON rss." + RssItemDao.Properties.FeedId.columnName + " = feed." + FeedDao.Properties.Id.columnName +
+ " JOIN " + FolderDao.TABLENAME + " f ON feed." + FeedDao.Properties.FolderId.columnName + " = f." + FolderDao.Properties.Id.columnName +
+ " WHERE " + RssItemDao.Properties.Read_temp.columnName + " != 1 " +
+ " GROUP BY f." + FolderDao.Properties.Id.columnName;
+
+ SparseArray<String> values = getStringSparseArrayFromSQL(buildSQL, 0, 1);
+
+ values.put(SPECIAL_FOLDERS.ALL_UNREAD_ITEMS.getValue(), getUnreadItemsCountForSpecificFolder(SPECIAL_FOLDERS.ALL_UNREAD_ITEMS));
+ values.put(SPECIAL_FOLDERS.ALL_STARRED_ITEMS.getValue(), getUnreadItemsCountForSpecificFolder(SPECIAL_FOLDERS.ALL_STARRED_ITEMS));
+
+
+ return values;
+ }
+
+ public String getUnreadItemsCountForSpecificFolder(SPECIAL_FOLDERS specialFolder) {
+ String buildSQL = "SELECT COUNT(rss." + RssItemDao.Properties.Id.columnName + ")" +
+ " FROM " + RssItemDao.TABLENAME + " rss ";
+
+ if(specialFolder != null && specialFolder.equals(SPECIAL_FOLDERS.ALL_STARRED_ITEMS)) {
+ buildSQL += " WHERE " + RssItemDao.Properties.Starred_temp.columnName + " = 1 ";
+ } else {
+ buildSQL += " WHERE " + RssItemDao.Properties.Read_temp.columnName + " != 1 ";
+ }
+
+ SparseArray<String> values = getStringSparseArrayFromSQL(buildSQL, 0, 0);
+ return values.valueAt(0);
+ }
+
+ public SparseArray<String> getUnreadItemCountForFeed() {
+ String buildSQL = "SELECT " + RssItemDao.Properties.FeedId.columnName + ", COUNT(" + RssItemDao.Properties.Id.columnName + ")" + // rowid as _id,
+ " FROM " + RssItemDao.TABLENAME +
+ " WHERE " + RssItemDao.Properties.Read_temp.columnName + " != 1 " +
+ " GROUP BY " + RssItemDao.Properties.FeedId.columnName;
+
+ return getStringSparseArrayFromSQL(buildSQL, 0, 1);
+ }
+
+ public SparseArray<String> getStarredItemCountForFeed() {
+ String buildSQL = "SELECT " + RssItemDao.Properties.FeedId.columnName + ", COUNT(" + RssItemDao.Properties.Id.columnName + ")" + // rowid as _id,
+ " FROM " + RssItemDao.TABLENAME +
+ " WHERE " + RssItemDao.Properties.Starred_temp.columnName + " = 1 " +
+ " GROUP BY " + RssItemDao.Properties.FeedId.columnName;
+
+ return getStringSparseArrayFromSQL(buildSQL, 0, 1);
+ }
+
+ public void clearDatabaseOverSize()
+ {
+ //If i have 9023 rows in the database, when i run that query it should delete 8023 rows and leave me with 1000
+ //database.execSQL("DELETE FROM " + RSS_ITEM_TABLE + " WHERE " + + "ORDER BY rowid DESC LIMIT 1000 *
+
+ //Let's say it said 1005 - you need to delete 5 rows.
+ //DELETE FROM table ORDER BY dateRegistered ASC LIMIT 5
+
+
+ int max = Constants.maxItemsCount;
+ int total = (int) getLongValueBySQL("SELECT COUNT(*) FROM " + RssItemDao.TABLENAME);
+ int unread = (int) getLongValueBySQL("SELECT COUNT(*) FROM " + RssItemDao.TABLENAME + " WHERE " + RssItemDao.Properties.Read_temp.columnName + " != 1");
+ int read = total - unread;
+
+ if(total > max)
+ {
+ int overSize = total - max;
+ //Soll verhindern, dass ungelesene Artikel gelöscht werden
+ if(overSize > read)
+ overSize = read;
+
+ String sqlStatement = "DELETE FROM " + RssItemDao.TABLENAME + " WHERE " + RssItemDao.Properties.Id.columnName +
+ " IN (SELECT " + RssItemDao.Properties.Id.columnName + " FROM " + RssItemDao.TABLENAME +
+ " WHERE " + RssItemDao.Properties.Read_temp.columnName + " = 1 AND " + RssItemDao.Properties.Starred_temp.columnName + " != 1 " +
+ " ORDER BY " + RssItemDao.Properties.Id.columnName + " asc LIMIT " + overSize + ")";
+ daoSession.getDatabase().execSQL(sqlStatement);
+ /* SELECT * FROM rss_item WHERE read_temp = 1 ORDER BY rowid asc LIMIT 3; */
+ }
+ }
+
+ public long getLastModified()
+ {
+ List<RssItem> rssItemList = daoSession.getRssItemDao().queryBuilder().orderDesc(RssItemDao.Properties.LastModified).limit(1).list();
+
+ if(rssItemList.size() > 0)
+ return rssItemList.get(0).getLastModified().getTime();
+ return 0;
+ }
+
+ public long getLowestItemId(boolean onlyStarred)
+ {
+ List<RssItem> rssItemList;
+
+ if(onlyStarred)
+ rssItemList = daoSession.getRssItemDao().queryBuilder().orderDesc(RssItemDao.Properties.Starred_temp).orderAsc(RssItemDao.Properties.Id).limit(1).list();
+ else
+ rssItemList = daoSession.getRssItemDao().queryBuilder().orderAsc(RssItemDao.Properties.Id).limit(1).list();
+
+ if(rssItemList.size() > 0)
+ return rssItemList.get(0).getId();
+ return 0;
+ }
+
+ public long getHighestItemId()
+ {
+ List<RssItem> rssItemList = daoSession.getRssItemDao().queryBuilder().orderDesc(RssItemDao.Properties.Id).limit(1).list();
+
+ if(rssItemList.size() > 0)
+ return rssItemList.get(0).getId();
+ return 0;
+ }
+
+
+
+
+
+
+
+
+ public long getLongValueBySQL(String buildSQL)
+ {
+ long result = -1;
+
+ Cursor cursor = daoSession.getDatabase().rawQuery(buildSQL, null);
+ try
+ {
+ if(cursor != null)
+ {
+ if(cursor.moveToFirst())
+ result = cursor.getLong(0);
+ }
+ } finally {
+ cursor.close();
+ }
+
+ return result;
+ }
+
+ public SparseArray<Integer> getIntegerSparseArrayFromSQL(String buildSQL, int indexKey, int indexValue) {
+ SparseArray<Integer> result = new SparseArray<Integer>();
+
+ Cursor cursor = daoSession.getDatabase().rawQuery(buildSQL, null);
+ try
+ {
+ if(cursor != null)
+ {
+ if(cursor.getCount() > 0)
+ {
+ cursor.moveToFirst();
+ do {
+ int key = cursor.getInt(indexKey);
+ Integer value = cursor.getInt(indexValue);
+ result.put(key, value);
+ } while(cursor.moveToNext());
+ }
+ }
+ } finally {
+ cursor.close();
+ }
+
+ return result;
+ }
+
+ public SparseArray<String> getStringSparseArrayFromSQL(String buildSQL, int indexKey, int indexValue) {
+ SparseArray<String> result = new SparseArray<String>();
+
+ Cursor cursor = daoSession.getDatabase().rawQuery(buildSQL, null);
+ try
+ {
+ if(cursor != null)
+ {
+ if(cursor.getCount() > 0)
+ {
+ cursor.moveToFirst();
+ do {
+ int key = cursor.getInt(indexKey);
+ String value = cursor.getString(indexValue);
+ result.put(key, value);
+ } while(cursor.moveToNext());
+ }
+ }
+ } finally {
+ cursor.close();
+ }
+
+ return result;
+ }
+
+
+
+ public static String join(Collection<?> col, String delim) {
+ StringBuilder sb = new StringBuilder();
+ Iterator<?> iter = col.iterator();
+ if (iter.hasNext())
+ sb.append(iter.next().toString());
+ while (iter.hasNext()) {
+ sb.append(delim);
+ sb.append(iter.next().toString());
+ }
+ return sb.toString();
+ }
+}
diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseHelperOrm.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseHelperOrm.java
new file mode 100644
index 00000000..1ca1ca14
--- /dev/null
+++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseHelperOrm.java
@@ -0,0 +1,51 @@
+/**
+ * Android ownCloud News
+ *
+ * @author David Luhmer
+ * @copyright 2013 David Luhmer david-dev@live.de
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package de.luhmer.owncloudnewsreader.database;
+
+import android.content.Context;
+import android.database.sqlite.SQLiteDatabase;
+
+import de.luhmer.owncloudnewsreader.database.model.DaoMaster;
+import de.luhmer.owncloudnewsreader.database.model.DaoSession;
+
+public class DatabaseHelperOrm {
+ public static final String DATABASE_NAME_ORM = "OwncloudNewsReaderOrm.db";
+
+
+ private static DaoSession daoSession;
+
+
+ public static synchronized DaoSession getDaoSession(Context context)
+ {
+ if(daoSession == null) {
+ // As we are in development we will use the DevOpenHelper which drops the database on a schema update
+ DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(context, DATABASE_NAME_ORM, null);
+ // Access the database using the helper
+ SQLiteDatabase db = helper.getWritableDatabase();
+ // Construct the DaoMaster which brokers DAOs for the Domain Objects
+ DaoMaster daoMaster = new DaoMaster(db);
+ // Create the session which is a container for the DAO layer and has a cache which will return handles to the same object across multiple queries
+ daoSession = daoMaster.newSession();
+ }
+ return daoSession;
+ }
+}
diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/generator/DatabaseOrmGenerator.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/generator/DatabaseOrmGenerator.java
new file mode 100644
index 00000000..685b9477
--- /dev/null
+++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/generator/DatabaseOrmGenerator.java
@@ -0,0 +1,76 @@
+package de.luhmer.owncloudnewsreader.database.generator;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import de.greenrobot.daogenerator.DaoGenerator;
+
+/**
+ * Created by David on 15.07.2014.
+ */
+public class DatabaseOrmGenerator {
+ private static final String SCHEMA_OUTPUT_DIR = "./News-Android-App/src/main/java/";
+
+
+ /**
+ * Generator main application which builds all of the schema versions
+ * (including older versions used for migration test purposes) and ensures
+ * business rules are met; these include ensuring we only have a single
+ * current schema instance and the version numbering is correct.
+ *
+ * @param args
+ *
+ * @throws Exception
+ * @throws IOException
+ */
+ public static void main(String[] args) throws IOException, Exception {
+ List<SchemaVersion> versions = new ArrayList<SchemaVersion>();
+
+ versions.add(new Version3(true));
+
+ validateSchemas(versions);
+
+ for (SchemaVersion version : versions) {
+ // NB: Test output creates stubs, we have an established testing
+ // standard which should be followed in preference to generating
+ // these stubs.
+ new DaoGenerator().generateAll(version.getSchema(),
+ SCHEMA_OUTPUT_DIR);
+ }
+ }
+
+ /**
+ * Validate the schema, throws
+ *
+ * @param versions
+ * @throws IllegalArgumentException
+ * if data is invalid
+ */
+ public static void validateSchemas(List<SchemaVersion> versions)
+ throws IllegalArgumentException {
+ int numCurrent = 0;
+ Set<Integer> versionNumbers = new HashSet<Integer>();
+
+ for (SchemaVersion version : versions) {
+ if (version.isCurrent()) {
+ numCurrent++;
+ }
+
+ int versionNumber = version.getVersionNumber();
+ if (versionNumbers.contains(versionNumber)) {
+ throw new IllegalArgumentException(
+ "Unable to process schema versions, multiple instances with version number : "
+ + version.getVersionNumber());
+ }
+ versionNumbers.add(versionNumber);
+ }
+
+ if (numCurrent != 1) {
+ throw new IllegalArgumentException(
+ "Unable to generate schema, exactly one schema marked as current is required.");
+ }
+ }
+}
diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/generator/SchemaVersion.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/generator/SchemaVersion.java
new file mode 100644
index 00000000..e7573585
--- /dev/null
+++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/generator/SchemaVersion.java
@@ -0,0 +1,51 @@
+package de.luhmer.owncloudnewsreader.database.generator;
+
+import de.greenrobot.daogenerator.Schema;
+
+/**
+ * Created by David on 18.07.2014.
+ */
+public abstract class SchemaVersion {
+
+ public static final String CURRENT_SCHEMA_PACKAGE = "de.luhmer.owncloudnewsreader.database.model";
+
+
+ private final Schema schema;
+
+ private final boolean current;
+
+ /**
+ * Constructor
+ *
+ * @param current indicating if this is the current schema.
+ */
+ public SchemaVersion(boolean current) {
+ int version = getVersionNumber();
+ String packageName = CURRENT_SCHEMA_PACKAGE;
+ if (!current) {
+ packageName += ".v" + version;
+ }
+ this.schema = new Schema(version, packageName);
+ this.schema.enableKeepSectionsByDefault();
+ this.current = current;
+ }
+
+ /**
+ * @return the GreenDAO schema.
+ */
+ protected Schema getSchema() {
+ return schema;
+ }
+
+ /**
+ * @return boolean indicating if this is the highest or current schema version.
+ */
+ public boolean isCurrent() {
+ return current;
+ }
+
+ /**
+ * @return unique integer schema version identifier.
+ */
+ public abstract int getVersionNumber();
+}
diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/generator/Version3.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/generator/Version3.java
new file mode 100644
index 00000000..dedc535b
--- /dev/null
+++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/generator/Version3.java
@@ -0,0 +1,96 @@
+package de.luhmer.owncloudnewsreader.database.generator;
+
+/**
+ * Created by David on 18.07.2014.
+ */
+
+import de.greenrobot.daogenerator.Entity;
+import de.greenrobot.daogenerator.Property;
+import de.greenrobot.daogenerator.Schema;
+
+/**
+ * Version 1 of the Schema definition
+ *
+ * @author Jeremy
+ */
+public class Version3 extends SchemaVersion {
+
+ /**
+ * Constructor
+ *
+ * @param current
+ */
+ public Version3(boolean current) {
+ super(current);
+
+ Schema schema = getSchema();
+ addEntitysToSchema(schema);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getVersionNumber() {
+ return 3;
+ }
+
+ private static void addEntitysToSchema(Schema schema) {
+
+ /* Folder */
+ Entity folder = schema.addEntity("Folder");
+ Property folderId = folder.addIdProperty().notNull().getProperty();
+ folder.addStringProperty("label").notNull();
+
+ /* Feed */
+ Entity feed = schema.addEntity("Feed");
+ Property feedId = feed.addIdProperty().notNull().getProperty();
+ Property folderIdProperty = feed.addLongProperty("folderId").getProperty();
+
+ feed.addStringProperty("feedTitle").notNull();
+ feed.addStringProperty("faviconUrl");
+ feed.addStringProperty("link");
+ feed.addStringProperty("avgColour");
+
+
+
+ /* RSS Item */
+ Entity rssItem = schema.addEntity("RssItem");
+ Property rssItemId = rssItem.addIdProperty().notNull().getProperty();
+ Property rssItemFeedId = rssItem.addLongProperty("feedId").notNull().getProperty();
+
+ rssItem.addStringProperty("link");
+ rssItem.addStringProperty("title");
+ rssItem.addStringProperty("body");
+ rssItem.addBooleanProperty("read");
+ rssItem.addBooleanProperty("starred");
+ rssItem.addStringProperty("author").notNull();
+ rssItem.addStringProperty("guid").notNull();
+ rssItem.addStringProperty("guidHash").notNull();
+ rssItem.addBooleanProperty("read_temp");
+ rssItem.addBooleanProperty("starred_temp");
+ rssItem.addDateProperty("lastModified");
+ rssItem.addDateProperty("pubDate");
+
+
+ rssItem.addStringProperty("enclosureLink");
+ rssItem.addStringProperty("enclosureMime");
+
+
+ feed.addToOne(folder, folderIdProperty);
+ folder.addToMany(feed, folderIdProperty);
+
+ feed.addToMany(rssItem, rssItemFeedId);
+ rssItem.addToOne(feed, rssItemFeedId);
+
+
+
+
+ Entity rssItemView = schema.addEntity("CurrentRssItemView");
+ rssItemView.addIdProperty().notNull();
+ rssItemView.addLongProperty("rssItemId").notNull();
+
+
+ rssItem.implementsInterface("HasId<Long>");
+ }
+}
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);
+ }
+
+}