Last active
May 25, 2020 16:30
-
-
Save dkomanov/617f3d9940561f8b290f73f64093d82f to your computer and use it in GitHub Desktop.
[writing-async-app-in-scala-part-3] blocking dao 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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