All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.penglecode.mybatis.ex.BatchTemplate Maven / Gradle / Ivy

Go to download

mybatis的自定义扩展。 版本1.0.0 支持mybatis 3.2|3.3版本 版本1.0.1 支持mybatis 3.4版本

The newest version!
package com.penglecode.mybatis.ex;

import org.apache.ibatis.session.SqlSession;
/**
 * Batch操作的模板类
 * 
 * 如果当前SqlSession或底层SqlSession中的executor是DynamicExecutor类型的
 * 那么在SqlSessionCallback回调方法中将以BATCH模式来执行SqlSession的各种操作
 * 
 * @author	  	pengpeng
 * @date	  	2014年7月9日 下午3:07:09
 * @version  	1.0
 */
public class BatchTemplate {

	private final SqlSession sqlSession;
	
	public BatchTemplate(SqlSession sqlSession) {
		super();
		if(sqlSession == null){
			throw new IllegalArgumentException("Parameter 'sqlSession' can not be null!");
		}
		this.sqlSession = sqlSession;
	}
	
	/**
	 * 如果当前sqlSession中的executor是DynamicExecutor类型的
	 * 那么在execute方法中将以BATCH模式来执行SqlSession的各种操作
	 * @param action
	 * @return
	 */
	public  T execute(SqlSessionCallback action) {
		try {
			ExecutorSynchronizationManager.beginBatchExecutorMode();
			return action.doInSqlSession(sqlSession);
		} finally {
			ExecutorSynchronizationManager.endBatchExecutorMode();
		}
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy