9. package ru.tinkoff.example
object DBConnector {
…
database.put(new WritePolicy,
new Key("namespace", "setName", new StringValue("key1")),
Seq(new Bin("binName1", new StringValue("binValue"))):_*)
database.put(new WritePolicy,
new Key("namespace", "setName", new StringValue("key2")),
Seq(new Bin("binName2", new IntegerValue(2))):_*)
database.put(new WritePolicy,
new Key("namespace", "setName", new StringValue("key3")),
Seq(new Bin("binName3", new BooleanValue(true))):_*)
}
7 Key types
12 Bin types
Java
19. def call[K, B](action: Action, key: K, bin: B)
(implicit kw: KeyWrapper[K],
bw: BinWrapper[B],
pw: Option[WritePolicy] = None) = ???
call(Put, "key", "abcd")(
new KeyWrapper[String]{},
new BinWrapper[String]{}, None)
20. trait BinWrapper[B] {
def apply(v: B): Bin = new Bin("name", toValue(v))
def toValue(v: B): Value = v match {
case s: String => new StringValue(s)
case h: HList => new MapValue(toMap(h))
case _ => throw new Exception("Wrong type")
}
def apply(r: Record): Map[String, B] =
r.bins.collect {
case (name, something) =>
name -> fetch(something)
}.toMap
def fetch(donkey: Any): B
}
21. new BinWrapper[String] {
def apply(v: String): Bin = ???
}
new BinWrapper[Int] {
def apply(v: Int): Bin = ???
}
new BinWrapper[ ] {
def apply(v: ): Bin = ???
}
25. val tpe = weakTypeOf[B]
val fetchValue = tpe match {
case t if t =:= weakTypeOf[String] =>
q""" def fetch(any: Any): $tpe = any match {
case v: String => v
case _ => throw new Exception("Wrong type")
} """
case t if isHList(t) =>
q""" def fetch(any: Any): $tpe = any match {
case mv: MapValue => mv.getObject match {
case m: Map[String, Any] =>
parse(m).toHList[$tpe].getOrElse{}
case _ => throw new Exception("Wrong type")
}
case _ => throw new Exception("Wrong type")
} """
...
}