cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Kienenberger" <>
Subject Re: DataContext scope in web apps
Date Mon, 27 Mar 2006 19:34:51 GMT
On 3/27/06, Andrus Adamchik <> wrote:
> 3. Another possibility - if you never ever carry uncommitted state
> across requests, you can setup a filter that does
> DataContext.rollbackChanges() at the end of the request. This is a
> variation of the request-scope context, only preserving caching
> benefits.

This is how I'm doing it as well.

I have a session-scoped DataContext and I assign it to thread-local in
my first servlet filter.   At the post-processing stage (insuring that
it's also the last piece of code executed per request), I remove the
thread-local, and I validate that the DataContext has no new objects,
no modified objects, and no deleted objects.   If it does, I log each
object as an error and rollback the context.   For now, I also throw
an error since this is still in the dev stages and it's a bug to be in
this state.

I'm happy to post the code if anyone's interested.  It depends only on
Cayenne and javax.servlet classes.

View raw message