From bafdc6ff017e2749e8ed05c16b50a879b3c2ae78 Mon Sep 17 00:00:00 2001 From: cgj <782070772@qq.com> Date: Tue, 22 Sep 2020 15:09:48 +0800 Subject: [PATCH] Update SqlSessionTemplate.java check executor type on mapper method args, when it has, use executor type by user specified on mapper method arg --- .../org/mybatis/spring/SqlSessionTemplate.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/mybatis/spring/SqlSessionTemplate.java b/src/main/java/org/mybatis/spring/SqlSessionTemplate.java index fb1905cf5c..f20c517a69 100644 --- a/src/main/java/org/mybatis/spring/SqlSessionTemplate.java +++ b/src/main/java/org/mybatis/spring/SqlSessionTemplate.java @@ -28,7 +28,9 @@ import java.sql.Connection; import java.util.List; import java.util.Map; +import java.util.Set; +import org.apache.ibatis.binding.MapperMethod; import org.apache.ibatis.cursor.Cursor; import org.apache.ibatis.exceptions.PersistenceException; import org.apache.ibatis.executor.BatchResult; @@ -421,8 +423,22 @@ public void destroy() throws Exception { private class SqlSessionInterceptor implements InvocationHandler { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + ExecutorType executorType = null; + + if (args != null && args.length > 1 && args[1] instanceof MapperMethod.ParamMap) { + MapperMethod.ParamMap params = (MapperMethod.ParamMap) args[1]; + Set set = params.entrySet(); + for (Map.Entry it : set) { + if (it.getValue() instanceof ExecutorType) { + executorType = (ExecutorType) it.getValue(); + } + } + } + SqlSession sqlSession = getSqlSession(SqlSessionTemplate.this.sqlSessionFactory, - SqlSessionTemplate.this.executorType, SqlSessionTemplate.this.exceptionTranslator); + executorType == null ? SqlSessionTemplate.this.executorType : executorType, + SqlSessionTemplate.this.exceptionTranslator); + try { Object result = method.invoke(sqlSession, args); if (!isSqlSessionTransactional(sqlSession, SqlSessionTemplate.this.sqlSessionFactory)) {