Skip to content

Commit

Permalink
Refactored "SQLMappingFunction"
Browse files Browse the repository at this point in the history
*This commit is related to issue #529 [1]*

[1] #529
  • Loading branch information
JaniruTEC committed Apr 13, 2024
1 parent eae6c03 commit 35b4e00
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -188,4 +188,10 @@ fun SupportSQLiteOpenHelper.Factory.asMapped(mappingFunction: SQLMappingFunction
return MappingSupportSQLiteOpenHelperFactory(this, mappingFunction)
}

interface SQLMappingFunction : (String) -> String
interface SQLMappingFunction {

fun map(sql: String): String

fun mapWhereClause(whereClause: String?): String?

}

0 comments on commit 35b4e00

Please sign in to comment.