mbickel
09/09/2016, 1:52 PMandrewoma
09/10/2016, 1:56 AMManagedThreadLocalSession
if for where something external manages transactions, often via @Transaction
attributes. There's a couple of examples but nothing for Guice. Personally, I wouldn't recommend this path. I'd use ThreadLocalSession
and use session.transaction {}
blocks. These blocks are re-entrant so there's no problem nesting codeandrewoma
09/10/2016, 1:58 AMmbickel
09/12/2016, 9:07 AM@Provides fun provideSession(dataSource: DataSource): Session = ThreadLocalSession(dataSource, PostgresDialect(), emptySet())
(instead of the Managed one). Looks good so far - and yeah, this is Dropwizard underneath, so the DS is pooled by default.janvladimirmostert
09/24/2016, 1:49 PMjkwatson
09/24/2016, 2:44 PMjanvladimirmostert
09/24/2016, 6:04 PMjkwatson
09/24/2016, 6:11 PMjanvladimirmostert
09/24/2016, 6:18 PMjkwatson
09/24/2016, 6:19 PMjanvladimirmostert
09/24/2016, 6:20 PMjkwatson
09/24/2016, 6:20 PMjanvladimirmostert
09/24/2016, 6:25 PMjkwatson
09/24/2016, 6:29 PMjanvladimirmostert
09/24/2016, 6:29 PMjanvladimirmostert
09/24/2016, 6:30 PMjkwatson
09/24/2016, 6:30 PMjkwatson
09/24/2016, 6:30 PMjkwatson
09/24/2016, 6:31 PMgalen
09/24/2016, 6:32 PMjanvladimirmostert
09/24/2016, 6:35 PMgalen
09/24/2016, 6:37 PMgalen
09/24/2016, 6:37 PMjanvladimirmostert
09/24/2016, 6:47 PMUser(fname=it.getString(0), lname=it.getString(1), …)
The RX-Java one I’ll have a look at, maybe VertX is stable enough for use, just feel strange going back a decade and manually mapping results from a database call to an object.
16 override fun getUser(id: String): Future<User> =
17 client.queryOne("SELECT ID, FNAME, LNAME FROM USERS WHERE ID=?", listOf(id)) {
18 it.results.map { User(it.getString(0), it.getString(1), it.getString(2)) }.first()
19 }
At startup all you have to do is:
1 val client = JDBCClient.createShared(vertx, JsonObject()
2 .put("url", "jdbc:hsqldb:mem:test?shutdown=true")
3 .put("driver_class", "org.hsqldb.jdbcDriver")
4 .put("max_pool_size", 30));
http://maballesteros.com/articles/vertx3-kotlin-rest-jdbc-tutorial/jkwatson
09/24/2016, 7:44 PMjanvladimirmostert
09/24/2016, 7:49 PMjkwatson
09/24/2016, 7:49 PMjanvladimirmostert
09/24/2016, 7:50 PMjkwatson
09/24/2016, 7:50 PMjkwatson
09/24/2016, 7:51 PM