Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[writing-async-app-in-scala-part-3] blocking dao 2
class RobustDao(jdbcTemplate: JdbcTemplate,
blockingEc: ExecutionContext,
applicationEc: ExecutionContext) {
def get(id: String): Future[Option[RichDomainObject]] = {
Future(getBlocking(id))(blockingEc)
.map(blob => blob.map(parseJson))(applicationEc)
}
private def getBlocking(id: String): Option[String] =
jdbcTemplate.queryForObject(
"SELECT blob FROM table WHERE id = ?",
Array(id),
rs => rs.getString(1) // no parsing, just simple data extraction
)
private def parseJson(s: String): RichDomainObject = ???
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment