geek.shrek
Mar 24th, 2010, 06:16 PM
Hi,
I have a scenario to synchronize multiple database of different type (SQL Server, MySQL, etc)
I have 1 main source then I need to distribute the data to multiple DB.
I wanted to use transaction management so I can roll back when there's an error.
I have problem organising the multiple connection with transaction manager.
Here is my applicationContext.xml at the moment.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<tx:annotation-driven/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerD ataSource">
<property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver" />
<property name="url" value="jdbc:derby://localhost:1527/bookshop;databaseName=DBMAIN;create=true" />
<property name="username" value="app" />
<property name="password" value="app" />
</bean>
<bean id="dataSource2" class="org.springframework.jdbc.datasource.DriverManagerD ataSource">
<property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver" />
<property name="url" value="jdbc:derby://localhost:1456/bookshop;databaseName=DBBACK;create=true" />
<property name="username" value="app" />
<property name="password" value="app" />
</bean>
<bean id="dataSource3" class="org.springframework.jdbc.datasource.DriverManagerD ataSource">
<property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver" />
<property name="url" value="jdbc:derby://localhost:5656/bookshop;databaseName=DBBACK2;create=true" />
<property name="username" value="app" />
<property name="password" value="app" />
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTran sactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="transactionTemplate" class="org.springframework.transaction.support.Transactio nTemplate">
<property name="transactionManager" ref="transactionManager"/>
</bean>
<bean id="bookShop" class="com.apress.springrecipes.bookshop.JdbcBookShop">
<property name="dataSource" ref="dataSource" />
</bean>
</beans>
/**
This class holds the main data
**/
public class JdbcBookShop extends JdbcDaoSupport implements BookShop
{
private List<BOOKS> books;
}
I was thinking to have another object that using "books" object and synchronise to dataSource2 and dataSource3. :confused:
but I have no idea how to manage this transaction with the transactionManager, because it will
different datasouce.
Can someone please give me an idea or example on how to use it?
Thanks,
I have a scenario to synchronize multiple database of different type (SQL Server, MySQL, etc)
I have 1 main source then I need to distribute the data to multiple DB.
I wanted to use transaction management so I can roll back when there's an error.
I have problem organising the multiple connection with transaction manager.
Here is my applicationContext.xml at the moment.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<tx:annotation-driven/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerD ataSource">
<property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver" />
<property name="url" value="jdbc:derby://localhost:1527/bookshop;databaseName=DBMAIN;create=true" />
<property name="username" value="app" />
<property name="password" value="app" />
</bean>
<bean id="dataSource2" class="org.springframework.jdbc.datasource.DriverManagerD ataSource">
<property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver" />
<property name="url" value="jdbc:derby://localhost:1456/bookshop;databaseName=DBBACK;create=true" />
<property name="username" value="app" />
<property name="password" value="app" />
</bean>
<bean id="dataSource3" class="org.springframework.jdbc.datasource.DriverManagerD ataSource">
<property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver" />
<property name="url" value="jdbc:derby://localhost:5656/bookshop;databaseName=DBBACK2;create=true" />
<property name="username" value="app" />
<property name="password" value="app" />
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTran sactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="transactionTemplate" class="org.springframework.transaction.support.Transactio nTemplate">
<property name="transactionManager" ref="transactionManager"/>
</bean>
<bean id="bookShop" class="com.apress.springrecipes.bookshop.JdbcBookShop">
<property name="dataSource" ref="dataSource" />
</bean>
</beans>
/**
This class holds the main data
**/
public class JdbcBookShop extends JdbcDaoSupport implements BookShop
{
private List<BOOKS> books;
}
I was thinking to have another object that using "books" object and synchronise to dataSource2 and dataSource3. :confused:
but I have no idea how to manage this transaction with the transactionManager, because it will
different datasouce.
Can someone please give me an idea or example on how to use it?
Thanks,