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


Scala BSONString类代码示例

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


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

示例1: StringMapFormatter

//设置package包名称以及导入依赖的类
package com.evojam.documents

import collection.JavaConversions._
import org.bson.Document
import reactivemongo.bson.{BSONString, BSONDocument, BSONDocumentReader, BSONDocumentWriter}

import com.evojam.driver.DocumentFormat

object StringMapFormatter {
  implicit object Handler extends BSONDocumentReader[Map[String, String]] with BSONDocumentWriter[Map[String, String]] {
    override def read(bson: BSONDocument): Map[String, String] =
      bson.elements.map({case (key, value) => (key, value.asInstanceOf[BSONString].as[String])}).toMap

    override def write(t: Map[String, String]): BSONDocument =
      BSONDocument(t.toStream.map({case (k,v) => (k, BSONString(v))}))
  }

  implicit object javaFmt extends DocumentFormat[Map[String, String]] {
    override def writes(a: Map[String, String]) = {
      val doc = new Document()
      a foreach {
        case (k, v) => doc.append(k, v)
      }
      doc
    }

    override def reads(doc: Document): Map[String, String] =
      doc.keySet().map(key => (key, doc.getString(key))).toMap
  }

} 
开发者ID:evojam,项目名称:mongo-drivers-benchmarks,代码行数:32,代码来源:StringMapFormatter.scala

示例2: IndexModel

//设置package包名称以及导入依赖的类
package it.agilelab.bigdata.wasp.core.models

import it.agilelab.bigdata.wasp.core.utils.ConfigManager
import reactivemongo.bson.{BSONDocument, BSONObjectID, BSONString}

object IndexModel {
  val readerType = "index"

  val schema_base_elastic =
    """
    "id_event":{"type":"double","index":"not_analyzed","store":"true","enabled":"true"},
    "source_name":{"type":"string","index":"not_analyzed","store":"true","enabled":"true"},
    "Index_name":{"type":"string","index":"not_analyzed","store":"true","enabled":"true"},
    "metric_name":{"type":"string","index":"not_analyzed","store":"true","enabled":"true"},
    "timestamp":{"type":"date","format":"date_time","index":"not_analyzed","store":"true","enabled":"true"},
    "latitude":{"type":"double","index":"not_analyzed","store":"true","enabled":"true"},
    "longitude":{"type":"double","index":"not_analyzed","store":"true","enabled":"true"},
    "value":{"type":"double","index":"not_analyzed","store":"true","enabled":"true"},
    "payload":{"type":"string","index":"not_analyzed","store":"true","enabled":"true"}
               """

  val schema_base_solr = """
                         { "name":"id_event", "type":"tdouble", "stored":true },
                         { "name":"source_name", "type":"string", "stored":true },
                         { "name":"topic_name", "type":"string","stored":true },
                         { "name":"metric_name", "type":"string","stored":true },
                         { "name":"timestamp", "type":"string","stored":true },
                         { "name":"latitude", "type":"tdouble", "stored":true },
                         { "name":"longitude", "type":"tdouble", "stored":true },
                         { "name":"value", "type":"string", "stored":true },
                         { "name":"payload", "type":"string", "stored":true }
                    """

  def normalizeName(basename: String) = s"${basename.toLowerCase}_index"
}

case class IndexModel(override val name: String,
                      creationTime: Long,
                      schema: Option[BSONDocument],
                      _id: Option[BSONObjectID] = None,
                      query: Option[String] = None,
                      numShards: Option[Int] = Some(1),
                      replicationFactor: Option[Int] = Some(1))
    extends Model {

  def resource = s"${ConfigManager.buildTimedName(name)}/$dataType"

  def collection = s"${ConfigManager.buildTimedName(name)}"

  def dataType =
    schema
      .map(
          bson =>
            bson.elements.headOption
              .getOrElse(("undefined", BSONString("undefined")))
              ._1)
      .getOrElse("undefined")

} 
开发者ID:agile-lab-dev,项目名称:wasp,代码行数:60,代码来源:IndexModel.scala

