Permalink
Browse files

[scala] Connection properties support:

```scala
import acolyte.Acolyte.connection

connection(handler, "acolyte.parameter.untypedNull" -> "true"/* ... */)
```
  • Loading branch information...
cchantep
cchantep committed Dec 4, 2013
1 parent 3b7d915 commit 500abb5493a1b6221b5e5c0f2fdf102a5bcf88ff
Showing with 43 additions and 2 deletions.
  1. +24 −2 scala/src/main/scala/Acolyte.scala
  2. +19 −0 scala/src/test/scala/acolyte/ConnectionSpec.scala
@@ -33,17 +33,39 @@ object Acolyte {
* Creates a connection, whose statement will be passed to given handler.
*
* @param h statement handler
* @param p connection properties
* @return a new Acolyte connection
*
* {{{
* connection(handler) // without connection properties
*
* // With connection property to fallback untyped null
* connection(handler, "acolyte.parameter.untypedNull" -> "true")
* }}}
*/
def connection(h: AbstractCompositeHandler[_]) = Driver.connection(h)
def connection(h: AbstractCompositeHandler[_], p: (String, String)*) =
Driver.connection(h, p.foldLeft(new java.util.Properties()) { (ps, t)
ps.put(t._1, t._2); ps
})
/**
* Creates a connection, managed with given handler.
*
* @param h connection handler
* @param p connection properties
* @return a new Acolyte connection
*
* {{{
* connection(handler) // without connection properties
*
* // With connection property to fallback untyped null
* connection(handler, "acolyte.parameter.untypedNull" -> "true")
* }}}
*/
def connection(h: ConnectionHandler) = Driver.connection(h)
def connection(h: ConnectionHandler, p: (String, String)*) =
Driver.connection(h, p.foldLeft(new java.util.Properties()) { (ps, t)
ps.put(t._1, t._2); ps
})
/**
* Creates an empty handler.
@@ -0,0 +1,19 @@
package acolyte
import acolyte.ScalaCompositeHandler.{ empty EmptyHandler }
object ConnectionSpec extends org.specs2.mutable.Specification {
"Connection" title
"Properties" should {
"be empty" in {
Acolyte.connection(EmptyHandler).getProperties.isEmpty must beTrue
}
"be set" in {
Acolyte.connection(EmptyHandler, "_test" -> "_val").
getProperties.get("_test") aka "property" mustEqual "_val"
}
}
}

0 comments on commit 500abb5

Please sign in to comment.