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 Diran Ayandele <Ad...@Sun.COM> on 2006/02/23 23:01:36 UTC
Re: Distributed DataSources and SQL Maps
Chris, I've done a few projects with multiple datasources. Here are the
steps:
1. Create multiple contexts in dao.xml:
<daoConfig>
<context id="one">
<transactionManager type="SQLMAP">
<property name="SqlMapConfigResource"
value="sos/dao/ibatis/oneSqlMapConfig.xml"/>
</transactionManager>
<dao interface="sos.dao.OneDao"
implementation="sos.dao.ibatis.OneDaoImpl"/>
</context>
<context id="two">
<transactionManager type="SQLMAP">
<property name="SqlMapConfigResource"
value="sos/dao/ibatis/twoSqlMapConfig.xml"/>
</transactionManager>
<dao interface="sos.dao.TwoDao"
implementation="sos.dao.ibatis.TwoDaoImpl"/>
</context>
</daoConfig>
2. Create seperate sqlMapConfig files for each (to keep things clear)
<sqlMapConfig>
<settings
cacheModelsEnabled="true"
enhancementEnabled="true"
maxSessions="64"
maxTransactions="8"
maxRequests="128"
useStatementNamespaces="false"/>
<transactionManager type="JDBC">
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="${JDBC.Driver}"/>
<property name="JDBC.ConnectionURL"
value="${TWQ.JDBC.ConnectionURL}"/>
<property name="JDBC.Username" value="${TWO.JDBC.Username}"/>
<property name="JDBC.Password" value="${TWO.JDBC.Password}"/>
<property name="Pool.MaximumActiveConnections"
value="${Pool.MaximumActiveConnections}"/>
<property name="Pool.MaximumIdleConnections"
value="${Pool.MaximumIdleConnections}"/>
</dataSource>
</transactionManager>
<!-- SQLMaps go here -->
<sqlMap resource="sos/dao/ibatis/maps/Two.xml"/>
</sqlMapConfig>
3. Make your maps.
4. That's it really. You will need to use your sybase drivers...
Diran
Christopher.Mathrusse@sybase.com wrote:
>
> My problem is as follows:
>
> Customer (POJO) -> CustomerDao -> CustomerDaoImpl -> CustomerSQLMap ->
> DataSource1
>
> CustomerBilling (POJO) -> CustomerBillingDao -> CustomerBillingDaoImpl
> -> CustomerBillingSQLMap -> DataSource2
>
> CustomerBilling object has a Customer object that is accessible with a
> get method. What I would like to do in the CustomerBilling SQL Map is
> as follows:
>
> <resultMap id="CustomerBillingResult"
> class="com.sybase.cosmos.domain.CustomerBilling">
> <result column="customer_no" property="customer"
> select="Customer-findByPrimaryKey"/>
>
>
> The problem with the above SQL Map is that when the
> Customer-findByPrimaryKey is invoked it is trying to use *DataSource2
> *associated with the CustomerBillingDao, not *DataSource1 *associated
> with the CustomerDao, so I get an exception because the table does not
> exist within the CustomerBillingDao DataSource.
>
> How can I tell iBatis to use the correct DataSource for this query?
>
> Thanks very much....
>
> Chris Mathrusse
> christopher.mathrusse@sybase.com
> Sybase, Inc
> One Sybase Drive
> Dublin, CA 94568
> (925) 236-5553