Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 18160 invoked from network); 17 Apr 2007 21:10:29 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 17 Apr 2007 21:10:29 -0000 Received: (qmail 67375 invoked by uid 500); 17 Apr 2007 21:10:33 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 67364 invoked by uid 500); 17 Apr 2007 21:10:32 -0000 Mailing-List: contact user-java-help@ibatis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user-java@ibatis.apache.org Delivered-To: mailing list user-java@ibatis.apache.org Received: (qmail 67353 invoked by uid 99); 17 Apr 2007 21:10:32 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 Apr 2007 14:10:32 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of lists@nabble.com designates 72.21.53.35 as permitted sender) Received: from [72.21.53.35] (HELO talk.nabble.com) (72.21.53.35) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 Apr 2007 14:10:25 -0700 Received: from [72.21.53.38] (helo=jubjub.nabble.com) by talk.nabble.com with esmtp (Exim 4.50) id 1Hduw9-0007WL-Am for user-java@ibatis.apache.org; Tue, 17 Apr 2007 14:10:05 -0700 Message-ID: <10047766.post@talk.nabble.com> Date: Tue, 17 Apr 2007 14:10:05 -0700 (PDT) From: Paul Sanders To: user-java@ibatis.apache.org Subject: Re: How can I change datasource connect info on the fly w/iBATIS and Spring? In-Reply-To: <1176835214.28976.3.camel@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: tendancer@gmail.com References: <9983995.post@talk.nabble.com> <1176490374.8582.10.camel@localhost.localdomain> <10043460.post@talk.nabble.com> <1176835214.28976.3.camel@localhost.localdomain> X-Virus-Checked: Checked by ClamAV on apache.org Chris Lamey wrote: > > That should work ok, that Map could get modified at servlet init time. > Drat, doesn't appear to, at least not how I've written it. I think there are two problems - first, the map is already set by the time my servlet gets created and a call to setTargetDataSources will not overwrite it. Second, the map is String to String, rather than a key to a dataSource name. But I don't know how to give my dataSource a name in the context when it doesn't come from a config file. Here's what I did - maybe I did something stupid: my bean def: public class MediusRoutingDataSource extends AbstractRoutingDataSource { protected static boolean didOnce = false; @Override protected Object determineCurrentLookupKey() { if (didOnce) return "xxxMedius"; else { didOnce = true; return "medius2";} } } test code: public void testGetBanPoliciesFromDifferentSource() { BanPolicyManager mgr = (BanPolicyManager)ctx.getBean("banPolicyDAO"); System.out.println(mgr.fetchBanPolicies()); // uses 'medius2' datasource, returns empty list BasicDataSource newDS = new BasicDataSource(); newDS.setUsername("psanders"); newDS.setUrl("jdbc:oracle:thin:@toad002:1521:sid"); newDS.setPassword("psanders"); newDS.setDriverClassName("oracle.jdbc.driver.OracleDriver"); MediusRoutingDataSource mds = (MediusRoutingDataSource)ctx.getBean("mediusDataSource"); // some code omitted to create a Map routingMap.put("xxxMedius", newDS); // add new datasource to the routing map mds.setTargetDataSources(routingMap); System.out.println(mgr.fetchBanPolicies()); // now uses 'xxxMedius' datasource // exception raised java.lang.IllegalStateException: Cannot determine target DataSource for lookup key [xxxMedius] } -- 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#a10047766 Sent from the iBATIS - User - Java mailing list archive at Nabble.com.