Re: DataContext scope in web apps

From: Mike Kienenberger (mkienen..mail.com)
Date: Mon Mar 27 2006 - 14:34:51 EST

  • Next message: Mike Kienenberger: "Re: DataContext scope in web apps"

    On 3/27/06, Andrus Adamchik <andru..bjectstyle.org> 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.



    This archive was generated by hypermail 2.0.0 : Mon Mar 27 2006 - 14:35:15 EST