Thank you for the hints John,

and yes im using a servlet container.




2013/11/7 John Huss <[email protected]>

> Assuming your using a servlet container:
>
> 1) Add CayenneFilter to your web.xml
>
> http://cayenne.apache.org/docs/3.1/api/org/apache/cayenne/configuration/web/CayenneFilter.html
>
> 2) Retrieve the ServerRuntime using WebUtil.getCayenneRuntime
>
> http://cayenne.apache.org/docs/3.1/api/org/apache/cayenne/configuration/web/WebUtil.html#getCayenneRuntime(javax.servlet.ServletContext)
>
> If not servlets, then you can just do new ServerRuntime(...) and stash it
> in a static variable or do anything you like.
>
>
>
> On Wed, Nov 6, 2013 at 4:47 PM, Emanuele Maiarelli <
> [email protected]> wrote:
>
> > We have a web multi tenant application developed with cayenne 3.0.
> >
> > Tenants are implemented in a single database, so there's a 'tenantId' on
> > most of database tables.
> >
> > With cayenne we implemented the tenancy, 'injecting' the property, either
> > on SelectQuery and new entities, using a custom automated way.
> >
> > Everything is working fine, but we'd like to migrate it to cayenne 3.1
> > reimplementing teantcy management using LifeCycle events listeners (to
> > populate tenat field)  and datachannelflters (for intercepting
> > selectqueries to add tenant field).
> >
> > Actually we provide ObjectContexts using a WebApplicationContextFilter
> > implemented this way:
> > ....
> >  public void doFilter(ServletRequest request,
> >                        ServletResponse response, FilterChain chain)
> throws
> > IOException,
> >
> > ServletException {
> >
> >     boolean reset = false;
> >
> >     if (request instanceof HttpServletRequest) {
> >       reset = true;
> >
> >       HttpSession session = ((HttpServletRequest)request)
> >         .getSession(true);
> >       DataContext context = ServletUtil.getSessionContext(session);
> >
> >
> >       BaseContext.bindThreadObjectContext(context);
> >     }
> >
> >     try {
> >       chain.doFilter(request, response);
> >     }
> >
> >
> > ....
> >
> > so for each session we have a context and we bind it to threads.
> >
> > Now with cayenne 3.1, we should use ServerRuntime getting its DataDomain,
> > setting the callback listener and filter, and then obtaining contexts
> from
> > the  ServerRuntime.
> >
> > What's the right way to manage the ServerRuntime inside the application
> > server?
> >
> > Should we implement it as singleton, and obtain an ObjectContex for each
> > session and binding to threads using BaseContext as we did before?
> >
>

Reply via email to