From 35b4e00177f80d7e72cc160b707db3c1e45e97b2 Mon Sep 17 00:00:00 2001 From: JaniruTEC <52893617+JaniruTEC@users.noreply.github.com> Date: Thu, 14 Mar 2024 17:27:48 +0100 Subject: [PATCH] Refactored "SQLMappingFunction" *This commit is related to issue #529 [1]* [1] https://github.com/cryptomator/android/issues/529 --- .../org/cryptomator/data/db/SQLiteCacheControl.kt | 6 +++++- .../db/sqlmapping/MappingSupportSQLiteDatabase.kt | 14 ++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/data/src/main/java/org/cryptomator/data/db/SQLiteCacheControl.kt b/data/src/main/java/org/cryptomator/data/db/SQLiteCacheControl.kt index fdad1f605..fd540bafe 100644 --- a/data/src/main/java/org/cryptomator/data/db/SQLiteCacheControl.kt +++ b/data/src/main/java/org/cryptomator/data/db/SQLiteCacheControl.kt @@ -12,9 +12,13 @@ object SQLiteCacheControl { private val newIdentifier: String get() = UUID.randomUUID().toString() - override fun invoke(sql: String): String { + override fun map(sql: String): String { return "$sql -- $newIdentifier" } + + override fun mapWhereClause(whereClause: String?): String { + return map(whereClause ?: "1 = 1") + } } fun SupportSQLiteOpenHelper.Factory.asCacheControlled(): SupportSQLiteOpenHelper.Factory = asMapped(RandomUUIDMapping) diff --git a/data/src/main/java/org/cryptomator/data/db/sqlmapping/MappingSupportSQLiteDatabase.kt b/data/src/main/java/org/cryptomator/data/db/sqlmapping/MappingSupportSQLiteDatabase.kt index 0eba2530c..88b8b1401 100644 --- a/data/src/main/java/org/cryptomator/data/db/sqlmapping/MappingSupportSQLiteDatabase.kt +++ b/data/src/main/java/org/cryptomator/data/db/sqlmapping/MappingSupportSQLiteDatabase.kt @@ -72,18 +72,18 @@ internal class MappingSupportSQLiteDatabase( private val helper = AOP_SQLiteDatabase() private fun map(sql: String): String { - return mappingFunction(sql) + return mappingFunction.map(sql) } private fun map(query: SupportSQLiteQuery): SupportSQLiteQuery { return MappingSupportSQLiteQuery(query) } - private fun mapWhereClause(whereClause: String?): String { + private fun mapWhereClause(whereClause: String?): String? { if (whereClause != null && whereClause.isBlank()) { throw IllegalArgumentException() } - return map(whereClause ?: "1 = 1") + return mappingFunction.mapWhereClause(whereClause) } private inner class MappingSupportSQLiteStatement( @@ -188,4 +188,10 @@ fun SupportSQLiteOpenHelper.Factory.asMapped(mappingFunction: SQLMappingFunction return MappingSupportSQLiteOpenHelperFactory(this, mappingFunction) } -interface SQLMappingFunction : (String) -> String \ No newline at end of file +interface SQLMappingFunction { + + fun map(sql: String): String + + fun mapWhereClause(whereClause: String?): String? + +} \ No newline at end of file