Announcement Announcement Module
Collapse
No announcement yet.
Load multiple iBatis SqlMap configuration files Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Load multiple iBatis SqlMap configuration files

    Hello,

    I've got following two sqlmaps configuration files:


    module-x-file:
    Code:
    <sqlMapConfig>
        <sqlMap resource="ibatis/table-keyword.xml" />
    </sqlMapConfig>
    module-y-file:
    Code:
    <sqlMapConfig>
        <sqlMap resource="ibatis/table-annotation.xml" />
        <sqlMap resource="ibatis/table-file.xml" />
        <sqlMap resource="ibatis/table-link.xml" />
        <sqlMap resource="ibatis/table-book.xml" />
        <sqlMap resource="ibatis/table-formalpublication.xml" />
    </sqlMapConfig>


    I'd like to merge these two files now. Is there a possability so that I do not have to create a file like this below?

    module-z-file:
    Code:
    <sqlMapConfig>
        <sqlMap resource="ibatis/table-keyword.xml" />
        <sqlMap resource="ibatis/table-annotation.xml" />
        <sqlMap resource="ibatis/table-file.xml" />
        <sqlMap resource="ibatis/table-link.xml" />
        <sqlMap resource="ibatis/table-book.xml" />
        <sqlMap resource="ibatis/table-formalpublication.xml" />
    </sqlMapConfig>
    This is used in a framework, where you have modules and each module is represented by a jar file. These modules are standard components like one for the security or the remoting. The idea is to be able to use such a module and you just have to know ONE (i.e. module-x-file, see above) file which has to be used when iBatis SqlMap is used.

    Could we made such an abstraction in spring?


    Thanks,
    Cheers,
    Martin

  • #2
    Did you ever find this answer?

    I'm looking to do the same thing. Is it possible to set two configLocations within the spring bean definition?

    Comment


    • #3
      Yes you can load multiple sqlMap contexts as spring beans

      See this example:

      Code:
       <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
          <property name="configLocation" value="WEB-INF/sqlmap-context.xml"/>
          <property name="dataSource" ref="dataSource"/>
        </bean>
        <bean id="mysqlcreditSqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
          <property name="configLocation" value="WEB-INF/mysql-credit-sqlmap-context.xml"/>
          <property name="dataSource" ref="mysqlcreditDataSource"/>
        </bean>
        <bean id="mysqlcreditSqlMapClientWRITE" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
          <property name="configLocation" value="WEB-INF/mysql-credit-sqlmap-context.xml"/>
          <property name="dataSource" ref="mysqlcreditDataSourceWRITE"/>
        </bean>
      We use this to access different datasources from the same app.

      Comment


      • #4
        Re: Multiple sqlMaps

        This is very useful - by separating all custom queries into separate sqlMap files, we avoid the problem of abator regeneration stepping on our queries. Thanks!

        Comment


        • #5
          dynamic data source for spring dao bean

          Hi,
          is it possible to dynamically change the data source of the DAO bean?
          I have a requirement where User need to see data from archive database instead of prod database.
          So I wanted to use same code (same query etc) but pointing to different datasource.
          Any help is highly appreciated.


          Originally posted by zebthecat View Post
          See this example:

          Code:
           <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
              <property name="configLocation" value="WEB-INF/sqlmap-context.xml"/>
              <property name="dataSource" ref="dataSource"/>
            </bean>
            <bean id="mysqlcreditSqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
              <property name="configLocation" value="WEB-INF/mysql-credit-sqlmap-context.xml"/>
              <property name="dataSource" ref="mysqlcreditDataSource"/>
            </bean>
            <bean id="mysqlcreditSqlMapClientWRITE" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
              <property name="configLocation" value="WEB-INF/mysql-credit-sqlmap-context.xml"/>
              <property name="dataSource" ref="mysqlcreditDataSourceWRITE"/>
            </bean>
          We use this to access different datasources from the same app.

          Comment

          Working...
          X