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