Skip to content

Commit

Permalink
[DB] openhelper is lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
agrosner committed Feb 18, 2021
1 parent a4b3680 commit 5ad4d86
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions lib/src/main/kotlin/com/dbflow5/config/DBFlowDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,20 @@ abstract class DBFlowDatabase : DatabaseWrapper {

internal var writeAheadLoggingEnabled = false

val openHelper: OpenHelper
@Synchronized get() {
var helper = _openHelper
if (helper == null) {
val config = FlowManager.getConfig().databaseConfigMap[associatedDatabaseClassFile]
helper = if (config?.openHelperCreator != null) {
config.openHelperCreator.createHelper(this, internalCallback)
} else {
AndroidSQLiteOpenHelper(FlowManager.context, this, internalCallback)
}
onOpenWithConfig(config, helper)
val openHelper: OpenHelper by lazy {
var helper = _openHelper
if (helper == null) {
val config = FlowManager.getConfig().databaseConfigMap[associatedDatabaseClassFile]
helper = if (config?.openHelperCreator != null) {
config.openHelperCreator.createHelper(this, internalCallback)
} else {
AndroidSQLiteOpenHelper(FlowManager.context, this, internalCallback)
}
_openHelper = helper
return helper
onOpenWithConfig(config, helper)
}
_openHelper = helper
return@lazy helper
}

private fun onOpenWithConfig(config: DatabaseConfig?, helper: OpenHelper) {
helper.performRestoreFromBackup()
Expand Down

0 comments on commit 5ad4d86

Please sign in to comment.