Results 1 to 3 of 3

Thread: MyBatis BATCH Executor

  1. #1
    Join Date
    Jul 2010
    Posts
    8

    Default MyBatis BATCH Executor

    Hi all,

    for first sorry for my english.

    My question is about MyBatis: I need to know if it's possibile to change the executor type (SIMPLE, BATCH) for at runtime.

    I need to set the Executor in BATCH mode for a single method in a Service Object because I need to send ~10,000 query to DB. In the rest of my project SIMPLE mode is ok.

    I'm using Mapper interface and the Mapper scanner configurer to create DAO implementations.

    Unfortunately I'm not able to find a clear documentation about this.

    Thanks in advance.

  2. #2

    Default

    You'll need to open a new session with the new executor type.

    SqlSession sqlSession = getSqlSessionFactory().openSession(ExecutorType.BA TCH);
    AdminMapper adminMapper = sqlSession.getMapper(AdminMapper.class);
    for(APXIGBean apxig : apxigList) {
    adminMapper.insertAPXIG(Integer.parseInt(apxig.get Id()));
    }
    sqlSession.flushStatements();
    sqlSession.commit();
    sqlSession.close();

  3. #3
    Join Date
    May 2012
    Posts
    1

    Default

    Hey, thanks for question. I'm looking for the same.

    Quote Originally Posted by seetasomagani View Post
    You'll need to open a new session with the new executor type.

    SqlSession sqlSession = getSqlSessionFactory().openSession(ExecutorType.BA TCH);
    AdminMapper adminMapper = sqlSession.getMapper(AdminMapper.class);
    for(APXIGBean apxig : apxigList) {
    adminMapper.insertAPXIG(Integer.parseInt(apxig.get Id()));
    }
    sqlSession.flushStatements();
    sqlSession.commit();
    sqlSession.close();

    That's correct. But how to do this via Spring and do not create batched map manually.

    Now I have

    HTML Code:
    <bean id="MyDefaultDao" class="org.mybatis.spring.mapper.MapperFactoryBean">
        <property name="mapperInterface" value="com.foo.MyInterface"/>
        <property name="sqlSessionFactory" ref="mySqlSessionFactory"/>
    </bean>
    And I want smth like this:

    HTML Code:
    <bean id="MyBatchDao" class="org.mybatis.spring.mapper.MapperFactoryBean">
        <property name="mapperInterface" value="com.foo.MyInterface"/>
        <property name="execType" value="ExecutorType.BATCH"/>
        <property name="sqlSessionFactory" ref="mySqlSessionFactory"/>
    </bean>
    And inject this to required object
    Last edited by nkukhar; May 10th, 2012 at 04:32 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
  •