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

com.alibaba.easyretry.extension.mybatis.dao.BaseDAOSupport Maven / Gradle / Ivy

The newest version!
package com.alibaba.easyretry.extension.mybatis.dao;

import java.util.Objects;
import java.util.function.Function;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

/**
 * @author wuhao
 */
public abstract class BaseDAOSupport {

	private final SqlSessionFactory sqlSessionFactory;

	public BaseDAOSupport(SqlSessionFactory sqlSessionFactory) {
		this.sqlSessionFactory = sqlSessionFactory;
	}

	protected  T execute(Function function) {
		Objects.requireNonNull(sqlSessionFactory, "require sqlSessionFactory non null");
		try (final SqlSession session = sqlSessionFactory.openSession(false)) {
			return function.apply(session);
		}
	}

	protected  T execute(Function function, boolean autoCommit) {
		Objects.requireNonNull(sqlSessionFactory, "require sqlSessionFactory non null");
		try (final SqlSession session = sqlSessionFactory.openSession(autoCommit)) {
			return function.apply(session);
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy