Guice, JDBC and managing database connections

前端 未结 4 541
时光取名叫无心
时光取名叫无心 2020-12-12 13:57

I\'m looking to create a sample project while learning Guice which uses JDBC to read/write to a SQL database. However, after years of using Spring and letting it abstract a

4条回答
  •  忘掉有多难
    2020-12-12 14:33

    I would use something like c3po to create datasources directly. If you use ComboPooledDataSource you only need instance (pooling is done under the covers), which you can bind directly or through a provider.

    Then I'd create an interceptor on top of that, one that e.g. picks up @Transactional, manages a connection and commit/ rollback. You could make Connection injectable as well, but you need to make sure you close the connections somewhere to allow them to be checked into the pool again.

提交回复
热议问题