ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Julien Lafontaine" <julienlafontaine2...@gmail.com>
Subject Re: Need a custom way for sqlMapConfig.xml to get JDBC properties
Date Wed, 22 Nov 2006 22:46:44 GMT
Why don't you just do something like that:


Properties p = new Properties();
p.setProperty("db.connectionDriver", "driver");

p.setProperty("db.connectionUserName", "driver");

...
SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader, p);

It worked for me

Julien




On 11/23/06, Hycel Taylor <hycel1@gmail.com> wrote:
>
> In our environment, we are currently using iBatis in three separate
> databases.  We deploy to four environments, dev, staging, and two
> production environments.  For security reasons, the database user
> names and passwords are different in each environment.  Deploying jars
> that use iBatis is cumbersome because the sqlMapConfig.xml has to live
> in the jar and the properties file which the sqlMapConfig references
> must also exist within the class path.
>
> Example:
>
> <sqlMapConfig>
> <properties resource="config/feeddb/ibatis/feeddb.properties"/>
>
> <transactionManager type="JDBC">
>    <dataSource type="DBCP">
>      <property name="JDBC.Driver" value="${db.connectionDriver}"/>
>      <property name="JDBC.ConnectionURL" value="${db.connectionURL}"/>
>      <property name="JDBC.Username" value="${db.connectionUserName}"/>
>      <property name="JDBC.Password" value="${db.connectionPassword}"/>
>      <property name="JDBC.DefaultAutoCommit" value="false"/>
>      <property name="Pool.MaximumActiveConnection" value="10"/>
>      <property name="Pool.MaximumIdleConnections" value="5"/>
>      <property name="Pool.MaximumCheckoutTime" value="60000"/>
>      <property name="Pool.TimeToWait" value=""/>
>    </dataSource>
> </transactionManager>
> …
>
> I've been given the mandate to "Change all configuration files used by
> iBatis to be read from one central place".   In order to meet this
> goal, I need to modify, hopefully, only a few iBatis java classes that
> would use the interface, shown below, to in order to retrieve JDBC
> property parameters.
>
> public interface CustomResource {
> public String getConnectionDriver();
> public String getConnectionURL();
> public String getConnectionUserName();
> public String getConnectionPassword();
> }
>
> I could then write a concrete class that implements CustomResource to
> retrieve JDBC resource information anyway I want.  There are a few
> more things that I need to hammer out in order to implement this.
>
> 1) What iBatis class or classes would I need to modify to use the
> CustomResource intereface?
>
> 2) In sqlMapConfig.xml I would also need to define a property to
> specify the use of the custom class.
>
> Example: <property
> customResource="com.test.app.feeddb.dataAccess.ibatis.CustomResourceImpl
> "/>
>
> Now, it seems that I may have to modify some more iBatis classes and
> the DTD to make this possible.
>
> I would appreciate any advice, suggestions or other possible solutions
> to resolve this issue.
>
> Thank you,
>
> Hycel Taylor
> Principal Architect
> 80108 Media
>

Mime
View raw message