You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Aleksey Masny <pr...@gmail.com> on 2009/12/17 15:29:07 UTC

How to use multiple dataSource in camel.iBatis?

I use Camel and iBatis component. And i need pool data in one database,
transform it and insert to another database. 

Therefore I have two different SqlMapConfig*.xml files (SqlMapConfigWMS.xml
and SqlMapConfigJDE.xml) in  src/resources directory. SqlMapConfigWMS.xml
includes link to WMS_selectMissingBoms statement and SqlMapConfigJDE.xml
includes link to JDE_testInsert statement. 

My route:

from("ibatis:WMS_selectMissingBoms?" +
        		"maxMessagesPerPoll=1&" +
        		"initialDelay=1000&" +
        		"delay=60000").//pool in one database
        	to("bean:helper?method=mapBomToEvent").//transform
        	to("ibatis:JDE_testInsert?statementType=Insert")//insert to another
database

But iBatis component uses only one, first found or default SqlMapConfig.xml.
Therefore camel-ibatis throw exception
com.ibatis.sqlmap.client.SqlMapException: There is no statement named
JDE_testInsert in this SqlMap.

I think, for resolve this problem I can use two ibatis istanсes and
configure its with different SqlMapConfig*.xml files? For example
"ibatis_WMS" and "ibatis_JDE", and use this id in endpoint url? But how
manualy create instance ibatis component with predefined configuration file?

Or do you know of any other solution?

Thank you and best regards, 
Aleksey Masny.
-- 
View this message in context: http://old.nabble.com/How-to-use-multiple-dataSource-in-camel.iBatis--tp26828799p26828799.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: How to use multiple dataSource in camel.iBatis?

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Dec 18, 2009 at 9:30 AM, Aleksey Masny <pr...@gmail.com> wrote:
>
> Glaus, many thanks!
>
> Now (before 2.2.0 release) I modified dependency to camel-ibatis on (in
> pom.xml):
>    <dependency>
>      <groupId>org.apache.camel</groupId>
>      <artifactId>camel-ibatis</artifactId>
>      <version>2.2-SNAPSHOT</version>
>    </dependency>
>
> Added snapshot repository (in pom.xml):
>  <repositories>
>    <repository>
>      <id>snaphot-repo</id>
>
> <url>https://repository.apache.org/content/repositories/snapshots/</url>
>    </repository>
>  </repositories>
>
> And manualy identified the configuration file for IBatis (in
> camel-context.xml):
>  <bean id="JDEdb"
> class="org.apache.camel.component.ibatis.IBatisComponent">
>     <property name="sqlMapConfig" value="classpath:WMS_SqlMapConfig.xml2"/>
>  </bean>
>
> And here's my route, for example.
> from("timer://start?fixedRate=true&period=10000").//
>           to("bean:helper?method=genEvent").//
>           to("JDEdb:testInsert?statementType=Insert");//
>
> It works!
>
> Camel it's a obedient camel :)

Great that is good news.

Yeah we have tamed that wild Camel many years ago. This Camel is
willingly and loves its community and its riders!


> --
> View this message in context: http://old.nabble.com/How-to-use-multiple-dataSource-in-camel.iBatis--tp26828799p26840495.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: How to use multiple dataSource in camel.iBatis?

Posted by Aleksey Masny <pr...@gmail.com>.
Glaus, many thanks!

Now (before 2.2.0 release) I modified dependency to camel-ibatis on (in
pom.xml):
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-ibatis</artifactId>
      <version>2.2-SNAPSHOT</version>
    </dependency>

Added snapshot repository (in pom.xml): 
  <repositories>
    <repository>
      <id>snaphot-repo</id>
     
<url>https://repository.apache.org/content/repositories/snapshots/</url>
    </repository>
  </repositories>

And manualy identified the configuration file for IBatis (in
camel-context.xml):
  <bean id="JDEdb"
class="org.apache.camel.component.ibatis.IBatisComponent">
     <property name="sqlMapConfig" value="classpath:WMS_SqlMapConfig.xml2"/>
  </bean>

And here's my route, for example. 
from("timer://start?fixedRate=true&period=10000").//
    	   to("bean:helper?method=genEvent").//
    	   to("JDEdb:testInsert?statementType=Insert");//

It works!

