Re: Handling multiple databases using Cayenne+Spring

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu Apr 08 2010 - 12:40:32 EDT

  • Next message: Andrus Adamchik: "Re: Visibility & Monitoring"

    I should add that DataNode is a shared object, so
    DataNode.setDataSource(..) will affect all threads accessing Cayenne.
    So if you have thread-specific DataSource (something your original
    message seems to imply), it won't be appropriate to set it globally.
    This is another reason why a custom factory may be a better idea, as
    it can integrate with Spring backend, taking into account all its
    configuration details. So here is another idea:

    http://cayenne.apache.org/doc30/api/org/apache/cayenne/conf/Configuration.html#setDataSourceFactory%28org.apache.cayenne.conf.DataSourceFactory%29

    The difference between DataSourceFactory set in the Modeler and the
    one set via Configuration is that the later can itself originate from
    Spring, and get all the stuff it needs via injection. Don't know
    enough about Spring to give you more details, but if you can inject
    web-layer objects (request, session) into Spring beans, you should be
    able to pull it off.

    Otherwise your best bet is still a custom DataSourceFactory, but used
    with a static ThreadLocal that stores current HttpServletRequest.

    Andrus

    On Apr 8, 2010, at 4:40 PM, Andrus Adamchik wrote:

    > You can.
    >
    > On Apr 8, 2010, at 4:26 PM, Sudheer wrote:
    >
    >>
    >> Can we implement without customizing DataSourceFactory? Because
    >> entire
    >> connection related information is in an object that is part of
    >> HTTPSession.
    >> getDataSource method only takes String parameter.
    >
    > A factory can be smart about that, getting this info from a thread
    > local or something.
    >
    >> Can I have empty xxxx.driver.xml configured and attach DataSource
    >> dynamically to the node?
    >
    > You can use DataNode.setDataSource(..). You may still want create a
    > custom factory that does nothing to make sure Cayenne starts without
    > errors.
    >
    > Andrus
    >



    This archive was generated by hypermail 2.0.0 : Thu Apr 08 2010 - 12:42:20 EDT