users@jersey.java.net

transaction-per-request

From: Adam Rabung <adamrabung_at_gmail.com>
Date: Thu, 15 Apr 2010 13:08:23 -0400

Hello,
I am trying to cleanly implement "transaction-per-request" alongside
Jersey Resources.  That is, I'd like no mention of transactions in
individual resources, but rather in a central place, as outlined by
Martin Probst in an earlier email [1]:

try {
  chain.doFilter(request, response);
  commitSession();
} finally {
  rollbackSession(); // no-op if already committed
  closeSession();
}

I've seen a few conversations about this topic on the mailing list,
but I can't piece together a good solution using the advice. I'd
rather avoid Spring for tx management, as it's not yet a dependency.
I've taken a look at CloseableService, ResourceFilter, overriding
ServletContainer.service, etc, and cannot see how I can use these to
implement transparent rollback-on-exception. I got it working by
calling rollback in a custom ExceptionMapper, but that feels very
dirty :)

If anyone has pulled this off, could they offer some pseudocode
describing the approach? Extra bonus points if the solution gives me
metadata on what resource is being executed :)

Thank you,
Adam

[1] http://markmail.org/thread/aefgmci6r2thkqxc