Skip to content

Commit

Permalink
reorg of MapDBStore to permit views
Browse files Browse the repository at this point in the history
  • Loading branch information
sanity committed Sep 26, 2020
1 parent 3e4f19d commit a246fe4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'kweb'
version '0.4.3'
version '0.4.4'

buildscript {
ext.kotlin_version = '1.4.0'
Expand Down Expand Up @@ -54,6 +54,7 @@ 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"
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/kweb/shoebox/Shoebox.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import kweb.shoebox.View.VerifyBehavior
import kweb.shoebox.View.VerifyBehavior.BLOCKING_VERIFY
import kweb.shoebox.stores.DirectoryStore
import kweb.shoebox.stores.LmdbStore
import kweb.shoebox.stores.MapDBStore
import kweb.shoebox.stores.MemoryStore
import java.nio.file.Path
import java.util.concurrent.ConcurrentHashMap
Expand Down Expand Up @@ -163,6 +164,7 @@ class Shoebox<T : Any>(val store: Store<T>) {
is MemoryStore<T> -> MemoryStore<Reference>()
is DirectoryStore<T> ->
DirectoryStore(store.directory.parent.resolve("${store.directory.fileName}-$name-view"), Reference.serializer())
is MapDBStore<T> -> MapDBStore(store.db, "${store.name}-$name-view", Reference.serializer())
is LmdbStore<T> -> LmdbStore("${store.name}-$name-view", Reference.serializer())
else -> throw RuntimeException("Shoebox doesn't currently support creating a view for store type ${store::class.simpleName}")
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/kweb/shoebox/stores/LmdbStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ val defaultGson: Gson = Converters.registerAll(GsonBuilder()).let {
it.registerTypeAdapter(object : TypeToken<Duration>() {}.type, DurationConverter())
}.create()
*/
@Deprecated("Should be used via MapStore")
@Deprecated("Use MapDBStore instead")
class LmdbStore<T : Any>(val name: String, private val kSerializer: KSerializer<T>) : Store<T> {

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ import kotlinx.serialization.KSerializer
import kotlinx.serialization.protobuf.ProtoBuf
import kweb.shoebox.KeyValue
import kweb.shoebox.Store
import org.mapdb.DB
import org.mapdb.Serializer

/**
* Created by ian on 3/22/17.
*/
@ExperimentalSerializationApi
class MapStore<T : Any>(private val map : MutableMap<String, ByteArray>, private val serializer: KSerializer<T>) : Store<T> {
class MapDBStore<T : Any>(val db : DB, val name : String, val serializer: KSerializer<T>) : Store<T> {

private val map = db.hashMap(name).keySerializer(Serializer.STRING).valueSerializer(Serializer.BYTE_ARRAY).create()

override val entries: Iterable<KeyValue<T>>
get() = map.map { (k, v) ->
Expand Down

0 comments on commit a246fe4

Please sign in to comment.