From c5af8305858a309605c841ae16c735199c229f05 Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Mon, 3 Jun 2024 11:36:16 +0800 Subject: [PATCH] fix: FlexMapperProxy.getMethodDsKey --- .../core/mybatis/binding/FlexMapperProxy.java | 48 ++++++++----------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/binding/FlexMapperProxy.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/binding/FlexMapperProxy.java index bf92c3d3..bbee3410 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/binding/FlexMapperProxy.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/binding/FlexMapperProxy.java @@ -25,18 +25,14 @@ import com.mybatisflex.core.mybatis.FlexConfiguration; import com.mybatisflex.core.row.RowMapper; import com.mybatisflex.core.table.TableInfo; import com.mybatisflex.core.table.TableInfoFactory; -import com.mybatisflex.core.util.MapUtil; import com.mybatisflex.core.util.StringUtil; import org.apache.ibatis.reflection.ExceptionUtil; import org.apache.ibatis.session.SqlSession; import java.lang.reflect.Method; import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; public class FlexMapperProxy extends MybatisMapperProxy { - private static final String NULL_KEY = "@NK@"; - private static final Map methodDsKeyCache = new ConcurrentHashMap<>(); private final FlexDataSource dataSource; public FlexMapperProxy(SqlSession sqlSession, Class mapperInterface, Map methodCache, @@ -106,33 +102,29 @@ public class FlexMapperProxy extends MybatisMapperProxy { private static String getMethodDsKey(Method method, Object proxy) { - String result = MapUtil.computeIfAbsent(methodDsKeyCache, method, m -> { - UseDataSource methodAnno = method.getAnnotation(UseDataSource.class); - if (methodAnno != null && StringUtil.isNotBlank(methodAnno.value())) { - return methodAnno.value(); - } + UseDataSource methodAnno = method.getAnnotation(UseDataSource.class); + if (methodAnno != null && StringUtil.isNotBlank(methodAnno.value())) { + return methodAnno.value(); + } - Class[] interfaces = proxy.getClass().getInterfaces(); - for (Class anInterface : interfaces) { - UseDataSource classAnno = anInterface.getAnnotation(UseDataSource.class); - if (classAnno != null && StringUtil.isNotBlank(classAnno.value())) { - return classAnno.value(); + Class[] interfaces = proxy.getClass().getInterfaces(); + for (Class anInterface : interfaces) { + UseDataSource classAnno = anInterface.getAnnotation(UseDataSource.class); + if (classAnno != null && StringUtil.isNotBlank(classAnno.value())) { + return classAnno.value(); + } + } + + if (interfaces[0] != RowMapper.class) { + TableInfo tableInfo = TableInfoFactory.ofMapperClass(interfaces[0]); + if (tableInfo != null) { + String tableDsKey = tableInfo.getDataSource(); + if (StringUtil.isNotBlank(tableDsKey)) { + return tableDsKey; } } - - if (interfaces[0] != RowMapper.class) { - TableInfo tableInfo = TableInfoFactory.ofMapperClass(interfaces[0]); - if (tableInfo != null) { - String tableDsKey = tableInfo.getDataSource(); - if (StringUtil.isNotBlank(tableDsKey)) { - return tableDsKey; - } - } - } - return NULL_KEY; - }); - - return NULL_KEY.equals(result) ? null : result; + } + return null; } }