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 Bhaarat Sharma <bh...@gmail.com> on 2009/05/01 20:09:42 UTC
how to have two datasources in sql-map-config.xml
Hi
Currently our sql-map-config looks like this:
<sqlMapConfig>
<settings enhancementEnabled="true" useStatementNamespaces="true" />
<transactionManager type="JDBC">
<dataSource type="JNDI">
<property name="DataSource" value="jdbc/RSGH/IJA/twy/ftwdb" />
</dataSource>
</transactionManager>
<sqlMap resource="existingSearch.xml" />
<sqlMap resource="deceased_search.xml"/>
<sqlMap resource="multiLoanSearch.xml"/>
</sqlMapConfig>
In the above we only have one JDBC connection and this connection goes to a
SQL Server. However, now we will have to access another DB which is in
Oracle. So we will have to create another JDBC connection and have some of
our sqlMaps reference that NEW JDBC connection. Can this be done in iBatis?
can we have multiple data sources, and if so, then how do
we differentiate which DB a sqlMap references.
Thanks!
Re: how to have two datasources in sql-map-config.xml
Posted by Warren Bell <wa...@gmail.com>.
I have objects that are made up of data from two different datasources.
I am currently using spring and my configuration is like that below. I
guess this is a design question, but I have always constructed these
type of objects in a service layer. It doesn't look like you can access
two data sources from 1 dao or if you should even do this. Does it make
sense to construct these type of objects in one DAO? Or should the DAOs
be tied to one datasource and stricly return one object?
I guess what I am asking is, what is the best way to construct an object
that is made up from two different datasources? And should the
construction of an object be completed in the DAO?
Warren
Brandon Goodin wrote:
> You are correct.
>
> Brandon Goodin
>
> On Fri, May 1, 2009 at 1:48 PM, Srinivas Doddi <Srinivas_Doddi@gap.com
> <ma...@gap.com>> wrote:
>
> We were using two separate Sql Map Configuration files for this
> kind of scenario. In IBATIS, I guess there is no way of
> specifying two different Sql maps clients in a single
> configuration file. ( Correct me, if I am wrong)
>
>
>
> Thank you.
>
>
>
> **SRINIVAS DODDI**
>
> ------------------------------------------------------------------------
>
> *From:* Bhaarat Sharma [mailto:bhaarat.s@gmail.com
> <ma...@gmail.com>]
> *Sent:* Friday, May 01, 2009 2:24 PM
> *To:* user-java@ibatis.apache.org <ma...@ibatis.apache.org>
> *Subject:* Re: how to have two datasources in sql-map-config.xml
>
>
>
> also, we have a spring-for-ibatis.xml file where we have code like
> this
>
>
>
> <bean id="IbatisDataSource"
> class="org.springframework.jndi.JndiObjectFactoryBean">
>
> <property name="jndiName" value="jdbc/RSGH/IJA/twy/ftwdb"/>
>
> </bean>
>
>
>
> <bean id="BTHSqlMapClient"
> class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
>
> <property name="configLocation"
> value="classpath:sql-map-config.xml"/>
>
> <property name="dataSource" ref="IbatisDataSource"/>
>
> </bean>
>
>
>
> <bean id="UsageIfaceDAO"
> class="biv.data.dao.reports.auditreports.UsageReportDAO">
>
> <property name="sqlMapClient" ref="BTHSqlMapClient"/>
>
> <property name="dataSource" ref="IbatisDataSource"/>
>
> </bean>
>
>
>
> so can I then just add another bean with jndi like this:
>
> <bean id="IbatisDataSource2"
> class="org.springframework.jndi.JndiObjectFactoryBean">
>
> <property name="jndiName"
> value="jdbc/RSGH/IJA/twy/<mynewDBNAME>"/>
>
> </bean>
>
>
>
> then another bean for sql-map-client (I will have to make another
> xml right? say sql-map-client1.xml)
>
> <bean id="BTHSqlMapClient1"
> class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
>
> <property name="configLocation"
> value="classpath:sql-map-config1.xml"/>
>
> <property name="dataSource" ref="IbatisDataSource"/>
>
> </bean>
>
>
>
> and then start registering my DAO's like this
>
> <bean id="SomeNewDAO"
> class="biv.data.dao.reports.auditreports.SomeReportDAO">
>
> <property name="sqlMapClient" ref="BTHSqlMapClient1"/>
>
> <property name="dataSource" ref="IbatisDataSource"/>
>
> </bean>
>
>
>
> Thanks
>
> -bhaarat
>
> On Fri, May 1, 2009 at 2:09 PM, Bhaarat Sharma
> <bhaarat.s@gmail.com <ma...@gmail.com>> wrote:
>
> Hi
>
>
>
> Currently our sql-map-config looks like this:
>
>
>
> <sqlMapConfig>
>
> <settings enhancementEnabled="true"
> useStatementNamespaces="true" />
>
> <transactionManager type="JDBC">
>
> <dataSource type="JNDI">
>
> <property name="DataSource"
> value="jdbc/RSGH/IJA/twy/ftwdb" />
>
> </dataSource>
>
> </transactionManager>
>
>
>
> <sqlMap resource="existingSearch.xml" />
>
> <sqlMap resource="deceased_search.xml"/>
>
> <sqlMap resource="multiLoanSearch.xml"/>
>
> </sqlMapConfig>
>
>
>
> In the above we only have one JDBC connection and this connection
> goes to a SQL Server. However, now we will have to access another
> DB which is in Oracle. So we will have to create another JDBC
> connection and have some of our sqlMaps reference that NEW JDBC
> connection. Can this be done in iBatis? can we have multiple data
> sources, and if so, then how do we differentiate which DB a sqlMap
> references.
>
>
>
> Thanks!
>
>
>
>
--
Thanks,
Warren Bell
909-645-8864
warrenbell2@gmail.com
Re: how to have two datasources in sql-map-config.xml
Posted by Brandon Goodin <br...@gmail.com>.
You are correct.
Brandon Goodin
On Fri, May 1, 2009 at 1:48 PM, Srinivas Doddi <Sr...@gap.com>wrote:
> We were using two separate Sql Map Configuration files for this kind of
> scenario. In IBATIS, I guess there is no way of specifying two different
> Sql maps clients in a single configuration file. ( Correct me, if I am
> wrong)
>
>
>
> Thank you.
>
>
>
> *SRINIVAS DODDI*
> ------------------------------
>
> *From:* Bhaarat Sharma [mailto:bhaarat.s@gmail.com]
> *Sent:* Friday, May 01, 2009 2:24 PM
> *To:* user-java@ibatis.apache.org
> *Subject:* Re: how to have two datasources in sql-map-config.xml
>
>
>
> also, we have a spring-for-ibatis.xml file where we have code like this
>
>
>
> <bean id="IbatisDataSource"
> class="org.springframework.jndi.JndiObjectFactoryBean">
>
> <property name="jndiName" value="jdbc/RSGH/IJA/twy/ftwdb"/>
>
> </bean>
>
>
>
> <bean id="BTHSqlMapClient"
> class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
>
> <property name="configLocation" value="classpath:sql-map-config.xml"/>
>
> <property name="dataSource" ref="IbatisDataSource"/>
>
> </bean>
>
>
>
> <bean id="UsageIfaceDAO"
> class="biv.data.dao.reports.auditreports.UsageReportDAO">
>
> <property name="sqlMapClient" ref="BTHSqlMapClient"/>
>
> <property name="dataSource" ref="IbatisDataSource"/>
>
> </bean>
>
>
>
> so can I then just add another bean with jndi like this:
>
> <bean id="IbatisDataSource2"
> class="org.springframework.jndi.JndiObjectFactoryBean">
>
> <property name="jndiName" value="jdbc/RSGH/IJA/twy/<mynewDBNAME>"/>
>
> </bean>
>
>
>
> then another bean for sql-map-client (I will have to make another xml
> right? say sql-map-client1.xml)
>
> <bean id="BTHSqlMapClient1"
> class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
>
> <property name="configLocation" value="classpath:sql-map-config1.xml"/>
>
> <property name="dataSource" ref="IbatisDataSource"/>
>
> </bean>
>
>
>
> and then start registering my DAO's like this
>
> <bean id="SomeNewDAO"
> class="biv.data.dao.reports.auditreports.SomeReportDAO">
>
> <property name="sqlMapClient" ref="BTHSqlMapClient1"/>
>
> <property name="dataSource" ref="IbatisDataSource"/>
>
> </bean>
>
>
>
> Thanks
>
> -bhaarat
>
> On Fri, May 1, 2009 at 2:09 PM, Bhaarat Sharma <bh...@gmail.com>
> wrote:
>
> Hi
>
>
>
> Currently our sql-map-config looks like this:
>
>
>
> <sqlMapConfig>
>
> <settings enhancementEnabled="true" useStatementNamespaces="true" />
>
> <transactionManager type="JDBC">
>
> <dataSource type="JNDI">
>
> <property name="DataSource"
> value="jdbc/RSGH/IJA/twy/ftwdb" />
>
> </dataSource>
>
> </transactionManager>
>
>
>
> <sqlMap resource="existingSearch.xml" />
>
> <sqlMap resource="deceased_search.xml"/>
>
> <sqlMap resource="multiLoanSearch.xml"/>
>
> </sqlMapConfig>
>
>
>
> In the above we only have one JDBC connection and this connection goes to a
> SQL Server. However, now we will have to access another DB which is in
> Oracle. So we will have to create another JDBC connection and have some of
> our sqlMaps reference that NEW JDBC connection. Can this be done in iBatis?
> can we have multiple data sources, and if so, then how do
> we differentiate which DB a sqlMap references.
>
>
>
> Thanks!
>
>
>
RE: how to have two datasources in sql-map-config.xml
Posted by Srinivas Doddi <Sr...@gap.com>.
We were using two separate Sql Map Configuration files for this kind of
scenario. In IBATIS, I guess there is no way of specifying two
different Sql maps clients in a single configuration file. ( Correct
me, if I am wrong)
Thank you.
SRINIVAS DODDI
________________________________
From: Bhaarat Sharma [mailto:bhaarat.s@gmail.com]
Sent: Friday, May 01, 2009 2:24 PM
To: user-java@ibatis.apache.org
Subject: Re: how to have two datasources in sql-map-config.xml
also, we have a spring-for-ibatis.xml file where we have code like this
<bean id="IbatisDataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/RSGH/IJA/twy/ftwdb"/>
</bean>
<bean id="BTHSqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="classpath:sql-map-config.xml"/>
<property name="dataSource" ref="IbatisDataSource"/>
</bean>
<bean id="UsageIfaceDAO"
class="biv.data.dao.reports.auditreports.UsageReportDAO">
<property name="sqlMapClient" ref="BTHSqlMapClient"/>
<property name="dataSource" ref="IbatisDataSource"/>
</bean>
so can I then just add another bean with jndi like this:
<bean id="IbatisDataSource2"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/RSGH/IJA/twy/<mynewDBNAME>"/>
</bean>
then another bean for sql-map-client (I will have to make another xml
right? say sql-map-client1.xml)
<bean id="BTHSqlMapClient1"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation"
value="classpath:sql-map-config1.xml"/>
<property name="dataSource" ref="IbatisDataSource"/>
</bean>
and then start registering my DAO's like this
<bean id="SomeNewDAO"
class="biv.data.dao.reports.auditreports.SomeReportDAO">
<property name="sqlMapClient" ref="BTHSqlMapClient1"/>
<property name="dataSource" ref="IbatisDataSource"/>
</bean>
Thanks
-bhaarat
On Fri, May 1, 2009 at 2:09 PM, Bhaarat Sharma <bh...@gmail.com>
wrote:
Hi
Currently our sql-map-config looks like this:
<sqlMapConfig>
<settings enhancementEnabled="true" useStatementNamespaces="true" />
<transactionManager type="JDBC">
<dataSource type="JNDI">
<property name="DataSource"
value="jdbc/RSGH/IJA/twy/ftwdb" />
</dataSource>
</transactionManager>
<sqlMap resource="existingSearch.xml" />
<sqlMap resource="deceased_search.xml"/>
<sqlMap resource="multiLoanSearch.xml"/>
</sqlMapConfig>
In the above we only have one JDBC connection and this connection goes
to a SQL Server. However, now we will have to access another DB which
is in Oracle. So we will have to create another JDBC connection and
have some of our sqlMaps reference that NEW JDBC connection. Can this
be done in iBatis? can we have multiple data sources, and if so, then
how do we differentiate which DB a sqlMap references.
Thanks!
Re: how to have two datasources in sql-map-config.xml
Posted by Bhaarat Sharma <bh...@gmail.com>.
also, we have a spring-for-ibatis.xml file where we have code like this
<bean id="IbatisDataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/RSGH/IJA/twy/ftwdb"/>
</bean>
<bean id="BTHSqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="classpath:sql-map-config.xml"/>
<property name="dataSource" ref="IbatisDataSource"/>
</bean>
<bean id="UsageIfaceDAO"
class="biv.data.dao.reports.auditreports.UsageReportDAO">
<property name="sqlMapClient" ref="BTHSqlMapClient"/>
<property name="dataSource" ref="IbatisDataSource"/>
</bean>
so can I then just add another bean with jndi like this:
<bean id="IbatisDataSource2"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/RSGH/IJA/twy/<mynewDBNAME>"/>
</bean>
then another bean for sql-map-client (I will have to make another xml right?
say sql-map-client1.xml)
<bean id="BTHSqlMapClient1"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="classpath:sql-map-config1.xml"/>
<property name="dataSource" ref="IbatisDataSource"/>
</bean>
and then start registering my DAO's like this
<bean id="SomeNewDAO"
class="biv.data.dao.reports.auditreports.SomeReportDAO">
<property name="sqlMapClient" ref="BTHSqlMapClient1"/>
<property name="dataSource" ref="IbatisDataSource"/>
</bean>
Thanks
-bhaarat
On Fri, May 1, 2009 at 2:09 PM, Bhaarat Sharma <bh...@gmail.com> wrote:
> Hi
> Currently our sql-map-config looks like this:
>
> <sqlMapConfig>
> <settings enhancementEnabled="true" useStatementNamespaces="true" />
> <transactionManager type="JDBC">
> <dataSource type="JNDI">
> <property name="DataSource" value="jdbc/RSGH/IJA/twy/ftwdb" />
> </dataSource>
> </transactionManager>
> <sqlMap resource="existingSearch.xml" />
> <sqlMap resource="deceased_search.xml"/>
> <sqlMap resource="multiLoanSearch.xml"/>
> </sqlMapConfig>
>
> In the above we only have one JDBC connection and this connection goes to a
> SQL Server. However, now we will have to access another DB which is in
> Oracle. So we will have to create another JDBC connection and have some of
> our sqlMaps reference that NEW JDBC connection. Can this be done in iBatis?
> can we have multiple data sources, and if so, then how do
> we differentiate which DB a sqlMap references.
>
> Thanks!
>
Re: how to have two datasources in sql-map-config.xml
Posted by Brandon Goodin <br...@gmail.com>.
Hey Bhaarat,
The example you provided is the approach I would take in your situation.
Brandon Goodin
On Fri, May 1, 2009 at 1:25 PM, Bhaarat Sharma <bh...@gmail.com> wrote:
> Brandon,
> I think your reply came as I was tying up my reply. Please check out my
> second reply to see if that makes sense.
>
> Thanks
>
>
> On Fri, May 1, 2009 at 2:21 PM, Brandon Goodin <br...@gmail.com>wrote:
>
>> Why not create a separate SqlMapClient for the Oracle database?
>>
>> Brandon Goodin
>>
>>
>>
>> On Fri, May 1, 2009 at 1:09 PM, Bhaarat Sharma <bh...@gmail.com>wrote:
>>
>>> Hi
>>> Currently our sql-map-config looks like this:
>>>
>>> <sqlMapConfig>
>>> <settings enhancementEnabled="true" useStatementNamespaces="true" />
>>> <transactionManager type="JDBC">
>>> <dataSource type="JNDI">
>>> <property name="DataSource" value="jdbc/RSGH/IJA/twy/ftwdb" />
>>> </dataSource>
>>> </transactionManager>
>>> <sqlMap resource="existingSearch.xml" />
>>> <sqlMap resource="deceased_search.xml"/>
>>> <sqlMap resource="multiLoanSearch.xml"/>
>>> </sqlMapConfig>
>>>
>>> In the above we only have one JDBC connection and this connection goes to
>>> a SQL Server. However, now we will have to access another DB which is in
>>> Oracle. So we will have to create another JDBC connection and have some of
>>> our sqlMaps reference that NEW JDBC connection. Can this be done in iBatis?
>>> can we have multiple data sources, and if so, then how do
>>> we differentiate which DB a sqlMap references.
>>>
>>> Thanks!
>>>
>>
>>
>
Re: how to have two datasources in sql-map-config.xml
Posted by Bhaarat Sharma <bh...@gmail.com>.
Brandon,
I think your reply came as I was tying up my reply. Please check out my
second reply to see if that makes sense.
Thanks
On Fri, May 1, 2009 at 2:21 PM, Brandon Goodin <br...@gmail.com>wrote:
> Why not create a separate SqlMapClient for the Oracle database?
>
> Brandon Goodin
>
>
>
> On Fri, May 1, 2009 at 1:09 PM, Bhaarat Sharma <bh...@gmail.com>wrote:
>
>> Hi
>> Currently our sql-map-config looks like this:
>>
>> <sqlMapConfig>
>> <settings enhancementEnabled="true" useStatementNamespaces="true" />
>> <transactionManager type="JDBC">
>> <dataSource type="JNDI">
>> <property name="DataSource" value="jdbc/RSGH/IJA/twy/ftwdb" />
>> </dataSource>
>> </transactionManager>
>> <sqlMap resource="existingSearch.xml" />
>> <sqlMap resource="deceased_search.xml"/>
>> <sqlMap resource="multiLoanSearch.xml"/>
>> </sqlMapConfig>
>>
>> In the above we only have one JDBC connection and this connection goes to
>> a SQL Server. However, now we will have to access another DB which is in
>> Oracle. So we will have to create another JDBC connection and have some of
>> our sqlMaps reference that NEW JDBC connection. Can this be done in iBatis?
>> can we have multiple data sources, and if so, then how do
>> we differentiate which DB a sqlMap references.
>>
>> Thanks!
>>
>
>
Re: how to have two datasources in sql-map-config.xml
Posted by Brandon Goodin <br...@gmail.com>.
Why not create a separate SqlMapClient for the Oracle database?
Brandon Goodin
On Fri, May 1, 2009 at 1:09 PM, Bhaarat Sharma <bh...@gmail.com> wrote:
> Hi
> Currently our sql-map-config looks like this:
>
> <sqlMapConfig>
> <settings enhancementEnabled="true" useStatementNamespaces="true" />
> <transactionManager type="JDBC">
> <dataSource type="JNDI">
> <property name="DataSource" value="jdbc/RSGH/IJA/twy/ftwdb" />
> </dataSource>
> </transactionManager>
> <sqlMap resource="existingSearch.xml" />
> <sqlMap resource="deceased_search.xml"/>
> <sqlMap resource="multiLoanSearch.xml"/>
> </sqlMapConfig>
>
> In the above we only have one JDBC connection and this connection goes to a
> SQL Server. However, now we will have to access another DB which is in
> Oracle. So we will have to create another JDBC connection and have some of
> our sqlMaps reference that NEW JDBC connection. Can this be done in iBatis?
> can we have multiple data sources, and if so, then how do
> we differentiate which DB a sqlMap references.
>
> Thanks!
>