티스토리 뷰

공부/DBMS, SQL

[iBatis] update batch

doublemetal 2014. 11. 7. 19:08

http://mdbitz.com/2010/10/19/performing-batch-processing-with-ibatis-and-spring/


위 사이트 코드 참고하여 익명 이너 클래스 대신 Helper 클래스 작성하여 사용하였다.




public class UpdateBatchHelper<E> implements SqlMapClientCallback {

private Iterator<E> iterator;

private String statement;


@SuppressWarnings("unused")

private UpdateBatchHelper() {

// default 생성자는 사용하지 않는다.

}


public UpdateBatchHelper(Iterator<E> iterator, String statement) {

this.iterator = iterator;

this.statement = statement;

}


/**

* @param executor

* @return

* @throws SQLException

* @see org.springframework.orm.ibatis.SqlMapClientCallback#doInSqlMapClient(com.ibatis.sqlmap.client.SqlMapExecutor)

*/

@Override

public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {

executor.startBatch();

while (iterator.hasNext()) {

executor.update(statement, iterator.next());

}

return executor.executeBatch();

}


public void setIterator(Iterator<E> iterator) {

this.iterator = iterator;

}


public void setStatement(String statement) {

this.statement = statement;

}

}

'공부 > DBMS, SQL' 카테고리의 다른 글

[Mysql] DATETIME default value  (0) 2015.04.20
[mysql] 재시작  (0) 2014.12.28
[mysql] 컬럼명으로 테이블 찾기  (0) 2014.11.26
[mysql] LAST_INSERT_ID()  (0) 2014.10.22
[Mysql] Table Character Set 변경 쿼리  (0) 2013.12.26
댓글
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함