All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.org.kodein.db.impl.AbstractDBFactory.kt Maven / Gradle / Ivy

The newest version!
package org.kodein.db.impl

import org.kodein.db.*
import org.kodein.db.impl.model.cache.defaultCacheCopyMaxSize
import org.kodein.db.impl.model.cache.defaultCacheSize
import org.kodein.db.impl.model.cache.middleware
import org.kodein.db.model.ModelDB
import org.kodein.db.model.cache.ModelCache

public abstract class AbstractDBFactory : DBFactory {

    protected abstract val mdbFactory: DBFactory

    override fun open(path: String, vararg options: Options.Open): DB {
        val mdbOptions = if (options() == null) {
            val middleware = ModelCache.middleware(
                maxSize = options()?.maxSize ?: defaultCacheSize,
                copyMaxSize =  options()?.maxSize ?: defaultCacheCopyMaxSize(),
                hashCodeImmutabilityChecks = options() == null
            )
            arrayOf(Middleware.Model(middleware)) + options
        } else {
            options
        }

        val mdb = mdbFactory.open(path, *mdbOptions)

        return DBImpl(mdb)
    }

    override fun destroy(path: String, vararg options: Options.Open) {
        mdbFactory.destroy(path, *options)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy