Re: Using Multiple Domain in a Web Application

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu Jan 08 2004 - 18:40:01 EST

  • Next message: Tore Halset: "using dataport"

    Hi John,

    You will need to subclass WebApplicationListener for your case with
    multiple domains. Put the name of your subclass in the web.xml instead.
    On session startup you would likely want a context created based on
    "login" domain. So "sessionCreated" overridden method would look like
    this:

            public void sessionCreated(HttpSessionEvent se) {
                    se.getSession().setAttribute(
                            BasicServletConfiguration.DATA_CONTEXT_KEY,
                            getConfiguration().getDomain("company").createDataContext());
            }

    To obtain login context use something like this:

           DataContext ctxt =
    BasicServletConfiguration.getDefaultContext(mySession);

    Later, when you finish processing login and determine the right domain,
    you can either substitute the initial "login" DataContext (if you no
    longer need access to this DB), or use a different key to store the new
    DataContext. Here is an example substituting the "login" context with
    the new one based on correct domain:

             mySession.setAttribute(
                            BasicServletConfiguration.DATA_CONTEXT_KEY,
                            DataContext.createDataContext("XYZ"));

    > DataContext ctxt = DataContext.createDataContext( "company" );

    This line would create a new instance of DataContext. This is probably
    not what you want. Instead retrieve DataContext stored in the session
    as described above.

    Andrus

    On Jan 8, 2004, at 5:39 PM, John Barrett wrote:

    > Hello,
    >
    > I am building a Web Application, using Cayenne, with multiple domains.
    > One domain is used for the entry point (validate user and get domain
    > name) to get the domain to use. I have set up the
    > WebApplicationListener in the WEB-INF and am using the following to
    > get a DataContext:
    >
    > DataContext ctxt = DataContext.createDataContext( "company" );
    >
    > This works fine and I am able to access the correct domain/database,
    > but in the catalina.out file the following is logged when a new
    > session is created:
    >
    > INFO - Session event listener threw exception
    > org.objectstyle.cayenne.CayenneRuntimeException: [v.1.0.2 October 27
    > 2003] More than one domain is configured; use 'getDomain(String name)'
    > instead.
    > at
    > org.objectstyle.cayenne.conf.Configuration.getDomain(Configuration.java
    > :422)
    > at
    > org.objectstyle.cayenne.conf.WebApplicationListener.sessionCreated(WebA
    > pplicationListener.java:116)

    > I take it the application is creating a new data context for each
    > transaction and not utilizing the session data context. What would be
    > the correct way in configuring Cayenne (to eliminate the Exception)
    > and obtain the correct data context for a given domain?
    >
    > Thanks,
    >
    > John Barrett
    > JSB Consulting Corporation
    > joh..sbcc.com
    > 703-318-9420



    This archive was generated by hypermail 2.0.0 : Thu Jan 08 2004 - 18:40:05 EST