Hi Ramiro, I typically create web applications, so manually binding a single context to the thread isn't really an option. I need to create them on an ad-hoc basis for each user, etc.
Thanks, mrg On Thu, Feb 28, 2013 at 10:28 AM, Ramiro Aparicio < [email protected]> wrote: > El 28/02/2013 16:15, John Huss escribió: > > If it's a servlet app, then the runtime is created in CayenneFilter and >> bound to the thread for each request and you access it via >> >> WebUtil.getCayenneRuntime(**servletContext); >> >> >> Or you can get a context from the injector if you have bound that to a >> thread: >> >> ObjectContext context = >> CayenneRuntime.**getThreadInjector().**getInstance(** >> ObjectContextFactory.class >> ).createContext(); >> >> >> If not a servlet app, then yeah, I'd just store it in a static variable or >> application instance. >> >> >> >> On Thu, Feb 28, 2013 at 8:43 AM, Michael Gentry <[email protected] >> >wrote: >> >> Is there an existing place (class) in 3.1 to stuff a ServerRuntime >>> instance >>> for global use or is it expected that you'll create a separate class to >>> hold a static instance variable of ServerRuntime? >>> >>> Thanks, >>> >>> mrg >>> >>> > We avoid storing it as a singleton and use the same concept for non web > apps using BaseContext > <http://cayenne.apache.org/**docs/3.1/api/org/apache/** > cayenne/BaseContext.html<http://cayenne.apache.org/docs/3.1/api/org/apache/cayenne/BaseContext.html> > >**BaseContext.**bindThreadObjectContext(**context)|| > context = BaseContext.**getThreadObjectContext() > > So you usually just bind the context on startup and don't need to have > write your own singleton for that. > > Indeed we made a DAO Template that works in both scenarios to be able to > reuse the dao library. > > > > >
