How to make simple JDBC transactions outside of an IoC container?

The project I'm working on uses direct access to JDBC data in all its glory and does not use any transactions. I feel that using transactions and simplifying ways to write data access methods is important, especially with some of the changes that are currently being made. The project has existed for a long time and is not suitable for the ORM structure. He also uses a lot of singletones (pah) and unravels it to make him use dependency injection would be enough work, and I don't think I can convince anyone that we should do it now.

I like the Spring JDBC interface, in particular through it SimpleJdbcTemplate. My question is how to enable some simple (for each servlet request) transactions for this, without setting anything programmatically in any data access method, or when using the IOC Spring container or AOP. I played with my own architecture, which ends with an interface similar SimpleJdbcTemplate, and can use a single-local connection and a request transaction when calls to it are made in the context of the request (via ServletRequestListenerwith a ThreadLocal). This seems to work well, but I think that using a good external library like Spring JDBC would be preferable.

Does anyone have any experience?

+5
source share
2 answers
+5
source

Spring processes transactions for you declaratively, unless you need to worry about writing AOP classes. If you use JDK 5 or later and Spring 2.5, you have even better with annotations .

I would not agree with per-servlet transactions. You must have a service level that is part of an application that knows about the elements of work. Controllers call services that process transactions.

0
source

All Articles