Results 1 to 5 of 5

Thread: Load multiple iBatis SqlMap configuration files

  1. #1
    Join Date
    Nov 2004
    Location
    Zurich [CH]
    Posts
    14

    Default 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. #2
    Join Date
    Sep 2008
    Posts
    4

    Default 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?

  3. #3

    Default 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.

  4. #4
    Join Date
    Sep 2008
    Posts
    4

    Default 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!

  5. #5
    Join Date
    Mar 2012
    Posts
    3

    Default 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.


    Quote 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.

Similar Threads

  1. Replies: 12
    Last Post: Oct 30th, 2010, 12:26 AM
  2. Reusable 'Module' configuration files?
    By zanfolim in forum Architecture
    Replies: 6
    Last Post: Sep 28th, 2006, 06:52 AM
  3. iBatis lazy load transaction issues.
    By efpiva in forum Data
    Replies: 3
    Last Post: Jun 22nd, 2005, 06:20 PM
  4. multiple xml configuration files
    By egauthier in forum Container
    Replies: 10
    Last Post: Sep 23rd, 2004, 12:16 PM
  5. Replies: 2
    Last Post: Aug 28th, 2004, 04:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •