Announcement Announcement Module
Collapse
No announcement yet.
Multiple DataSources question Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Multiple DataSources question

    I'm writing an app that will use two data sources - a data source to the primary database that will involve read/write operations, and a data source to a second database for read operations only.

    Given this scenario does it make sense to configure a transaction manager for the first data source, but not for the second? For example, I was thinking dataAccessContext.xml would look something like this:

    -------------------------------------
    <beans>

    <bean id="primaryDataSource" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName"><value>jdbc/ChargeAdminDS</value></property>
    </bean>

    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
    <property name="dataSource"><ref local="primaryDataSource"/></property>
    </bean>

    <bean id="readonlyDataSource" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName"><value>jdbc/AccountsDS</value></property>
    </bean>

    <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClient FactoryBean">
    <property name="configLocation"><value>WEB-INF/sql-map-config.xml</value></property>
    </bean>

    <!-- ============== DAO Definitions for primaryDataSource ============= -->

    <bean id="chargeDao" class="nz.ac.otago.its.chargeadmin.dao.ibatis.SqlM apChargeDao">
    <property name="dataSource"><ref local="primaryDataSource"/></property>
    <property name="sqlMapClient"><ref local="sqlMapClient"/></property>
    </bean>

    [etc]

    <!-- ============== DAO Definition for readonlyDataSource ============= -->

    <bean id="accountsDao" class="nz.ac.otago.its.chargeadmin.dao.ibatis.SqlM apAccountsDao">
    <property name="dataSource"><ref local="readonlyDataSource"/></property>
    <property name="sqlMapClient"><ref local="sqlMapClient"/></property>
    </bean>

    </beans>
    -------------------------------------

    In applicationContext.xml I have a single business object bean that is
    wrapped by an outer transactional proxy (as in the JPetstore demo) for the "transactionManager" bean defined above. Is it ok for a method in this business object to invoke calls to BOTH data sources (via DAOs that are set via dependency injection)? I trust that the transactionManager bean would let the calls to the readonly datasource proceed without interferring? Or is there a better way of architecting this?

    Thanks in advance ...

    Steve

  • #2
    This should work OK. The transaction manager only manage the database you configure for it.

    Comment

    Working...
    X