Skip to content

Commit

Permalink
Clenup code, move more to common (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
illarionov authored Mar 19, 2024
1 parent 8ed6421 commit 2867a88
Show file tree
Hide file tree
Showing 21 changed files with 95 additions and 390 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import ru.pixnews.wasm.sqlite.open.helper.dsl.WasmSqliteOpenHelperFactoryConfigB
import ru.pixnews.wasm.sqlite.open.helper.embedder.SqliteEmbedder
import ru.pixnews.wasm.sqlite.open.helper.embedder.SqliteEmbedderConfig
import ru.pixnews.wasm.sqlite.open.helper.embedder.WasmSqliteCommonConfig
import ru.pixnews.wasm.sqlite.open.helper.internal.CloseGuard
import ru.pixnews.wasm.sqlite.open.helper.internal.CloseGuard.Reporter
import ru.pixnews.wasm.sqlite.open.helper.path.JvmDatabasePathResolver

/**
Expand All @@ -28,6 +30,9 @@ public fun <E : SqliteEmbedderConfig> WasmSqliteOpenHelperFactory(
val commonConfig = object : WasmSqliteCommonConfig {
override val logger: Logger = config.logger
}

setupCloseGuard(config.logger)

return WasmSqliteOpenHelperFactory(
pathResolver = config.pathResolver,
defaultLocale = config.locale,
Expand All @@ -37,3 +42,10 @@ public fun <E : SqliteEmbedderConfig> WasmSqliteOpenHelperFactory(
configurationOptions = config.configurationOptions,
)
}

private fun setupCloseGuard(rootLogger: Logger) {
val logger = rootLogger.withTag("SQLite")
CloseGuard.reporter = Reporter { message, allocationSite ->
logger.w(allocationSite, message::toString)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ internal class SQLiteConnectionPool<CP : Sqlite3ConnectionPtr, SP : Sqlite3State
val foreignKeyModeChanged = configuration.foreignKeyConstraintsEnabled !=
this.configuration.foreignKeyConstraintsEnabled
if (foreignKeyModeChanged &&
// Foreign key constraints can only be changed if there are no transactions
// in progress. To make this clear, we throw an exception if there are
// any acquired connections.
// Foreign key constraints can only be changed if there are no transactions
// in progress. To make this clear, we throw an exception if there are
// any acquired connections.
acquiredConnections.isNotEmpty()
) {
throw IllegalStateException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,17 @@ internal class SQLiteCursor(
/**
* The cursor window owned by this cursor.
*/
var window: CursorWindow? = null
private var window: CursorWindow? = null
/**
* Sets a new cursor window for the cursor to use.
*
*
* The cursor takes ownership of the provided cursor window; the cursor window
* will be closed when the cursor is closed or when the cursor adopts a new
* cursor window.
*
*
* If the cursor previously had a cursor window, then it is closed when the
* new cursor window is assigned.
*
*
* @param newWindow The new cursor window, typically a remote cursor window.
*/
set(newWindow) {
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 2867a88

Please sign in to comment.