top.lingkang.mm.SqlSessionFactoryProxy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mybatis-magic Show documentation
Show all versions of mybatis-magic Show documentation
mybatis能力扩展框架,兼顾mybatis的mapper.xml编写操作数据库。
The newest version!
package top.lingkang.mm;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSessionFactory;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
/**
* SqlSessionFactory 代理
*
* @author lingkang
* @create by 2024/3/4 16:29
*/
public class SqlSessionFactoryProxy implements InvocationHandler {
private SqlSessionFactory sqlSessionFactory;
public SqlSessionFactoryProxy(SqlSessionFactory sqlSessionFactory) {
this.sqlSessionFactory = sqlSessionFactory;
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (method.getReturnType() == Configuration.class)
return sqlSessionFactory.getConfiguration();
MagicSqlSession sqlSession = new MagicSqlSession(sqlSessionFactory, null);
return sqlSession;
}
}