This post originated from an RSS feed registered with Java Buzz
by Chris Winters.
Original Post: Curious about Spring transaction definitions?
Feed Title: cwinters.com
Feed URL: http://www.cwinters.com/search/registrar.php?domain=jroller.com®istrar=sedopark
Feed Description: Chris Winters on Java, programming and technology, usually in that order.
The interface org.springframework.transaction.TransactionDefinitionis the place for you. (Although it's useful to keep a copy of a J2EE book around since Spring uses its declaration semantics.) It's got the different propogation and isolation types and a short but effective sentence or two on what they mean.
Tonight, two days before an initial install, I finally got around to wrapping my DAO methods with transactions. Most of them are just single-use actions anyway so it didn't matter quite as much, but once you start assembling them into larger services (like 'createPayment' or 'voidTransaction') then you start feeling some pain.
Like everything else in Spring declaring transactions is pretty easy. First let's say you have a bean:
Now you want to tell Spring to manipulate transactions around certain methods -- the default transaction support is to say any exception thrown will trigger a rollback. To do this you create a proxy and point it at your bean:
This is a little unrealistic (presumably we have some read-only methods that don't require a transaction). But it's still nifty... except for the fact that we have other objects already referring to 'ledgerActionDao'. I don't want to point them all at the proxy now because I'll surely miss something.
And since the DAOs are all generated I took advantage of Spring's flexibility by declaring a set of patterns to match against all my DAOs instead of listing the methods for each one:
This is good stuff... BTW, if you haven't seen it yet this presentation from Eduardo Issao Ito is a fantastic overview of Spring with plenty of examples throughout.