diff options
author | David-Development <david-dev@live.de> | 2021-11-07 15:21:53 +0300 |
---|---|---|
committer | David Luhmer <david-dev@live.de> | 2021-11-07 15:21:53 +0300 |
commit | 1e03e58a531d393fb7a0ea3b4d1c676a5dfddf05 (patch) | |
tree | 3c0f61f9b199a7c77e16f5d6ec1d4ad5f5da06b8 /News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model | |
parent | 9da6c30a9d7c76ee455bff9be497f95b374d29da (diff) |
refactor sync
Signed-off-by: David Luhmer <david-dev@live.de>
Diffstat (limited to 'News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/model')
5 files changed, 180 insertions, 176 deletions
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 index 1bd9c10f..730c73d6 100644 --- 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 @@ -55,9 +55,7 @@ public class CurrentRssItemViewDao extends AbstractDao<CurrentRssItemView, Long> return cursor.getLong(offset + 0); } - /** - * @inheritdoc - */ + /** @inheritdoc */ @Override public CurrentRssItemView readEntity(Cursor cursor, int offset) { CurrentRssItemView entity = new CurrentRssItemView( // 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 index 53b01a3f..2b015305 100644 --- 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 @@ -11,10 +11,10 @@ import de.greenrobot.dao.identityscope.IdentityScopeType; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. /** - * Master of DAO (schema version 8): knows all DAOs. + * Master of DAO (schema version 9): knows all DAOs. */ public class DaoMaster extends AbstractDaoMaster { - public static final int SCHEMA_VERSION = 8; + public static final int SCHEMA_VERSION = 9; /** Creates underlying database table using DAOs. */ public static void createAllTables(SQLiteDatabase db, boolean ifNotExists) { @@ -57,6 +57,13 @@ public class DaoMaster extends AbstractDaoMaster { dropAllTables(db, true); onCreate(db); } + + @Override + public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) { + Log.i("greenDAO", "Downgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); + dropAllTables(db, true); + onCreate(db); + } } public DaoMaster(SQLiteDatabase db) { 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 index 45cf8e4c..dc6348be 100644 --- 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 @@ -15,16 +15,34 @@ 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"; + 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; + } + + /** Drops the underlying database table. */ + public static void dropTable(SQLiteDatabase db, boolean ifExists) { + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"FEED\""; + db.execSQL(sql); + } + /** Creates the underlying database table. */ public static void createTable(SQLiteDatabase db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; + 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 @@ -38,19 +56,6 @@ public class FeedDao extends AbstractDao<Feed, Long> { " (\"FOLDER_ID\");"); } - 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; - } - /** * @inheritdoc */ @@ -86,17 +91,7 @@ public class FeedDao extends AbstractDao<Feed, Long> { } } - /** - * 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 - */ + /** @inheritdoc */ @Override public Long readKey(Cursor cursor, int offset) { return cursor.getLong(offset + 0); @@ -108,9 +103,7 @@ public class FeedDao extends AbstractDao<Feed, Long> { entity.__setDaoSession(daoSession); } - /** - * @inheritdoc - */ + /** @inheritdoc */ @Override public Feed readEntity(Cursor cursor, int offset) { Feed entity = new Feed( // @@ -139,33 +132,6 @@ public class FeedDao extends AbstractDao<Feed, Long> { entity.setNotificationChannel(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); } - 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(); - } - } - /** * @inheritdoc */ @@ -174,11 +140,23 @@ public class FeedDao extends AbstractDao<Feed, Long> { entity.setId(rowId); return rowId; } - - /** @inheritdoc */ + + 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; + } + + /** + * @inheritdoc + */ @Override public Long getKey(Feed entity) { - if(entity != null) { + if (entity != null) { return entity.getId(); } else { return null; @@ -221,33 +199,34 @@ public class FeedDao extends AbstractDao<Feed, Long> { return selectDeep; } - protected Feed loadCurrentDeep(Cursor cursor, boolean lock) { - Feed entity = loadCurrent(cursor, 0, lock); - int offset = getAllColumns().length; + public Feed loadDeep(Long key) { + assertSinglePk(); + if (key == null) { + return null; + } - Folder folder = loadCurrentOther(daoSession.getFolderDao(), cursor, offset); - entity.setFolder(folder); + StringBuilder builder = new StringBuilder(getSelectDeep()); + builder.append("WHERE "); + SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns()); + String sql = builder.toString(); - return entity; - } + String[] keyArray = new String[]{key.toString()}; + Cursor cursor = db.rawQuery(sql, keyArray); - /** - * 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"); - public final static Property NotificationChannel = new Property(6, String.class, "notificationChannel", false, "NOTIFICATION_CHANNEL"); + 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. - */ + /** 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); @@ -269,7 +248,21 @@ public class FeedDao extends AbstractDao<Feed, Long> { } return list; } - + + /** + * 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"); + public final static Property NotificationChannel = new Property(6, String.class, "notificationChannel", false, "NOTIFICATION_CHANNEL"); + } + protected List<Feed> loadDeepAllAndCloseCursor(Cursor cursor) { try { return loadAllDeepFromCursor(cursor); @@ -277,7 +270,7 @@ public class FeedDao extends AbstractDao<Feed, Long> { cursor.close(); } } - + /** A raw-style query where you can pass any WHERE clause and arguments. */ public List<Feed> queryDeep(String where, String... selectionArg) { 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 index b17151d0..3765d10e 100644 --- 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 @@ -82,15 +82,6 @@ public class FolderDao extends AbstractDao<Folder, Long> { } /** - * 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"); - } - - /** * @inheritdoc */ @Override @@ -104,17 +95,28 @@ public class FolderDao extends AbstractDao<Folder, Long> { */ @Override public Long getKey(Folder entity) { - if(entity != null) { + if (entity != null) { return entity.getId(); } else { return null; } } - /** @inheritdoc */ - @Override + /** + * 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"); + } + + /** + * @inheritdoc + */ + @Override protected boolean isEntityUpdateable() { return true; } - + } 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 index d6ba7141..078decd1 100644 --- 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 @@ -179,15 +179,15 @@ public class RssItemDao extends AbstractDao<RssItem, Long> { cursor.getString(offset + 8), // guid cursor.getString(offset + 9), // guidHash cursor.getString(offset + 10), // fingerprint - cursor.isNull(offset + 11) ? null : cursor.getShort(offset + 11) != 0, // read_temp - cursor.isNull(offset + 12) ? null : cursor.getShort(offset + 12) != 0, // starred_temp - cursor.isNull(offset + 13) ? null : new java.util.Date(cursor.getLong(offset + 13)), // lastModified - cursor.isNull(offset + 14) ? null : new java.util.Date(cursor.getLong(offset + 14)), // pubDate - cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15), // enclosureLink - cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16), // enclosureMime - cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17), // mediaThumbnail - cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18), // mediaDescription - cursor.isNull(offset + 19) ? null : cursor.getShort(offset + 19) != 0 // rtl + cursor.isNull(offset + 11) ? null : cursor.getShort(offset + 11) != 0, // read_temp + cursor.isNull(offset + 12) ? null : cursor.getShort(offset + 12) != 0, // starred_temp + cursor.isNull(offset + 13) ? null : new java.util.Date(cursor.getLong(offset + 13)), // lastModified + cursor.isNull(offset + 14) ? null : new java.util.Date(cursor.getLong(offset + 14)), // pubDate + cursor.isNull(offset + 15) ? null : cursor.getString(offset + 15), // enclosureLink + cursor.isNull(offset + 16) ? null : cursor.getString(offset + 16), // enclosureMime + cursor.isNull(offset + 17) ? null : cursor.getString(offset + 17), // mediaThumbnail + cursor.isNull(offset + 18) ? null : cursor.getString(offset + 18), // mediaDescription + cursor.isNull(offset + 19) ? null : cursor.getShort(offset + 19) != 0 // rtl ); return entity; } @@ -217,33 +217,6 @@ public class RssItemDao extends AbstractDao<RssItem, Long> { entity.setRtl(cursor.isNull(offset + 19) ? null : cursor.getShort(offset + 19) != 0); } - 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(); - } - } - /** * @inheritdoc */ @@ -258,20 +231,36 @@ public class RssItemDao extends AbstractDao<RssItem, Long> { */ @Override public Long getKey(RssItem entity) { - if(entity != null) { + if (entity != null) { return entity.getId(); } else { return null; } } - /** @inheritdoc */ - @Override + 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; + } + + /** + * @inheritdoc + */ + @Override protected boolean isEntityUpdateable() { return true; } - - /** Internal query to resolve the "rssItemList" to-many relationship of Feed. */ + + /** + * Internal query to resolve the "rssItemList" to-many relationship of Feed. + */ public List<RssItem> _queryFeed_RssItemList(long feedId) { synchronized (this) { if (feed_RssItemListQuery == null) { @@ -300,17 +289,57 @@ public class RssItemDao extends AbstractDao<RssItem, Long> { } 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); + public RssItem loadDeep(Long key) { + assertSinglePk(); + if (key == null) { + return null; } - return entity; + 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; } /** @@ -339,31 +368,6 @@ public class RssItemDao extends AbstractDao<RssItem, Long> { public final static Property MediaDescription = new Property(18, String.class, "mediaDescription", false, "MEDIA_DESCRIPTION"); public final static Property Rtl = new Property(19, Boolean.class, "rtl", false, "RTL"); } - - /** - * 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 { |