Permalink
Browse files

[scala] Supports `Execution => RowList[_]` as query handler:

```scala
Acolyte.withQueryHandler({ e: Execution => rowList })
```
  • Loading branch information...
cchantep
cchantep committed Sep 12, 2013
1 parent 14b1978 commit a7d52d131853936f4283c336058ff75e409251fa
@@ -47,6 +47,11 @@ object Acolyte extends ScalaRowLists {
}
}
implicit def RowListQueryHandler[R <: RowList[_]](h: Execution R): QueryHandler = new QueryHandler {
def apply(sql: String, params: JList[Parameter]): QueryResult =
h(Execution(sql, scalaParameters(params))).asResult
}
private def scalaParameters(p: JList[Parameter]): List[ExecutedParameter] =
JavaConversions.collectionAsScalaIterable(p).
foldLeft(Nil: List[ExecutedParameter]) { (l, t)
@@ -151,4 +151,17 @@ object AcolyteSpec extends Specification {
}
}
"Scala use case #4" should {
val con = ScalaUseCases.useCase4
"return expected boolean result" in {
lazy val s = con.prepareStatement("SELECT * FROM table")
lazy val rs = s.executeQuery
(rs.next aka "has first row" must beTrue).
and(rs.getBoolean(1) aka "single column" must beTrue)
}
}
}
@@ -114,4 +114,15 @@ object ScalaUseCases {
// ... then connection is managed through |handler|
return DriverManager.getConnection(jdbcUrl);
} // end of useCase3
/**
* Use case #4 - Row list convinience constructor
* and query handler convertion.
*/
def useCase4: SqlConnection = connection {
handleStatement.
withQueryDetection("^SELECT ").
withQueryHandler({ e: Execution RowLists.booleanList :+ row1(true) })
} // end of useCase4
} // end of class ScalaUseCases

0 comments on commit a7d52d1

Please sign in to comment.