当前位置: 首页>>代码示例>>Scala>>正文


Scala DB类代码示例

本文整理汇总了Scala中org.iq80.leveldb.DB的典型用法代码示例。如果您正苦于以下问题:Scala DB类的具体用法?Scala DB怎么用?Scala DB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DB类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: db_utils

//设置package包名称以及导入依赖的类
package bycicle_tool

import org.iq80.leveldb.{DB, _}
import org.fusesource.leveldbjni.JniDBFactory._
import java.io._

import utils._

//??????????????????????????????????????????????????????????????????????

object db_utils {

    private lazy val _db : DB = {
        sConfig.onCloseCallbacks += {() => if (_db != null) _db.close() }
        openDb()
    }

    //----------------------------------------------------------------------

    def openDb() : DB = {
        val options = new Options()
        options.createIfMissing(true)

        val db = factory.open(
            new File(sConfig.sDBDirPath),
            options
        )

        if (db == null) {
            exitWithError("Con't open build database'")
        }

        return db
    }

    //----------------------------------------------------------------------

    def checkModified(path : String) : Boolean = {
        val file = new File(path)
        if (!file.exists()) return true

        val fileModifiedKey = file.getCanonicalPath() + "_lastModified"
        val lastModifiedBytes = _db.get(
            bytes(fileModifiedKey),
            new ReadOptions()
        )
        if (lastModifiedBytes == null ) {
            return true
        } else {
            val lmodDB = new String(lastModifiedBytes).toLong
            val modCur = recursiveLatestModified(file)

            System.out.println(s"$path saved last modify: $lmodDB, current modify date: $modCur")

            return modCur > lmodDB
        }
    }

    //----------------------------------------------------------------------
} 
开发者ID:gleyba,项目名称:mobile-tools,代码行数:61,代码来源:db.scala

示例2: LevelDBDataSource

//设置package包名称以及导入依赖的类
package io.iohk.ethereum.db.dataSource

import java.io.File

import io.iohk.ethereum.utils.Config
import org.iq80.leveldb.{DB, Options, WriteOptions}
import org.iq80.leveldb.impl.{Iq80DBFactory, WriteBatchImpl}


class LevelDBDataSource(
                         private var db: DB,
                         private val levelDbConfig: LevelDbConfig
                       )
  extends DataSource {

  
  override def destroy(): Unit = {
    try {
      close()
    } finally {
      Iq80DBFactory.factory.destroy(new File(levelDbConfig.path), null) // Options are not being used ¯\_(?)_/¯
    }
  }
}

trait LevelDbConfig {
  val createIfMissing: Boolean
  val paranoidChecks: Boolean
  val verifyChecksums: Boolean
  val path: String
}

object LevelDBDataSource {

  private def createDB(levelDbConfig: LevelDbConfig): DB = {
    import levelDbConfig._

    val options = new Options()
      .createIfMissing(createIfMissing)
      .paranoidChecks(paranoidChecks) // raise an error as soon as it detects an internal corruption
      .verifyChecksums(verifyChecksums) // force checksum verification of all data that is read from the file system on behalf of a particular read

    Iq80DBFactory.factory.open(new File(path), options)
  }

  def apply(levelDbConfig: LevelDbConfig): LevelDBDataSource = {
    new LevelDBDataSource(createDB(levelDbConfig), levelDbConfig)
  }
} 
开发者ID:input-output-hk,项目名称:etc-client,代码行数:50,代码来源:LevelDBDataSource.scala


注:本文中的org.iq80.leveldb.DB类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。