ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Denis Vladimirov" <denis.vladimi...@gmail.com>
Subject Re: multiple database/datasources
Date Tue, 30 May 2006 23:01:42 GMT
Another option is to use Spring:

----------in Spring Config------------

    <bean id="database1DataSource"
        class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName"><value>java:comp/env/jdbc/database1DS</value>
            </property>
    </bean>

    <bean id="database2DataSource"
        class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName"><value>java:comp/env/jdbc/database2DS</value>
            </property>
    </bean>

    <bean id="sqlMapClient"
        class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
        <property name="configLocation">
            <value>/yourPath/ibatisSqlMapConfig.xml</value></property>
    </bean>

    <bean id="yourDao1"
        class="com.yourpackage.dao.SameDao">
        <property name="dataSource"><ref
local="database1DataSource"/></property>
        <property name="sqlMapClient"><ref local="sqlMapClient"/></property>
    </bean>

    <bean id="yourDao2"
        class="com.yourpackage.dao.SameDao">
        <property name="dataSource"><ref
local="database2DataSource"/></property>
        <property name="sqlMapClient"><ref local="sqlMapClient"/></property>
    </bean>

 <bean id="yourDao3"
        class="com.yourpackage.dao.AnotherDao">
        <property name="dataSource"><ref
local="database2DataSource"/></property>
        <property name="sqlMapClient"><ref local="sqlMapClient"/></property>
    </bean>

-----------in Java ---------
/* the first 2 DAOs are the same but with the different datasource */
  SameDao yourDaoDB1 = (SameDao ) new ClassPathXmlApplicationContext(
                "your_spring_config.xml").getBean("yourDao1");

  SameDao yourDaoDB2 = (SameDao ) new ClassPathXmlApplicationContext(
                "your_spring_config.xml").getBean("yourDao2");


 AnotherDao anotherDaoDB2 = (AnotherDao) new ClassPathXmlApplicationContext(
                "your_spring_config.xml").getBean("yourDao3");

Regards,
Denis


On 5/31/06, Marrs, Kasey <Kasey.Marrs@williams.com> wrote:
>
>
>
> I have an application that uses multiple databases to pull data from.  How
> do I configure the SQL map config file and the DAO configuration to access
> multiple databases?
>
> Thanks
>
> <>< <>< <>< <>< <><
> Kasey Marrs
> 918-573-2242
> WIT Consulting Company
> ><> ><> ><> ><> ><>
>

Mime
View raw message