From 7d9a69eec3b4c415387053dc77ff50bac3543e96 Mon Sep 17 00:00:00 2001 From: Ian Clarke Date: Fri, 25 Sep 2020 22:56:20 -0500 Subject: [PATCH] support MapStore, which any map can be used with (eg. MapDB) --- build.gradle | 3 +-- src/main/kotlin/kweb/shoebox/stores/LmdbStore.kt | 1 + .../shoebox/stores/{MapDBStore.kt => MapStore.kt} | 13 +++---------- 3 files changed, 5 insertions(+), 12 deletions(-) rename src/main/kotlin/kweb/shoebox/stores/{MapDBStore.kt => MapStore.kt} (72%) diff --git a/build.gradle b/build.gradle index bfe8ebd..dd2ee4f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'kweb' -version '0.4.1' +version '0.4.2' buildscript { ext.kotlin_version = '1.4.0' @@ -54,7 +54,6 @@ dependencies { implementation 'org.lmdbjava:lmdbjava:0.7.0' compile "org.jetbrains.kotlinx:kotlinx-serialization-core:1.0.0-RC" implementation "org.jetbrains.kotlinx:kotlinx-serialization-protobuf:1.0.0-RC" - implementation "org.mapdb:mapdb:3.0.8" testImplementation "io.kotest:kotest-runner-junit5-jvm:4.2.3" testImplementation "io.kotest:kotest-assertions-core-jvm:4.2.3" diff --git a/src/main/kotlin/kweb/shoebox/stores/LmdbStore.kt b/src/main/kotlin/kweb/shoebox/stores/LmdbStore.kt index 15f6f2d..74ec488 100644 --- a/src/main/kotlin/kweb/shoebox/stores/LmdbStore.kt +++ b/src/main/kotlin/kweb/shoebox/stores/LmdbStore.kt @@ -20,6 +20,7 @@ val defaultGson: Gson = Converters.registerAll(GsonBuilder()).let { it.registerTypeAdapter(object : TypeToken() {}.type, DurationConverter()) }.create() */ +@Deprecated("Should be used via MapStore") class LmdbStore(val name: String, private val kSerializer: KSerializer) : Store { companion object { diff --git a/src/main/kotlin/kweb/shoebox/stores/MapDBStore.kt b/src/main/kotlin/kweb/shoebox/stores/MapStore.kt similarity index 72% rename from src/main/kotlin/kweb/shoebox/stores/MapDBStore.kt rename to src/main/kotlin/kweb/shoebox/stores/MapStore.kt index e18983d..d50b698 100644 --- a/src/main/kotlin/kweb/shoebox/stores/MapDBStore.kt +++ b/src/main/kotlin/kweb/shoebox/stores/MapStore.kt @@ -5,18 +5,12 @@ import kotlinx.serialization.KSerializer import kotlinx.serialization.protobuf.ProtoBuf import kweb.shoebox.KeyValue import kweb.shoebox.Store -import org.mapdb.DB -import org.mapdb.HTreeMap -import org.mapdb.Serializer /** * Created by ian on 3/22/17. */ @ExperimentalSerializationApi -class MapDBStore(private val db: DB, private val name: String, private val serializer: KSerializer) : Store { - private val map: HTreeMap = db - .hashMap(name, Serializer.STRING, Serializer.BYTE_ARRAY) - .createOrOpen() +class MapStore(private val map : MutableMap, private val name: String, private val serializer: KSerializer) : Store { override val entries: Iterable> get() = map.map { (k, v) -> @@ -33,7 +27,7 @@ class MapDBStore(private val db: DB, private val name: String, private } override fun get(key: String): T? { - val v = map.get(key) + val v = map[key] return if (v == null) { null } else { @@ -42,9 +36,8 @@ class MapDBStore(private val db: DB, private val name: String, private } override fun set(key: String, value: T): T? { - val v = map.get(key) + val v = map[key] map.set(key, ProtoBuf.encodeToByteArray(serializer, value)) - db.commit() return if (v == null) { null } else {