Update ORM and improve SQL

This commit is contained in:
David-Development 2015-01-17 12:19:08 +01:00 committed by David Development
parent c7ee15ea9c
commit 205d0c1b94
12 changed files with 73 additions and 29 deletions

View file

@ -64,8 +64,20 @@ public class DatabaseConnectionOrm {
daoSession = DatabaseHelperOrm.getDaoSession(context);
}
/*
public void insertNewFolder (Folder folder) {
daoSession.getFolderDao().insertOrReplace(folder);
}*/
public void deleteOldAndInsertNewFolders (final Folder... folder) {
daoSession.runInTx(new Runnable() {
@Override
public void run() {
daoSession.getFolderDao().deleteAll();
daoSession.getFolderDao().insertInTx(folder);
}
});
}
public void insertNewFeed (Feed feed) {
@ -359,10 +371,7 @@ public class DatabaseConnectionOrm {
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 + ")";
" WHERE " + RssItemDao.Properties.FeedId.columnName + " = " + idFeed;
if(onlyUnread && !onlyStarredItems)
buildSQL += " AND " + RssItemDao.Properties.Read_temp.columnName + " != 1";
@ -426,8 +435,16 @@ public class DatabaseConnectionOrm {
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);
final String SQL_INSERT_STATEMENT = SQL_SELECT;
daoSession.runInTx(new Runnable() {
@Override
public void run() {
daoSession.getCurrentRssItemViewDao().deleteAll();
daoSession.getDatabase().execSQL(SQL_INSERT_STATEMENT);
}
});
}
public SparseArray<String> getUnreadItemCountForFolder() {
@ -448,7 +465,7 @@ public class DatabaseConnectionOrm {
}
public String getUnreadItemsCountForSpecificFolder(SPECIAL_FOLDERS specialFolder) {
String buildSQL = "SELECT COUNT(rss." + RssItemDao.Properties.Id.columnName + ")" +
String buildSQL = "SELECT COUNT(1)" +
" FROM " + RssItemDao.TABLENAME + " rss ";
if(specialFolder != null && specialFolder.equals(SPECIAL_FOLDERS.ALL_STARRED_ITEMS)) {
@ -462,7 +479,7 @@ public class DatabaseConnectionOrm {
}
public SparseArray<String> 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 +488,7 @@ public class DatabaseConnectionOrm {
}
public SparseArray<String> 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;

View file

@ -29,7 +29,7 @@ public class DatabaseOrmGenerator {
public static void main(String[] args) throws IOException, Exception {
List<SchemaVersion> versions = new ArrayList<SchemaVersion>();
versions.add(new Version3(true));
versions.add(new Version4(true));
validateSchemas(versions);

View file

@ -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");

View file

@ -8,6 +8,8 @@ import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.Property;
import de.greenrobot.dao.internal.DaoConfig;
import de.luhmer.owncloudnewsreader.database.model.CurrentRssItemView;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* DAO for table CURRENT_RSS_ITEM_VIEW.

View file

@ -5,16 +5,20 @@ 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;
import de.luhmer.owncloudnewsreader.database.model.FolderDao;
import de.luhmer.owncloudnewsreader.database.model.FeedDao;
import de.luhmer.owncloudnewsreader.database.model.RssItemDao;
import de.luhmer.owncloudnewsreader.database.model.CurrentRssItemViewDao;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* Master of DAO (schema version 3): knows all DAOs.
* Master of DAO (schema version 4): knows all DAOs.
*/
public class DaoMaster extends AbstractDaoMaster {
public static final int SCHEMA_VERSION = 3;
public static final int SCHEMA_VERSION = 4;
/** Creates underlying database table using DAOs. */
public static void createAllTables(SQLiteDatabase db, boolean ifNotExists) {

View file

@ -9,6 +9,16 @@ import de.greenrobot.dao.AbstractDaoSession;
import de.greenrobot.dao.identityscope.IdentityScopeType;
import de.greenrobot.dao.internal.DaoConfig;
import de.luhmer.owncloudnewsreader.database.model.Folder;
import de.luhmer.owncloudnewsreader.database.model.Feed;
import de.luhmer.owncloudnewsreader.database.model.RssItem;
import de.luhmer.owncloudnewsreader.database.model.CurrentRssItemView;
import de.luhmer.owncloudnewsreader.database.model.FolderDao;
import de.luhmer.owncloudnewsreader.database.model.FeedDao;
import de.luhmer.owncloudnewsreader.database.model.RssItemDao;
import de.luhmer.owncloudnewsreader.database.model.CurrentRssItemViewDao;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**

View file

@ -1,7 +1,7 @@
package de.luhmer.owncloudnewsreader.database.model;
import java.util.List;
import de.luhmer.owncloudnewsreader.database.model.DaoSession;
import de.greenrobot.dao.DaoException;
// THIS CODE IS GENERATED BY greenDAO, EDIT ONLY INSIDE THE "KEEP"-SECTIONS

View file

@ -1,19 +1,20 @@
package de.luhmer.owncloudnewsreader.database.model;
import java.util.List;
import java.util.ArrayList;
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.internal.DaoConfig;
import de.greenrobot.dao.query.Query;
import de.greenrobot.dao.query.QueryBuilder;
import de.luhmer.owncloudnewsreader.database.model.Feed;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* DAO for table FEED.
@ -58,6 +59,9 @@ public class FeedDao extends AbstractDao<Feed, Long> {
"'FAVICON_URL' TEXT," + // 3: faviconUrl
"'LINK' TEXT," + // 4: link
"'AVG_COLOUR' TEXT);"); // 5: avgColour
// Add Indexes
db.execSQL("CREATE INDEX " + constraint + "IDX_FEED_FOLDER_ID ON FEED" +
" (FOLDER_ID);");
}
/** Drops the underlying database table. */

View file

@ -1,7 +1,7 @@
package de.luhmer.owncloudnewsreader.database.model;
import java.util.List;
import de.luhmer.owncloudnewsreader.database.model.DaoSession;
import de.greenrobot.dao.DaoException;
// THIS CODE IS GENERATED BY greenDAO, EDIT ONLY INSIDE THE "KEEP"-SECTIONS

View file

@ -8,6 +8,8 @@ import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.Property;
import de.greenrobot.dao.internal.DaoConfig;
import de.luhmer.owncloudnewsreader.database.model.Folder;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* DAO for table FOLDER.

View file

@ -1,7 +1,8 @@
package de.luhmer.owncloudnewsreader.database.model;
import de.greenrobot.dao.DaoException;
import de.luhmer.owncloudnewsreader.adapter.HasId;
import de.luhmer.owncloudnewsreader.database.model.DaoSession;
import de.greenrobot.dao.DaoException;
// THIS CODE IS GENERATED BY greenDAO, EDIT ONLY INSIDE THE "KEEP"-SECTIONS

View file

@ -1,19 +1,20 @@
package de.luhmer.owncloudnewsreader.database.model;
import java.util.List;
import java.util.ArrayList;
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.internal.DaoConfig;
import de.greenrobot.dao.query.Query;
import de.greenrobot.dao.query.QueryBuilder;
import de.luhmer.owncloudnewsreader.database.model.RssItem;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* DAO for table RSS_ITEM.
@ -78,6 +79,9 @@ public class RssItemDao extends AbstractDao<RssItem, Long> {
"'PUB_DATE' INTEGER," + // 13: pubDate
"'ENCLOSURE_LINK' TEXT," + // 14: enclosureLink
"'ENCLOSURE_MIME' TEXT);"); // 15: enclosureMime
// Add Indexes
db.execSQL("CREATE INDEX " + constraint + "IDX_RSS_ITEM_FEED_ID ON RSS_ITEM" +
" (FEED_ID);");
}
/** Drops the underlying database table. */