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

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                                                  
             com>                                                       To 
             2007/04/14 06:27                                           cc 
             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?


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:

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

View raw message