Permalink
Browse files

[scala] Append operation, to add a single value as row in row list:

```scala
val list = RowLists.rowList1(classOf[String])
list :+ "row"
```
  • Loading branch information...
cchantep
cchantep committed Sep 12, 2013
1 parent 36159af commit 764c22d87a590ec1785985e389386720f535e66a
Showing with 18 additions and 5 deletions.
  1. +12 −2 readme.md
  2. +2 −0 scala/src/main/scala/Acolyte.scala
  3. +4 −3 scala/src/test/scala/acolyte/ScalaUseCases.scala
View
@@ -289,8 +289,9 @@ import Acolyte._ // import DSL
// Prepare handler
val handler: CompositeHandler = handleStatement.
withQueryDetection("^SELECT "). // regex test from beginning
withQueryDetection("EXEC that_proc"). // second detection regex
withQueryDetection(
"^SELECT ", // regex test from beginning
"EXEC that_proc"). // second detection regex
withUpdateHandler({ e: Execution
if (e.sql.startsWith("DELETE ")) {
// Process deletion ...
@@ -478,6 +479,15 @@ RowLists.timeList() :+ timeRow
RowLists.timestampList() :+ tsRow
```
On single column row list, it's also possible to directly append unwrapped value, instead of row object wrapping a single value:
```java
RowLists.stringList :+ "stringVal"
// ... instead of ...
//RowLists.stringList() :+ Rows.row1("stringVal")
```
Once you have declared your row list, and before turning it as result set, you can either add rows to it, or leave it empty.
```scala
@@ -52,6 +52,8 @@ object Acolyte extends ScalaRowLists {
h(Execution(sql, scalaParameters(params))).asResult
}
implicit def SingleValueRow[A, B](value: A)(implicit f: A B): Row.Row1[B] = Rows.row1[B](f(value))
private def scalaParameters(p: JList[Parameter]): List[ExecutedParameter] =
JavaConversions.collectionAsScalaIterable(p).
foldLeft(Nil: List[ExecutedParameter]) { (l, t)
@@ -24,8 +24,9 @@ object ScalaUseCases {
// Prepare handler
val handler: CompositeHandler = handleStatement.
withQueryDetection("^SELECT "). // regex test from beginning
withQueryDetection("EXEC that_proc"). // second detection regex
withQueryDetection(
"^SELECT ", // regex test from beginning
"EXEC that_proc"). // second detection regex
withUpdateHandler({ e: Execution
if (e.sql.startsWith("DELETE ")) {
// Process deletion ...
@@ -122,7 +123,7 @@ object ScalaUseCases {
def useCase4: SqlConnection = connection {
handleStatement.
withQueryDetection("^SELECT ").
withQueryHandler({ e: Execution RowLists.booleanList :+ row1(true) })
withQueryHandler({ e: Execution RowLists.booleanList :+ true })
} // end of useCase4
} // end of class ScalaUseCases

0 comments on commit 764c22d

Please sign in to comment.