cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <and...@objectstyle.org>
Subject Re: Handling multiple databases using Cayenne+Spring
Date Thu, 08 Apr 2010 16:40:32 GMT
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
>


Mime
View raw message