diff options
author | desperateCoder <echotodevnull@gmail.com> | 2020-10-29 14:27:51 +0300 |
---|---|---|
committer | desperateCoder <echotodevnull@gmail.com> | 2020-10-29 14:27:51 +0300 |
commit | e1e9d7c76976c53d8d3f38b8f3ae0622015f282f (patch) | |
tree | 05db234869bcb87e6cbd0fe5050b3935497e5564 /app/src/main/java/it/niedermann/nextcloud/deck/persistence | |
parent | 94dd6cac5e7386145643fb17622302dfa5f50197 (diff) | |
parent | 3a55ceafd0bdbaafb94e99bc99b567357ab4c157 (diff) |
Merge branch 'master' of github.com:stefan-niedermann/nextcloud-deck
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/persistence')
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DeckDatabase.java | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DeckDatabase.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DeckDatabase.java index cb8bb558f..d2106f03b 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DeckDatabase.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DeckDatabase.java @@ -14,6 +14,7 @@ import androidx.room.TypeConverters; import androidx.room.migration.Migration; import androidx.sqlite.db.SupportSQLiteDatabase; +import it.niedermann.android.util.ColorUtil; import it.niedermann.nextcloud.deck.DeckLog; import it.niedermann.nextcloud.deck.api.LastSyncUtil; import it.niedermann.nextcloud.deck.model.AccessControl; @@ -66,7 +67,6 @@ import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.projects.Oc import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.projects.OcsProjectResourceDao; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.widgets.SingleCardWidgetModelDao; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.widgets.StackWidgetModelDao; -import it.niedermann.nextcloud.deck.util.ColorUtil; @Database( entities = { @@ -275,9 +275,9 @@ public abstract class DeckDatabase extends RoomDatabase { String suffix = "_new"; { String tableName = "Account"; - database.execSQL("CREATE TABLE `"+tableName+suffix+"` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` TEXT NOT NULL, `userName` TEXT NOT NULL, `url` TEXT NOT NULL, " + + database.execSQL("CREATE TABLE `" + tableName + suffix + "` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` TEXT NOT NULL, `userName` TEXT NOT NULL, `url` TEXT NOT NULL, " + "`color` INTEGER NOT NULL DEFAULT 0, `textColor` INTEGER NOT NULL DEFAULT 0, `serverDeckVersion` TEXT NOT NULL DEFAULT '0.6.4', `maintenanceEnabled` INTEGER NOT NULL DEFAULT 0, `etag` TEXT)"); - Cursor cursor = database.query("select * from `"+tableName+"`"); + Cursor cursor = database.query("select * from `" + tableName + "`"); while (cursor.moveToNext()) { String colorAsString1 = cursor.getString(4); // color String colorAsString2 = cursor.getString(5); // textColor @@ -285,44 +285,44 @@ public abstract class DeckDatabase extends RoomDatabase { @ColorInt Integer color1 = null; @ColorInt Integer color2 = null; try { - color1 = Color.parseColor(ColorUtil.formatColorToParsableHexString(colorAsString1)); - color2 = Color.parseColor(ColorUtil.formatColorToParsableHexString(colorAsString2)); + color1 = Color.parseColor(ColorUtil.INSTANCE.formatColorToParsableHexString(colorAsString1)); + color2 = Color.parseColor(ColorUtil.INSTANCE.formatColorToParsableHexString(colorAsString2)); } catch (Exception e) { color1 = Color.GRAY; color2 = Color.GRAY; } - database.execSQL("Insert into `"+tableName+suffix+"` VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", new Object[] { + database.execSQL("Insert into `" + tableName + suffix + "` VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", new Object[]{ cursor.getLong(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), - color1, color2, cursor.getString(6), cursor.getInt(7), cursor.getString(8)}); + color1, color2, cursor.getString(6), cursor.getInt(7), cursor.getString(8)}); } - database.execSQL("DROP TABLE `"+ tableName +"`"); - database.execSQL("ALTER TABLE `"+tableName+suffix+"` RENAME TO `"+tableName+"`"); - database.execSQL("CREATE UNIQUE INDEX `index_Account_name` ON `"+tableName+"` (`name`)"); - database.execSQL("UPDATE SQLITE_SEQUENCE SET seq = (select max(id) from "+tableName+") WHERE name = ?", new Object[] {tableName}); + database.execSQL("DROP TABLE `" + tableName + "`"); + database.execSQL("ALTER TABLE `" + tableName + suffix + "` RENAME TO `" + tableName + "`"); + database.execSQL("CREATE UNIQUE INDEX `index_Account_name` ON `" + tableName + "` (`name`)"); + database.execSQL("UPDATE SQLITE_SEQUENCE SET seq = (select max(id) from " + tableName + ") WHERE name = ?", new Object[]{tableName}); } { String tableName = "Board"; - database.execSQL("CREATE TABLE `"+tableName+suffix+"` (`localId` INTEGER PRIMARY KEY AUTOINCREMENT, `accountId` INTEGER NOT NULL, `id` INTEGER, `status` INTEGER NOT NULL, " + + database.execSQL("CREATE TABLE `" + tableName + suffix + "` (`localId` INTEGER PRIMARY KEY AUTOINCREMENT, `accountId` INTEGER NOT NULL, `id` INTEGER, `status` INTEGER NOT NULL, " + "`lastModified` INTEGER, `lastModifiedLocal` INTEGER, `title` TEXT, `ownerId` INTEGER NOT NULL, `color` INTEGER, " + "`archived` INTEGER NOT NULL, `shared` INTEGER NOT NULL, `deletedAt` INTEGER, `permissionRead` INTEGER NOT NULL, " + "`permissionEdit` INTEGER NOT NULL, `permissionManage` INTEGER NOT NULL, `permissionShare` INTEGER NOT NULL, " + "FOREIGN KEY(`ownerId`) REFERENCES `User`(`localId`) ON UPDATE NO ACTION ON DELETE SET NULL )"); - Cursor cursor = database.query("select * from `"+tableName+"`"); + Cursor cursor = database.query("select * from `" + tableName + "`"); while (cursor.moveToNext()) { String colorAsString1 = cursor.getString(8); // color @ColorInt Integer color1 = null; try { - color1 = Color.parseColor(ColorUtil.formatColorToParsableHexString(colorAsString1)); + color1 = Color.parseColor(ColorUtil.INSTANCE.formatColorToParsableHexString(colorAsString1)); } catch (Exception e) { color1 = Color.GRAY; } - database.execSQL("Insert into `"+tableName+suffix+"` VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new Object[] { + database.execSQL("Insert into `" + tableName + suffix + "` VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new Object[]{ cursor.getLong(0), cursor.getLong(1), cursor.getLong(2), cursor.getInt(3), - cursor.getLong(4), cursor.getLong(5), cursor.getString(6), cursor.getLong(7) , color1, + cursor.getLong(4), cursor.getLong(5), cursor.getString(6), cursor.getLong(7), color1, cursor.getInt(9), cursor.getInt(10), cursor.getInt(11), cursor.getInt(12), cursor.getInt(13), cursor.getInt(14), cursor.getInt(15) }); @@ -330,46 +330,46 @@ public abstract class DeckDatabase extends RoomDatabase { } - database.execSQL("DROP TABLE `"+ tableName +"`"); - database.execSQL("ALTER TABLE `"+tableName+suffix+"` RENAME TO `"+tableName+"`"); - database.execSQL("CREATE INDEX `index_Board_accountId` ON `"+tableName+"` (`accountId`)"); - database.execSQL("CREATE UNIQUE INDEX `index_Board_accountId_id` ON `"+tableName+"` (`accountId`, `id`)"); - database.execSQL("CREATE INDEX `index_Board_id` ON `"+tableName+"` (`id`)"); - database.execSQL("CREATE INDEX `index_Board_ownerId` ON `"+tableName+"` (`ownerId`)"); - database.execSQL("CREATE INDEX `index_Board_lastModifiedLocal` ON `"+tableName+"` (`lastModifiedLocal`)"); - database.execSQL("UPDATE SQLITE_SEQUENCE SET seq = (select max(id) from "+tableName+") WHERE name = ?", new Object[] {tableName}); + database.execSQL("DROP TABLE `" + tableName + "`"); + database.execSQL("ALTER TABLE `" + tableName + suffix + "` RENAME TO `" + tableName + "`"); + database.execSQL("CREATE INDEX `index_Board_accountId` ON `" + tableName + "` (`accountId`)"); + database.execSQL("CREATE UNIQUE INDEX `index_Board_accountId_id` ON `" + tableName + "` (`accountId`, `id`)"); + database.execSQL("CREATE INDEX `index_Board_id` ON `" + tableName + "` (`id`)"); + database.execSQL("CREATE INDEX `index_Board_ownerId` ON `" + tableName + "` (`ownerId`)"); + database.execSQL("CREATE INDEX `index_Board_lastModifiedLocal` ON `" + tableName + "` (`lastModifiedLocal`)"); + database.execSQL("UPDATE SQLITE_SEQUENCE SET seq = (select max(id) from " + tableName + ") WHERE name = ?", new Object[]{tableName}); } { String tableName = "Label"; - database.execSQL("CREATE TABLE `"+tableName+suffix+"` (`localId` INTEGER PRIMARY KEY AUTOINCREMENT, `accountId` INTEGER NOT NULL, `id` INTEGER, `status` INTEGER NOT NULL, " + + database.execSQL("CREATE TABLE `" + tableName + suffix + "` (`localId` INTEGER PRIMARY KEY AUTOINCREMENT, `accountId` INTEGER NOT NULL, `id` INTEGER, `status` INTEGER NOT NULL, " + "`lastModified` INTEGER, `lastModifiedLocal` INTEGER, `title` TEXT, `color` INTEGER NOT NULL DEFAULT 0, `boardId` INTEGER NOT NULL, " + "FOREIGN KEY(`boardId`) REFERENCES `Board`(`localId`) ON UPDATE NO ACTION ON DELETE CASCADE )"); - Cursor cursor = database.query("select * from `"+tableName+"`"); + Cursor cursor = database.query("select * from `" + tableName + "`"); while (cursor.moveToNext()) { String colorAsString1 = cursor.getString(7); // color @ColorInt Integer color1 = null; try { - color1 = Color.parseColor(ColorUtil.formatColorToParsableHexString(colorAsString1)); + color1 = Color.parseColor(ColorUtil.INSTANCE.formatColorToParsableHexString(colorAsString1)); } catch (Exception e) { color1 = Color.GRAY; } - database.execSQL("Insert into `"+tableName+suffix+"` VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", new Object[] { + database.execSQL("Insert into `" + tableName + suffix + "` VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", new Object[]{ cursor.getLong(0), cursor.getLong(1), cursor.getLong(2), cursor.getInt(3), cursor.getLong(4), cursor.getLong(5), cursor.getString(6), color1, cursor.getLong(8)}); } - database.execSQL("DROP TABLE `"+ tableName +"`"); - database.execSQL("ALTER TABLE `"+tableName+suffix+"` RENAME TO `"+tableName+"`"); - database.execSQL("CREATE UNIQUE INDEX `index_Label_accountId_id` ON `"+tableName+"` (`accountId`, `id`)"); - database.execSQL("CREATE INDEX `index_Label_boardId` ON `"+tableName+"` (`boardId`)"); - database.execSQL("CREATE INDEX `index_Label_accountId` ON `"+tableName+"` (`accountId`)"); - database.execSQL("CREATE UNIQUE INDEX `idx_label_title_unique` ON `"+tableName+"` (`boardId`, `title`)"); - database.execSQL("CREATE INDEX `index_Label_id` ON `"+tableName+"` (`id`)"); - database.execSQL("CREATE INDEX `index_Label_lastModifiedLocal` ON `"+tableName+"` (`lastModifiedLocal`)"); - database.execSQL("UPDATE SQLITE_SEQUENCE SET seq = (select max(id) from "+tableName+") WHERE name = ?", new Object[] {tableName}); + database.execSQL("DROP TABLE `" + tableName + "`"); + database.execSQL("ALTER TABLE `" + tableName + suffix + "` RENAME TO `" + tableName + "`"); + database.execSQL("CREATE UNIQUE INDEX `index_Label_accountId_id` ON `" + tableName + "` (`accountId`, `id`)"); + database.execSQL("CREATE INDEX `index_Label_boardId` ON `" + tableName + "` (`boardId`)"); + database.execSQL("CREATE INDEX `index_Label_accountId` ON `" + tableName + "` (`accountId`)"); + database.execSQL("CREATE UNIQUE INDEX `idx_label_title_unique` ON `" + tableName + "` (`boardId`, `title`)"); + database.execSQL("CREATE INDEX `index_Label_id` ON `" + tableName + "` (`id`)"); + database.execSQL("CREATE INDEX `index_Label_lastModifiedLocal` ON `" + tableName + "` (`lastModifiedLocal`)"); + database.execSQL("UPDATE SQLITE_SEQUENCE SET seq = (select max(id) from " + tableName + ") WHERE name = ?", new Object[]{tableName}); } } }; |