|
I'll give it a shot...
I'm developing an app that uses struts/castor
and I ran into a similar issue. I ended up building a pooling class which
made sure that any time a given thread needed a Database, it got the same
instance. This made things simpler by not having to pass the database
object in between objects that were enlisted to do work during a given
request. To handle commit/rollback I modified the pool so that it returned
a wrapper class that extends Database such that begin, commit, rollback, etc.
don't operate on the underlying database until the appropriate time. The
actual commit/rollback, etc. is handled by a RequestProcessor that finalizes any
database operations after the action has completed. This gives a primitive form
of container managed transactions and isolates a lot of the nastiness of making
sure you can do database operations without having to worry if something else on
the thread has already opened or closed a transaction. I'll be happy to
share what I've got so far if anyone wants it.
--bryan
|
