Return-Path: Delivered-To: apmail-cayenne-user-archive@www.apache.org Received: (qmail 90201 invoked from network); 8 Apr 2010 16:42:05 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 8 Apr 2010 16:42:05 -0000 Received: (qmail 62233 invoked by uid 500); 8 Apr 2010 16:42:02 -0000 Delivered-To: apmail-cayenne-user-archive@cayenne.apache.org Received: (qmail 62218 invoked by uid 500); 8 Apr 2010 16:42:02 -0000 Mailing-List: contact user-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@cayenne.apache.org Delivered-To: mailing list user@cayenne.apache.org Received: (qmail 62172 invoked by uid 99); 8 Apr 2010 16:42:02 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Apr 2010 16:42:02 +0000 X-ASF-Spam-Status: No, hits=-1.1 required=10.0 tests=AWL,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [208.78.103.231] (HELO vorsha.objectstyle.org) (208.78.103.231) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 08 Apr 2010 16:41:55 +0000 Received: (qmail 6925 invoked from network); 8 Apr 2010 16:40:33 -0000 Received: from unknown (HELO ?IPv6:::1?) (127.0.0.1) by localhost with SMTP; 8 Apr 2010 16:40:33 -0000 Message-Id: <04362144-5A31-452F-8242-420711B7A048@objectstyle.org> From: Andrus Adamchik To: user@cayenne.apache.org In-Reply-To: <07E945F3-C0BD-4E68-8563-AB81FC671D03@objectstyle.org> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v936) Subject: Re: Handling multiple databases using Cayenne+Spring Date: Thu, 8 Apr 2010 19:40:32 +0300 References: <1270549023971-699967.post@n3.nabble.com> <1270629082757-702422.post@n3.nabble.com> <980EFEC5-1913-4129-BFC8-68B82941AFBC@objectstyle.org> <1270733187884-705924.post@n3.nabble.com> <07E945F3-C0BD-4E68-8563-AB81FC671D03@objectstyle.org> X-Mailer: Apple Mail (2.936) 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 >