refactor: optimize FlexMapperProxy.java

This commit is contained in:
Michael Yang 2024-05-31 17:20:57 +08:00
parent 16c9d720ec
commit df79f44f32

View File

@ -97,8 +97,8 @@ public class FlexMapperProxy<T> extends MybatisMapperProxy<T> {
dbType = FlexGlobalConfig.getDefaultConfig().getDbType(); dbType = FlexGlobalConfig.getDefaultConfig().getDbType();
} }
DialectFactory.setHintDbType(dbType);
needClearDbType = true; needClearDbType = true;
DialectFactory.setHintDbType(dbType);
} }
// return method.invoke(mapper, args); // return method.invoke(mapper, args);
return cachedInvoker(method).invoke(proxy, method, args, sqlSession); return cachedInvoker(method).invoke(proxy, method, args, sqlSession);
@ -116,26 +116,26 @@ public class FlexMapperProxy<T> extends MybatisMapperProxy<T> {
private static String getConfigDataSourceKey(Method method, Object proxy) { private static String getConfigDataSourceKey(Method method, Object proxy) {
String result = MapUtil.computeIfAbsent(methodDsKeyCache, method, method1 -> { String result = MapUtil.computeIfAbsent(methodDsKeyCache, method, m -> {
UseDataSource useDataSource = method1.getAnnotation(UseDataSource.class); UseDataSource methodAnno = method.getAnnotation(UseDataSource.class);
if (useDataSource != null && StringUtil.isNotBlank(useDataSource.value())) { if (methodAnno != null && StringUtil.isNotBlank(methodAnno.value())) {
return useDataSource.value(); return methodAnno.value();
} }
Class<?>[] interfaces = proxy.getClass().getInterfaces(); Class<?>[] interfaces = proxy.getClass().getInterfaces();
for (Class<?> anInterface : interfaces) { for (Class<?> anInterface : interfaces) {
UseDataSource annotation = anInterface.getAnnotation(UseDataSource.class); UseDataSource classAnno = anInterface.getAnnotation(UseDataSource.class);
if (annotation != null) { if (classAnno != null && StringUtil.isNotBlank(classAnno.value())) {
return annotation.value(); return classAnno.value();
} }
} }
if (interfaces[0] != RowMapper.class) { if (interfaces[0] != RowMapper.class) {
TableInfo tableInfo = TableInfoFactory.ofMapperClass(interfaces[0]); TableInfo tableInfo = TableInfoFactory.ofMapperClass(interfaces[0]);
if (tableInfo != null) { if (tableInfo != null) {
String dataSourceKey = tableInfo.getDataSource(); String tableDsKey = tableInfo.getDataSource();
if (StringUtil.isNotBlank(dataSourceKey)) { if (StringUtil.isNotBlank(tableDsKey)) {
return dataSourceKey; return tableDsKey;
} }
} }
} }