Re: Please help: retrieval and proper usage of per thread DataContext

From: Joshua Pyle (joshua.t.pyl..mail.com)
Date: Wed Nov 30 2005 - 11:46:20 EST

  • Next message: Joshua Pyle: "Re: R: [v.1.1.3 September 28 2005] Global exception."

    Just incase this helps, this is all I do when getting a datacontext.

        public DataContext getDataContext() {
            DataContext context = null;
            try {
                context = DataContext.getThreadDataContext();
            } catch (IllegalStateException ex) {
                // Bind the DataContext
                context = DataContext.createDataContext();
                DataContext.bindThreadDataContext(context);
            }
            return context;
        }

    This is working great and essentially just gives me a DataContext that
    lives only during the request. I've found this is a great aproach for
    web based applications.

    --
    Joshua T. Pyle
    Go has always existed.
    

    On 11/29/05, Andrus Adamchik <andru..bjectstyle.org> wrote: > I confirmed - this is a bug in Jetty. I get the same results as you > do on Jetty 5.1.3, while on Tomcat "requestInitialized" and > "requestDestroyed" are being called just fine. Haven't tried Jetty 6 > yet. > > As a workaround that works on all servers with both servlet spec 2.3 > and 2.4, I suggest using WebApplicationContextFilter instead of the > listener. Here is a snip from a sample web.xml > > > <filter> > <filter-name>CayenneFilter</filter-name> > <filter- > class>org.objectstyle.cayenne.conf.WebApplicationContextFilter</ > filter-class> > </filter> > <filter-mapping> > <filter-name>CayenneFilter</filter-name> > <url-pattern>/*</url-pattern> > </filter-mapping> > > This is taken from Example #2 on Wiki: > > http://objectstyle.org/confluence/display/CAY/Cayenne+Examples) > > Andrus > > On Nov 30, 2005, at 3:45 AM, Joseph Hannon wrote: > > Andrus, > > > > A little more testing- thanks for the debug tip! I subclassed > > WebApplicationContextProvider and overrode all the relevant methods > > including "requestInitialized" to allow dubug log statements. > > "requestInitialized" is not called for some reason, but methods > > around it are. My results are below. I upgraded to Jetty 5.1.6 to > > see if that would help, it did not. Could try it in Tomcat to see > > if there is any change, wouldn't expect a change. I may need to do > > as you suggest with ServletUtil. I am also unaware of how to get > > the session at that point. > > > > Joseph > > > > App startup: > > > > (main) DEBUG foo.bar.utility.DataContextProvider.<init>() > > (main) DEBUG foo.bar.utility.DataContextProvider.contextInitialized() > > > > Going to Page 1 (reads from DB) > > > > (SunJsseListener1-1) DEBUG > > foo.bar.utility.DataContextProvider.sessionCreated() > > (SunJsseListener1-1) DEBUG > > foo.bar.utility.DataContextProvider.getConfiguration() > > > > Submit Page 1 > > Going to Page 2 (reads from DB) > > Submit Page 2 (writes to DB) > > > > (SunJsseListener1-0) DEBUG > > foo.bar.utility.DataContextProvider.sessionDestroyed() > > > > Complete. > > > >



    This archive was generated by hypermail 2.0.0 : Wed Nov 30 2005 - 11:46:23 EST