I just wanted to get my 2 cents in while this discussion is happening. ;-)

We're not upgraded to ibatis 3 yet, but in our current environment, we have 
found it to be VERY helpful to be able to deploy one application and have that 
same java code be able to use different datasources on the fly. We can use the 
currently live code with both the live server or any of our development 
servers, or conversely we can use bleeding edge code and test its compatibility 
with the live database server.  (lets us make sure that our sql maps are 
compatible with any schema changes on the live server, and also lets us go live 
with the exact app they tested with, without any code or config changes).

We accomplish this by having our client calls pass in the requested environment 
on each service call, which in turn on the service tier is used to lookup a 
specific instance of a SqlMapClient, lazily loaded, that has that db's 
datasource attached.

I give each of my environments a key, such as "live" or "development" or 
"staging" etc., which is what is passed to the service. 

This has been very useful; I actually just today had a tester that wasn't 
really testing our application but rather the data who was glad that they could 
use our live application with test data without having to wait on me. I'm not 
100% comfortable with my actual implementation because of the lookup that I 
have to do to get a SqlMap instance.

In other words, it would be cool to have this kind of on-the-fly-environment 
choosing built-in.  When I get time to pay more attention to v3, I might try to 
mock it up.

Let me know what you think...
-Bryan 

-----Original Message-----
From: Björn Raupach [mailto:raup...@e2n.de] 
Sent: Wednesday, April 28, 2010 4:14 AM
To: user-java@ibatis.apache.org
Subject: Re: Select environment using XML

This is not run-time. You must redeploy the application. Why not select the 
environment
based on a property file? This way you only need to restart the application.

<environments default="${env}">

Looks like a nice feature. Is there anything to be said against it?



On Apr 28, 2010, at 3:02 AM, Alex Park wrote:

> Hi,
> 
> SqlSessionFactoryBuilder.build() method can select a specific environment in 
> XML.
> 
> For example,
> 
> private Reader reader;
> private SqlSessionFactory sqlSessionFactorys;
> private SqlSession session;
> 
> reader = Resources.getResourceAsReader("ibatis-config.xml");
> 
> sqlSessionFactorys = new SqlSessionFactoryBuilder().build(reader, "test");
> testSession = sqlSessionFactorys.openSession(); // test env
> 
> sqlSessionFactorys = new SqlSessionFactoryBuilder().build(reader, "dev");
> devSession = sqlSessionFactorys.openSession(); // dev env
> 
> 
> Thanks,
> Alex
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org
> For additional commands, e-mail: user-java-h...@ibatis.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org
For additional commands, e-mail: user-java-h...@ibatis.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org
For additional commands, e-mail: user-java-h...@ibatis.apache.org

Reply via email to