Camel it's a obedient camel :)
-- 
View this message in context: http://old.nabble.com/How-to-use-multiple-dataSource-in-camel.iBatis--tp26828799p26840495.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: How to use multiple dataSource in camel.iBatis?

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Dec 17, 2009 at 4:59 PM, Claus Ibsen <cl...@gmail.com> wrote:
> On Thu, Dec 17, 2009 at 4:55 PM, Aleksey Masny <pr...@gmail.com> wrote:
>>
>> Statement from any <sqlMap> in the same SqlMapConfig.xml will execute in same
>> database, yes?
>> But i'd like execute statment in another database. In one DB - pooling, then
>> insert to another DB.
>>
>
> Ah then define 2 ibatis components them
>
> <bean id="ibatis1" class="org.apache.camel.component.ibatis.IbatisComponent">
>   <property name="sqlMapClient" ref="client1"/>
> </bean>
>
> <bean id="ibatis2" class="org.apache.camel.component.ibatis.IbatisComponent">
> <property name="sqlMapClient" ref="client2"/>
> </bean>
>

Sorry it appears that in Camel 2.1 or older you need a bit more leg
work to configure to use 2 different components with different
SqlMapConfigt.xml files.

I have changed that in 2.2 so you can set the name of this file directly.

 <property name="sqlMapConfig" value="classpath:MySecondSqlMapConfig.xml"/>



>
> And then use ibatis1 and ibatis2 in the camel urls.
>
>
>
>>
>> --
>> View this message in context: http://old.nabble.com/How-to-use-multiple-dataSource-in-camel.iBatis--tp26828799p26830215.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>
>
>
> --
> Claus Ibsen
> Apache Camel Committer
>
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: How to use multiple dataSource in camel.iBatis?

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Dec 17, 2009 at 4:55 PM, Aleksey Masny <pr...@gmail.com> wrote:
>
> Statement from any <sqlMap> in the same SqlMapConfig.xml will execute in same
> database, yes?
> But i'd like execute statment in another database. In one DB - pooling, then
> insert to another DB.
>

Ah then define 2 ibatis components them

<bean id="ibatis1" class="org.apache.camel.component.ibatis.IbatisComponent">
   <property name="sqlMapClient" ref="client1"/>
</bean>

<bean id="ibatis2" class="org.apache.camel.component.ibatis.IbatisComponent">
<property name="sqlMapClient" ref="client2"/>
</bean>


And then use ibatis1 and ibatis2 in the camel urls.



>
> --
> View this message in context: http://old.nabble.com/How-to-use-multiple-dataSource-in-camel.iBatis--tp26828799p26830215.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: How to use multiple dataSource in camel.iBatis?

Posted by Aleksey Masny <pr...@gmail.com>.
Statement from any <sqlMap> in the same SqlMapConfig.xml will execute in same
database, yes?
But i'd like execute statment in another database. In one DB - pooling, then
insert to another DB.


-- 
View this message in context: http://old.nabble.com/How-to-use-multiple-dataSource-in-camel.iBatis--tp26828799p26830215.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: How to use multiple dataSource in camel.iBatis?

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Dec 17, 2009 at 3:29 PM, Aleksey Masny <pr...@gmail.com> wrote:
>
> I use Camel and iBatis component. And i need pool data in one database,
> transform it and insert to another database.
>
> Therefore I have two different SqlMapConfig*.xml files (SqlMapConfigWMS.xml
> and SqlMapConfigJDE.xml) in  src/resources directory. SqlMapConfigWMS.xml
> includes link to WMS_selectMissingBoms statement and SqlMapConfigJDE.xml
> includes link to JDE_testInsert statement.
>
> My route:
>
> from("ibatis:WMS_selectMissingBoms?" +
>                        "maxMessagesPerPoll=1&" +
>                        "initialDelay=1000&" +
>                        "delay=60000").//pool in one database
>                to("bean:helper?method=mapBomToEvent").//transform
>                to("ibatis:JDE_testInsert?statementType=Insert")//insert to another
> database
>
> But iBatis component uses only one, first found or default SqlMapConfig.xml.
> Therefore camel-ibatis throw exception
> com.ibatis.sqlmap.client.SqlMapException: There is no statement named
> JDE_testInsert in this SqlMap.
>
> I think, for resolve this problem I can use two ibatis istanсes and
> configure its with different SqlMapConfig*.xml files? For example
> "ibatis_WMS" and "ibatis_JDE", and use this id in endpoint url? But how
> manualy create instance ibatis component with predefined configuration file?
>
> Or do you know of any other solution?
>

Hi

I think you can refer to other xml files in the default SqlMapConfig.xml file

for example from this
https://svn.apache.org/repos/asf/camel/trunk/components/camel-ibatis/src/test/resources/SqlMapConfig.xml

You got this line
  <sqlMap resource="org/apache/camel/component/ibatis/Account.xml"/>

You can just add another <sqlMap> for other files.



> Thank you and best regards,
> Aleksey Masny.
> --
> View this message in context: http://old.nabble.com/How-to-use-multiple-dataSource-in-camel.iBatis--tp26828799p26828799.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus