FAQ
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?

Search Discussions

  • John Huss at Nov 7, 2013 at 2:10 am
    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 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?
  • Emanuele Maiarelli at Nov 7, 2013 at 6:27 pm
    Thank you for the hints John,

    and yes im using a servlet container.




    2013/11/7 John Huss <johnthuss@gmail.com>
    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 <
    maiarelli.emanuele@gmail.com> 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?

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriescayenne
postedNov 6, '13 at 10:47p
activeNov 7, '13 at 6:27p
posts3
users2
websitecayenne.apache.org

2 users in discussion

Emanuele Maiarelli: 2 posts John Huss: 1 post

People

Translate

site design / logo © 2022 Grokbase