Skip to content

Commit

Permalink
Enable WAL for GeoPackage databases.
Browse files Browse the repository at this point in the history
  • Loading branch information
ComBatVision committed Jul 31, 2024
1 parent 01a54aa commit 6aec857
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package earth.worldwind.util.ormlite

import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteDatabase.*
import com.j256.ormlite.android.AndroidConnectionSource
import com.j256.ormlite.support.ConnectionSource

actual fun initConnection(pathName: String, readOnly: Boolean): ConnectionSource = AndroidConnectionSource(
SQLiteDatabase.openDatabase(pathName, null, if (readOnly) SQLiteDatabase.OPEN_READONLY else SQLiteDatabase.OPEN_READWRITE or SQLiteDatabase.CREATE_IF_NECESSARY)
openDatabase(
pathName, null,
if (readOnly) OPEN_READONLY else OPEN_READWRITE or CREATE_IF_NECESSARY or ENABLE_WRITE_AHEAD_LOGGING
).also { it.execSQL("PRAGMA synchronous = NORMAL") }
)
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ open class RenderContext {
inline fun <reified T : Drawable> getDrawablePool(): Pool<T> {
val key = T::class
// use SynchronizedPool; acquire and are release may be called in separate threads
return drawablePools[key] as Pool<T>? ?: SynchronizedPool<T>().also { drawablePools[key] = it }
return drawablePools[key] as? Pool<T> ?: SynchronizedPool<T>().also { drawablePools[key] = it }
}

fun offerPickedObject(pickedObject: PickedObject) { pickedObjects?.offerPickedObject(pickedObject) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,7 @@ open class GeoPackage(val pathName: String, val isReadOnly: Boolean = true) {
}

suspend fun readTilesDataSize(tableName: String) = withContext(Dispatchers.IO) {
val connection = connectionSource.getReadOnlyConnection(tableName)

try {
connection.queryForLong("SELECT SUM(LENGTH(tile_data)) FROM '$tableName'")
} catch (e: SQLException) {
Logger.logMessage(Logger.WARN, "GeoPackage", "readTilesDataSize", "Could not read tiles data size", e)
0L // Return zero if table does not exist
} finally {
connectionSource.releaseConnection(connection)
}
getTileUserDataDao(tableName).queryRawValue("SELECT SUM(LENGTH(tile_data)) FROM '$tableName'")
}

suspend fun readTileUserData(
Expand Down

0 comments on commit 6aec857

Please sign in to comment.