From 15445c2c0d448a75e6c0f52125af0919313e36ad Mon Sep 17 00:00:00 2001 From: David-Development Date: Sat, 17 Jan 2015 12:19:08 +0100 Subject: [PATCH] Update ORM and improve SQL --- .../database/DatabaseConnectionOrm.java | 11 ++++++++--- .../database/generator/DatabaseOrmGenerator.java | 2 +- .../generator/{Version3.java => Version4.java} | 10 +++++----- 3 files changed, 14 insertions(+), 9 deletions(-) rename News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/generator/{Version3.java => Version4.java} (93%) 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 index 4da3fcc1..69f1d2ce 100644 --- 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 @@ -357,13 +357,18 @@ public class DatabaseConnectionOrm { public String getAllItemsIdsForFeedSQL(long idFeed, boolean onlyUnread, boolean onlyStarredItems, DatabaseConnection.SORT_DIRECTION sortDirection) { + //TODO does this sql statement work properly? + String buildSQL = "SELECT " + RssItemDao.Properties.Id.columnName + + " FROM " + RssItemDao.TABLENAME + + " WHERE " + RssItemDao.Properties.FeedId.columnName + " = " + idFeed; + /* 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) @@ -462,7 +467,7 @@ public class DatabaseConnectionOrm { } public SparseArray getUnreadItemCountForFeed() { - String buildSQL = "SELECT " + RssItemDao.Properties.FeedId.columnName + ", COUNT(" + RssItemDao.Properties.Id.columnName + ")" + // rowid as _id, + String buildSQL = "SELECT " + RssItemDao.Properties.FeedId.columnName + ", COUNT(1)" + // rowid as _id, " FROM " + RssItemDao.TABLENAME + " WHERE " + RssItemDao.Properties.Read_temp.columnName + " != 1 " + " GROUP BY " + RssItemDao.Properties.FeedId.columnName; @@ -471,7 +476,7 @@ public class DatabaseConnectionOrm { } public SparseArray getStarredItemCountForFeed() { - String buildSQL = "SELECT " + RssItemDao.Properties.FeedId.columnName + ", COUNT(" + RssItemDao.Properties.Id.columnName + ")" + // rowid as _id, + String buildSQL = "SELECT " + RssItemDao.Properties.FeedId.columnName + ", COUNT(1)" + // rowid as _id, " FROM " + RssItemDao.TABLENAME + " WHERE " + RssItemDao.Properties.Starred_temp.columnName + " = 1 " + " GROUP BY " + RssItemDao.Properties.FeedId.columnName; 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 index 685b9477..89637016 100644 --- 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 @@ -29,7 +29,7 @@ public class DatabaseOrmGenerator { public static void main(String[] args) throws IOException, Exception { List versions = new ArrayList(); - versions.add(new Version3(true)); + versions.add(new Version4(true)); validateSchemas(versions); 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/Version4.java similarity index 93% rename from News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/generator/Version3.java rename to News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/generator/Version4.java index dedc535b..9c067d3e 100644 --- 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/Version4.java @@ -13,14 +13,14 @@ import de.greenrobot.daogenerator.Schema; * * @author Jeremy */ -public class Version3 extends SchemaVersion { +public class Version4 extends SchemaVersion { /** * Constructor * * @param current */ - public Version3(boolean current) { + public Version4(boolean current) { super(current); Schema schema = getSchema(); @@ -32,7 +32,7 @@ public class Version3 extends SchemaVersion { */ @Override public int getVersionNumber() { - return 3; + return 4; } private static void addEntitysToSchema(Schema schema) { @@ -45,7 +45,7 @@ public class Version3 extends SchemaVersion { /* Feed */ Entity feed = schema.addEntity("Feed"); Property feedId = feed.addIdProperty().notNull().getProperty(); - Property folderIdProperty = feed.addLongProperty("folderId").getProperty(); + Property folderIdProperty = feed.addLongProperty("folderId").index().getProperty(); feed.addStringProperty("feedTitle").notNull(); feed.addStringProperty("faviconUrl"); @@ -57,7 +57,7 @@ public class Version3 extends SchemaVersion { /* RSS Item */ Entity rssItem = schema.addEntity("RssItem"); Property rssItemId = rssItem.addIdProperty().notNull().getProperty(); - Property rssItemFeedId = rssItem.addLongProperty("feedId").notNull().getProperty(); + Property rssItemFeedId = rssItem.addLongProperty("feedId").notNull().index().getProperty(); rssItem.addStringProperty("link"); rssItem.addStringProperty("title");