Skip to content

Commit

Permalink
Redefined logic of "MappingSupportSQLiteQuery"
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 35b4e00 commit 95eede5
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase
import androidx.sqlite.db.SupportSQLiteOpenHelper
import androidx.sqlite.db.SupportSQLiteQuery
import androidx.sqlite.db.SupportSQLiteStatement
import java.util.Collections
import timber.log.Timber

internal class MappingSupportSQLiteDatabase(
private val delegate: SupportSQLiteDatabase,
Expand Down Expand Up @@ -153,10 +153,18 @@ internal class MappingSupportSQLiteDatabase(
private val delegateQuery: SupportSQLiteQuery
) : SupportSQLiteQuery by delegateQuery {

private val mappedQueries: MutableMap<String, String> = Collections.synchronizedMap(mutableMapOf())
private val lock = Any()
private var called = false

private val _sql = map(delegateQuery.sql)
override val sql: String
get() = mappedQueries.computeIfAbsent(delegateQuery.sql) { map(it) }
get() = synchronized(lock) {
if (called) {
Timber.tag("MappingSupportSQLiteQuery").e("SQL queried twice")
}
called = true
return _sql
}
}
}

Expand Down

0 comments on commit 95eede5

Please sign in to comment.