Skip to content

Commit

Permalink
[scala] Append operation, to add a single value as row in row list:
Browse files Browse the repository at this point in the history
```scala
val list = RowLists.rowList1(classOf[String])
list :+ "row"
```
  • Loading branch information
cchantep committed Nov 25, 2013
1 parent 36159af commit 764c22d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
14 changes: 12 additions & 2 deletions readme.md
Expand Up @@ -289,8 +289,9 @@ import Acolyte._ // import DSL


// Prepare handler // Prepare handler
val handler: CompositeHandler = handleStatement. val handler: CompositeHandler = handleStatement.
withQueryDetection("^SELECT "). // regex test from beginning withQueryDetection(
withQueryDetection("EXEC that_proc"). // second detection regex "^SELECT ", // regex test from beginning
"EXEC that_proc"). // second detection regex
withUpdateHandler({ e: Execution withUpdateHandler({ e: Execution
if (e.sql.startsWith("DELETE ")) { if (e.sql.startsWith("DELETE ")) {
// Process deletion ... // Process deletion ...
Expand Down Expand Up @@ -478,6 +479,15 @@ RowLists.timeList() :+ timeRow
RowLists.timestampList() :+ tsRow 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. 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 ```scala
Expand Down
2 changes: 2 additions & 0 deletions scala/src/main/scala/Acolyte.scala
Expand Up @@ -52,6 +52,8 @@ object Acolyte extends ScalaRowLists {
h(Execution(sql, scalaParameters(params))).asResult 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] = private def scalaParameters(p: JList[Parameter]): List[ExecutedParameter] =
JavaConversions.collectionAsScalaIterable(p). JavaConversions.collectionAsScalaIterable(p).
foldLeft(Nil: List[ExecutedParameter]) { (l, t) foldLeft(Nil: List[ExecutedParameter]) { (l, t)
Expand Down
7 changes: 4 additions & 3 deletions scala/src/test/scala/acolyte/ScalaUseCases.scala
Expand Up @@ -24,8 +24,9 @@ object ScalaUseCases {


// Prepare handler // Prepare handler
val handler: CompositeHandler = handleStatement. val handler: CompositeHandler = handleStatement.
withQueryDetection("^SELECT "). // regex test from beginning withQueryDetection(
withQueryDetection("EXEC that_proc"). // second detection regex "^SELECT ", // regex test from beginning
"EXEC that_proc"). // second detection regex
withUpdateHandler({ e: Execution withUpdateHandler({ e: Execution
if (e.sql.startsWith("DELETE ")) { if (e.sql.startsWith("DELETE ")) {
// Process deletion ... // Process deletion ...
Expand Down Expand Up @@ -122,7 +123,7 @@ object ScalaUseCases {
def useCase4: SqlConnection = connection { def useCase4: SqlConnection = connection {
handleStatement. handleStatement.
withQueryDetection("^SELECT "). withQueryDetection("^SELECT ").
withQueryHandler({ e: Execution RowLists.booleanList :+ row1(true) }) withQueryHandler({ e: Execution RowLists.booleanList :+ true })


} // end of useCase4 } // end of useCase4
} // end of class ScalaUseCases } // end of class ScalaUseCases

0 comments on commit 764c22d

Please sign in to comment.