Batch Update 기능

2013. 6. 27. 18:32OpenSource/Mybatis&Ibatis

반응형

 

Batch Update 기능 이란?
업무를 처리하는 웹 어플리케이션에서는 Insert, Update, Delete와 같은 Transactional 데이터 처리(OLTP)가 빈번하게 발생 한다. OLTP에 대한 대용량의 데이터 요청이 발생하면, 한번의 데이터 Connection으로 다수의 쿼리(설정된 쿼리의 개수)를 처리 하여 Connection의 횟수를 줄이므로 성능을 향상 시킬수 있다.

간단히 말하면 여러개의 CUD를 한번의 커넥션으로 처리 가능하다는 말이다! ^-^goood~

 

ibatis에 비해 매우 간단하다^-^goood~

 

1) 아래와 같이 옵션을  준다.

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
  PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-config.dtd">
<!--
    Copyright 2010 The myBatis Team

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->

<configuration> 
  <settings>  
  <setting name="defaultExecutorType" value="BATCH" /> <!-- batch 처리 옵션 --> 
 </settings>
</configuration>

 

2) Service에서 사용 하면 끝~~

아래처럼 단일 건 또는 for문 이용, List 형태로 받아서 Iterator 로 사용 가능 하다.

 1) 단일 건(Service단)
    public int insertWorkerInfo(WorkerInfoVo workerInfoVo) {
      return workerInfoService.insertWorkerInfo(workerInfoVo);
    }

 

 2) for를 이용(Service단)
    public void insertWorkerInfo(WorkerInfoVo workerInfoVo) {

    try {   
      for(int i =0 ; i < 10; i++){
          workerInfoDao.insertWorkerInfo(workerInfoVo);
     }
   } catch (Exception e) {

         블라블라
   }
  }

끝~~~~

반응형