You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Eugeny N Dzhurinsky <bo...@redwerk.com> on 2006/07/31 13:36:47 UTC

connections to different databases

Hello!
Is it possible somehow to use several databases for single SqlMapClient
instance?

For example, I would like to use queries in namespace "spider" to be executed
on MySQL, and queries in the reset namepaces to be executed on PostgreSQL, w/o
creating 2 instances of SQL map clients.

-- 
Eugene N Dzhurinsky

Re: connections to different databases

Posted by Gwyn Evans <gw...@gmail.com>.
It certainly looks so - I've only got a Spring setup, though...
e.g.
    <bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName"><value>${jndi.name}</value></property>
    </bean>

    <bean id="sqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
        <property name="configLocation" value="classpath:sqlMapConfig.xml"/>
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <!-- setup dao implemations -->
    <bean id="adminDaoImpl" class="package.dao.impl.AdminDaoImpl">
        <property name="sqlMapClient" ref="sqlMapClient"/>
    </bean>
    <bean id="configDaoImpl" class="package.dao.impl.ConfigDaoImpl">
        <property name="sqlMapClient" ref="sqlMapClient"/>
    </bean>

In the above, I'm using a shared dataSource, but the DaoImpls extend
Spring's SqlMapClientDaoSupport, which also supports a "dataSource"
property, so I'd expect to be able to remove it from the
"sqlMapClient" bean and add Dao-specific ones to the DaoImpl beans.

/Gwyn

On 31/07/06, Eugeny N Dzhurinsky <bo...@redwerk.com> wrote:
> Hello!
> Is it possible somehow to use several databases for single SqlMapClient
> instance?
>
> For example, I would like to use queries in namespace "spider" to be executed
> on MySQL, and queries in the reset namepaces to be executed on PostgreSQL, w/o
> creating 2 instances of SQL map clients.
>
> --
> Eugene N Dzhurinsky
>