Announcement Announcement Module
Collapse
No announcement yet.
MyBatis BATCH Executor Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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();

    Comment


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

      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, 04:32 AM.

      Comment

      Working...
      X