示例3: GalleryCommentEntity

//设置package包名称以及导入依赖的类
package com.rozilo.ussemble.models.db

import java.util.{Calendar, Date}

import com.rozilo.ussemble.models.api.GalleryCommentProtocol.GalleryComment
import io.circe.generic.JsonCodec
import reactivemongo.bson.{BSONDocument, BSONDocumentReader, BSONDocumentWriter, BSONObjectID, BSONString}
import io.circe._
import io.circe.generic.semiauto._


case class GalleryCommentEntity(id: BSONObjectID = BSONObjectID.generate,
                                body: String,
                                activity_id: BSONObjectID,
                                sender_id: BSONObjectID,
                                var read_by: Option[List[String]] = Some(List()),
                                createdAt: Option[Date] = Some(Calendar.getInstance.getTime),
                                updatedAt: Option[Date] = Some(Calendar.getInstance.getTime))


object GalleryCommentEntity {

  implicit def toGalleryCommentEntity(comment: GalleryComment): GalleryCommentEntity = GalleryCommentEntity(body = comment.body,
    activity_id = BSONObjectID.parse(comment.activity_id).get, sender_id = BSONObjectID.parse(comment.sender_id).get)

  import io.circe._
  import io.circe.syntax._
  import io.circe.generic.auto._


//  implicit val jsonEncoder = Encoder[GalleryCommentEntity]
//  implicit val jsonDecoder = Decoder[GalleryCommentEntity]

  implicit object GalleryCommentBSONReader extends BSONDocumentReader[GalleryCommentEntity] {

    def read(doc: BSONDocument): GalleryCommentEntity =
      GalleryCommentEntity(
        id = doc.getAs[BSONObjectID]("_id").get,
        body = doc.getAs[String]("body").get,
        activity_id = doc.getAs[BSONObjectID]("activity_id").get,
        sender_id = doc.getAs[BSONObjectID]("sender_id").get,
        read_by = doc.getAs[List[String]]("read_by")
      )
  }

  implicit object GalleryCommentBSONWriter extends BSONDocumentWriter[GalleryCommentEntity] {
    def write(commentEntity: GalleryCommentEntity): BSONDocument =
      BSONDocument(
        "_id" -> commentEntity.id,
        "body" -> BSONString(commentEntity.body),
        "activity_id" -> commentEntity.activity_id,
        "sender_id" -> commentEntity.sender_id,
        "read_by" -> commentEntity.read_by,
        "created_at" -> commentEntity.createdAt,
        "updated_at" -> commentEntity.updatedAt
      )
  }
} 
开发者ID:Rozilo,项目名称:uss-gallery,代码行数:59,代码来源:GalleryCommentEntity.scala

示例4: write

//设置package包名称以及导入依赖的类
package com.realizationtime.btdogg.persist

import java.time.{Instant, LocalDate}

import com.realizationtime.btdogg.TKey
import com.realizationtime.btdogg.parsing.ParsingResult.{FileEntry, TorrentDir, TorrentFile}
import com.realizationtime.btdogg.persist.MongoPersist.{Liveness, TorrentDocument}
import com.realizationtime.btdogg.persist.MongoTorrentWriter.localDateToString
import reactivemongo.bson.{BSONDateTime, BSONDocument, BSONDocumentWriter, BSONInteger, BSONString, BSONWriter, Macros}

trait MongoTorrentWriter {

  implicit val tkeyWriter = new BSONWriter[TKey, BSONString] {
    override def write(k: TKey): BSONString = BSONString(k.hash)
  }
  implicit val torrentDataFileWriter: BSONDocumentWriter[TorrentFile] = Macros.writer[TorrentFile]
  implicit val torrentDataDirWriter: BSONDocumentWriter[TorrentDir] = Macros.writer[TorrentDir]
  implicit val torrentDataWriter: BSONDocumentWriter[FileEntry] = Macros.writer[FileEntry]
  implicit val instantWriter = new BSONWriter[Instant, BSONDateTime] {
    override def write(t: Instant): BSONDateTime = BSONDateTime(t.toEpochMilli)
  }

