ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kyohyoh Choh <C...@jp.ibm.com>
Subject Re: How can I change datasource connect info on the fly w/iBATIS and Spring?
Date Tue, 17 Apr 2007 03:42:18 GMT




Hello
Our application has a similar requirement that need to switch among
multiple datasources dynamicly, although we do not need to create
datasource in fly. We defined the datasources in ApplicationContex.xml,
then using getBean to load the datasource depand on the user's request
parameter and then set the datasource to the DAO's sqlMapClientTemplate
using setDataSource method. Also we need to define DAO as Singleton=false
to keep thread save.

Best Regards



                                                                           
             Paul Sanders                                                  
             <tendancer@gmail.                                             
             com>                                                       To 
                                       user-java@ibatis.apache.org         
             2007/04/14 06:27                                           cc 
                                                                           
                                                                   Subject 
             Please respond to         Re: How can I change datasource     
             user-java@ibatis.         connect info on the fly w/iBATIS    
                apache.org             and Spring?                         
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           





Interesting.... but you are right, our datasource info is not known in
advance though some are stored in a table and fetched at runtime when the
user selects it from a drop down in the browser. And of course they can
create one on the fly, too.

I wonder if the answer is to unwire the datasource from the DAO bean and
inject it by hand in the controller method. I lose the niceness of the
Spring framework for this particular task but I think it should work?

Paul


Chris Lamey wrote:
>
> Yea, Spring has a new AbstractRoutingDataSource that can route to a
> different datasource based on a ThreadLocal.  The problem is that the
> iBATIS SqlMapClient doesn't know the datasource isn't the same between
> calls, so your caching gets horked.
>
> I don't know if it'll work for you because your datasources have to be
> known in advance and it sounds like yours may not be.
>
> Cheers,
> Chris
>
>

--
View this message in context:
http://www.nabble.com/How-can-I-change-datasource-connect-info-on-the-fly-w-iBATIS-and-Spring--tf3573169.html#a9986772

Sent from the iBATIS - User - Java mailing list archive at Nabble.com.




Mime
View raw message