Skip to content

Commit 549df78

Browse files
committed
extract methods to read and write state
1 parent 1680f2b commit 549df78

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

jdbc/src/main/scala/app/softnetwork/persistence/jdbc/query/JdbcStateProvider.scala

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ trait JdbcStateProvider[T <: Timestamped]
191191
case Some(d) => d
192192
case None =>
193193
document.state match {
194-
case Some(s) => serialization.write(s)(formats)
194+
case Some(s) => writeState(s)
195195
case _ => "{}"
196196
}
197197
}
@@ -316,7 +316,7 @@ trait JdbcStateProvider[T <: Timestamped]
316316
None
317317
case (_, _, _, state) =>
318318
alogger.debug(s"Load $tableFullName with $uuid -> $value")
319-
Option(serialization.read[T](state)(formats, manifest))
319+
Option(readState(state))
320320
}
321321
case _ =>
322322
alogger.debug(s"Load $tableFullName with $uuid -> None")
@@ -340,7 +340,6 @@ trait JdbcStateProvider[T <: Timestamped]
340340
def search(
341341
query: String
342342
)(implicit m: Manifest[T], formats: Formats): List[T] = {
343-
implicit val manifest: Manifest[T] = manifestWrapper.wrapped
344343
val action: DBIOAction[List[String], NoStream, Effect] = {
345344
sql"""
346345
SELECT state FROM $tableFullName WHERE $query
@@ -349,7 +348,7 @@ trait JdbcStateProvider[T <: Timestamped]
349348
db.run(action) complete () match {
350349
case Success(value) =>
351350
alogger.debug(s"Search $tableFullName with $query -> $value")
352-
value.map(serialization.read[T](_)(formats, manifest))
351+
value.map(readState)
353352
case Failure(f) =>
354353
alogger.error(f.getMessage, f)
355354
Nil
@@ -367,6 +366,14 @@ trait JdbcStateProvider[T <: Timestamped]
367366

368367
lazy val states = TableQuery[States]
369368

369+
protected def writeState(state: T): String = {
370+
serialization.write(state)(formats)
371+
}
372+
373+
protected def readState(state: String)(implicit manifest: Manifest[T]): T = {
374+
serialization.read(state)(formats, manifest)
375+
}
376+
370377
def initTable(): Unit = {
371378
alogger.info(
372379
s"Setting up table $tableFullName ${states.schema.createStatements.mkString(";\n")}"

0 commit comments

Comments
 (0)