Add: TODOs for (5/5 in replacing SQLite with Room)

This commit is contained in:
machiav3lli 2021-10-27 23:22:14 +02:00
parent d1c3454635
commit 7cbcbad40f

View File

@ -34,6 +34,7 @@ object Database {
private lateinit var db: SQLiteDatabase private lateinit var db: SQLiteDatabase
// not needed with Room
private interface Table { private interface Table {
val memory: Boolean val memory: Boolean
val innerName: String val innerName: String
@ -61,6 +62,7 @@ object Database {
} }
private object Schema { private object Schema {
// implemented
object Repository : Table { object Repository : Table {
const val ROW_ID = "_id" const val ROW_ID = "_id"
const val ROW_ENABLED = "enabled" const val ROW_ENABLED = "enabled"
@ -77,6 +79,7 @@ object Database {
""" """
} }
// implemented
object Product : Table { object Product : Table {
const val ROW_REPOSITORY_ID = "repository_id" const val ROW_REPOSITORY_ID = "repository_id"
const val ROW_PACKAGE_NAME = "package_name" const val ROW_PACKAGE_NAME = "package_name"
@ -111,6 +114,7 @@ object Database {
override val createIndex = ROW_PACKAGE_NAME override val createIndex = ROW_PACKAGE_NAME
} }
// implemented
object Category : Table { object Category : Table {
const val ROW_REPOSITORY_ID = "repository_id" const val ROW_REPOSITORY_ID = "repository_id"
const val ROW_PACKAGE_NAME = "package_name" const val ROW_PACKAGE_NAME = "package_name"
@ -127,6 +131,7 @@ object Database {
override val createIndex = "$ROW_PACKAGE_NAME, $ROW_NAME" override val createIndex = "$ROW_PACKAGE_NAME, $ROW_NAME"
} }
// implemented
object Installed : Table { object Installed : Table {
const val ROW_PACKAGE_NAME = "package_name" const val ROW_PACKAGE_NAME = "package_name"
const val ROW_VERSION = "version" const val ROW_VERSION = "version"
@ -143,6 +148,7 @@ object Database {
""" """
} }
// implemented
object Lock : Table { object Lock : Table {
const val ROW_PACKAGE_NAME = "package_name" const val ROW_PACKAGE_NAME = "package_name"
const val ROW_VERSION_CODE = "version_code" const val ROW_VERSION_CODE = "version_code"
@ -155,12 +161,14 @@ object Database {
""" """
} }
// TODO find a class to include them as constants
object Synthetic { object Synthetic {
const val ROW_CAN_UPDATE = "can_update" const val ROW_CAN_UPDATE = "can_update"
const val ROW_MATCH_RANK = "match_rank" const val ROW_MATCH_RANK = "match_rank"
} }
} }
// not needed remove after migration
private class Helper(context: Context) : SQLiteOpenHelper(context, "droidify", null, 1) { private class Helper(context: Context) : SQLiteOpenHelper(context, "droidify", null, 1) {
var created = false var created = false
private set private set
@ -198,6 +206,7 @@ object Database {
} }
} }
// not needed remove after migration
private fun handleTables(db: SQLiteDatabase, recreate: Boolean, vararg tables: Table): Boolean { private fun handleTables(db: SQLiteDatabase, recreate: Boolean, vararg tables: Table): Boolean {
val shouldRecreate = recreate || tables.any { val shouldRecreate = recreate || tables.any {
val sql = db.query( val sql = db.query(
@ -220,6 +229,7 @@ object Database {
} }
} }
// not needed remove after migration
private fun handleIndexes(db: SQLiteDatabase, vararg tables: Table) { private fun handleIndexes(db: SQLiteDatabase, vararg tables: Table) {
val shouldVacuum = tables.map { val shouldVacuum = tables.map {
val sqls = db.query( val sqls = db.query(
@ -248,6 +258,7 @@ object Database {
} }
} }
// TODO not needed, remove after migration
private fun dropOldTables(db: SQLiteDatabase, vararg neededTables: Table) { private fun dropOldTables(db: SQLiteDatabase, vararg neededTables: Table) {
val tables = db.query( val tables = db.query(
"sqlite_master", columns = arrayOf("name"), "sqlite_master", columns = arrayOf("name"),
@ -274,6 +285,8 @@ object Database {
private val observers = mutableMapOf<Subject, MutableSet<() -> Unit>>() private val observers = mutableMapOf<Subject, MutableSet<() -> Unit>>()
// TODO not needed remove after migration (replaced by LiveData)
private fun dataObservable(subject: Subject): (Boolean, () -> Unit) -> Unit = private fun dataObservable(subject: Subject): (Boolean, () -> Unit) -> Unit =
{ register, observer -> { register, observer ->
synchronized(observers) { synchronized(observers) {
@ -290,6 +303,7 @@ object Database {
} }
} }
// TODO not needed remove after migration (replaced by LiveData)
fun observable(subject: Subject): Observable<Unit> { fun observable(subject: Subject): Observable<Unit> {
return Observable.create { return Observable.create {
val callback: () -> Unit = { it.onNext(Unit) } val callback: () -> Unit = { it.onNext(Unit) }
@ -299,12 +313,14 @@ object Database {
} }
} }
// TODO not needed remove after migration (replaced by LiveData)
private fun notifyChanged(vararg subjects: Subject) { private fun notifyChanged(vararg subjects: Subject) {
synchronized(observers) { synchronized(observers) {
subjects.asSequence().mapNotNull { observers[it] }.flatten().forEach { it() } subjects.asSequence().mapNotNull { observers[it] }.flatten().forEach { it() }
} }
} }
// TODO Done through inserts/replace of DAOs, only temporary still not finished
private fun SQLiteDatabase.insertOrReplace( private fun SQLiteDatabase.insertOrReplace(
replace: Boolean, replace: Boolean,
table: String, table: String,
@ -350,6 +366,7 @@ object Database {
return outputStream.toByteArray() return outputStream.toByteArray()
} }
// Partially done, only
object RepositoryAdapter { object RepositoryAdapter {
// Done in put // Done in put
internal fun putWithoutNotification(repository: Repository, shouldReplace: Boolean): Long { internal fun putWithoutNotification(repository: Repository, shouldReplace: Boolean): Long {
@ -498,7 +515,7 @@ object Database {
.use { it.firstOrNull()?.getInt(0) ?: 0 } .use { it.firstOrNull()?.getInt(0) ?: 0 }
} }
// Complex left to wiring phase // TODO Too complex left to wiring phase
fun query( fun query(
installed: Boolean, updates: Boolean, searchQuery: String, installed: Boolean, updates: Boolean, searchQuery: String,
section: ProductItem.Section, order: ProductItem.Order, signal: CancellationSignal? section: ProductItem.Section, order: ProductItem.Order, signal: CancellationSignal?
@ -596,7 +613,7 @@ object Database {
} }
} }
// Unnecessary with Room // TODO should be taken care of with extra functions that build on Room's queries
fun transformItem(cursor: Cursor): ProductItem { fun transformItem(cursor: Cursor): ProductItem {
return cursor.getBlob(cursor.getColumnIndex(Schema.Product.ROW_DATA_ITEM)) return cursor.getBlob(cursor.getColumnIndex(Schema.Product.ROW_DATA_ITEM))
.jsonParse { .jsonParse {
@ -623,6 +640,7 @@ object Database {
} }
} }
// Done
object CategoryAdapter { object CategoryAdapter {
// Done // Done
fun getAll(signal: CancellationSignal?): Set<String> { fun getAll(signal: CancellationSignal?): Set<String> {
@ -642,6 +660,7 @@ object Database {
} }
} }
// Done
object InstalledAdapter { object InstalledAdapter {
// Done // Done
fun get(packageName: String, signal: CancellationSignal?): InstalledItem? { fun get(packageName: String, signal: CancellationSignal?): InstalledItem? {
@ -707,6 +726,7 @@ object Database {
} }
} }
// Done with some changes in DAOS
object LockAdapter { object LockAdapter {
// Done in insert (Lock object instead of pair) // Done in insert (Lock object instead of pair)
private fun put(lock: Pair<String, Long>, notify: Boolean) { private fun put(lock: Pair<String, Long>, notify: Boolean) {