Wednesday, April 12, 2006

Recap of recent weeks (Spring framework).

Let's see... When I was laying down with severe stomach flu last week I had a bunch of ideas of what to write about here... Where did it all go?

Had first encounter with Spring. Amazing technology, really. I started looking for some container that will have contextual support for persistent operations, basically. Mostly because I got sick of seeing code passing, from one method into another, some custom construct tying together database connection and current statement and/or result set (Did I mention how twisted are some designs I encounter at my workplace? I'm sure I did :) ). I wanted something akin to how it's done in EJB, but without an EJB container (it's unthinkable to expect us to deploy a full-blown J2EE stack in any foreseeable perspective). Very glad Spring allows for this. It took me two partial weekend days overall to figure out a working XML config file. After I figured it out, it all makes sense:
  • configure a DataSource (I'm using embedded Derby; this has a nasty effect that shutting down Derby cleanly is not possible without writing a wrapper DisposableBean, as Derby will not take a single no-arg method call to go down....)
  • using this DataSource, create a Hibernate SessionFactory
  • using same DataSource, build transaction manager
  • take that transaction manager and stuff it into a DAO alongside SessionFactory (make sure DAO implements an interface, and when casting the object acquired from application context aka bean factory, cast the object to that interface; again, result being not unlike EJB or RMI stub compiler would produce)
The DAO has very little code. In fact, less than a plain Hibernate solution would have, benefit of famous HibernateTemplate. As an extra bonus, I get declarative transaction support, all worked in by a little AOP magic. Hoping to have significant time savings to result out of this for my project at work. And the project quickly approaches a major crunch... timely discovery, then.

0 Comments:

Post a Comment

<< Home