  implicit val torrentWriter: BSONDocumentWriter[TorrentDocument] = Macros.writer[TorrentDocument]

  implicit val livenessWriter: BSONDocumentWriter[Liveness] = Macros.writer[Liveness]

  implicit val localDateWriter = new BSONWriter[LocalDate, BSONString] {
    override def write(t: LocalDate): BSONString = BSONString(localDateToString(t))
  }

  implicit val mapWriter: BSONDocumentWriter[Map[LocalDate, Int]] = new BSONDocumentWriter[Map[LocalDate, Int]] {
    def write(map: Map[LocalDate, Int]): BSONDocument = {
      val elements = map.toStream.map { tuple =>
        localDateToString(tuple._1) -> BSONInteger(tuple._2)
      }
      BSONDocument(elements)
    }
  }

}

object MongoTorrentWriter {

  def localDateToString(date: LocalDate): String = date.toString

} 
开发者ID:bwrega,项目名称:btdogg,代码行数:47,代码来源:MongoTorrentWriter.scala

示例5: ReceiptRepository

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

import model.{FileEntity, ReceiptEntity}
import reactivemongo.api.collections.bson.BSONCollection
import reactivemongo.bson.{BSONArray, BSONDocument, BSONString}
import scala.concurrent.Future

class ReceiptRepository extends MongoDao[ReceiptEntity] {

  lazy val collectionFuture: Future[BSONCollection] = dbFuture.map(db => db[BSONCollection]("receipts"))

  def save(receiptEntity: ReceiptEntity): Future[ReceiptEntity] = save(collectionFuture, receiptEntity)

  def deleteById(id: String): Future[Unit] = deleteById(collectionFuture, id).map(_ => ())

  def findForUserId(userId: String): Future[List[ReceiptEntity]] =
    findList(collectionFuture, BSONDocument("userId" -> userId)).map(_.sortWith(_.timestamp > _.timestamp))

  def findByIds(ids: Seq[String]): Future[List[ReceiptEntity]] =
    findList(collectionFuture,
             BSONDocument(
               "_id" ->
                 BSONDocument("$in" -> BSONArray(ids.map(BSONString)))))
      .map(_.sortWith(_.timestamp > _.timestamp))

  def addFileToReceipt(receiptId: String, file: FileEntity): Future[Unit] =
    collectionFuture
      .flatMap(
        _.update(
          selector = BSONDocument("_id" -> receiptId),
          update = BSONDocument(
            "$push" -> BSONDocument("files"        -> file),
            "$set"  -> BSONDocument("lastModified" -> System.currentTimeMillis())
          )
        ))
      .map(_ => ())

  def findById(id: String): Future[Option[ReceiptEntity]] = find(collectionFuture, queryById(id))

} 
开发者ID:Leonti,项目名称:receipts-rest-service,代码行数:41,代码来源:ReceiptRepository.scala

示例6: read

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

import java.util.UUID

import org.joda.time.DateTime
import reactivemongo.bson.{BSONDateTime, BSONHandler, BSONString}

package object handlers {
  implicit val UUIDHandler = BSONHandler(
    { read: BSONString => UUID.fromString(read.value) },
    { write: UUID => BSONString(write.toString)  }
  )

  implicit val DateTimeHandler = new BSONHandler[BSONDateTime, DateTime] {
    override def read(bson: BSONDateTime): DateTime = {
      new DateTime(bson.value)
    }

    override def write(t: DateTime): BSONDateTime = {
      BSONDateTime(t.getMillis)
    }
  }
} 
开发者ID:pequalsnp,项目名称:eve-isk-tracker,代码行数:24,代码来源:package.scala


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