From 476e33db42eb36fc9d23fa3125b258c9ad078cb3 Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Sun, 2 Jun 2024 12:19:04 +0800 Subject: [PATCH] refactor: optimize FlexMapperProxy.java --- .../core/mybatis/binding/FlexMapperProxy.java | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 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 ca316974..bf92c3d3 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 @@ -60,10 +60,6 @@ public class FlexMapperProxy extends MybatisMapperProxy { //最终使用的数据源 String finalDsKey = userDsKey; - //由用户指定的数据类型 - DbType userDbType = DialectFactory.getHintDbType(); - DbType finalDbType = userDbType; - try { if (StringUtil.isBlank(finalDsKey)) { finalDsKey = getMethodDsKey(method, proxy); @@ -73,34 +69,29 @@ public class FlexMapperProxy extends MybatisMapperProxy { finalDsKey = DataSourceKey.getShardingDsKey(finalDsKey, proxy, method, args); if (StringUtil.isNotBlank(finalDsKey) && !finalDsKey.equals(userDsKey)) { - DataSourceKey.use(finalDsKey); needClearDsKey = true; + DataSourceKey.use(finalDsKey); } - - if (finalDbType == null) { + DbType hintDbType = DialectFactory.getHintDbType(); + if (hintDbType == null) { if (finalDsKey != null && dataSource != null) { - //使用最终分片获取数据源类型 - finalDbType = dataSource.getDbType(finalDsKey); + hintDbType = dataSource.getDbType(finalDsKey); } - if (finalDbType == null) { - finalDbType = FlexGlobalConfig.getDefaultConfig().getDbType(); + if (hintDbType == null) { + hintDbType = FlexGlobalConfig.getDefaultConfig().getDbType(); } needClearDbType = true; - DialectFactory.setHintDbType(finalDbType); + DialectFactory.setHintDbType(hintDbType); } return cachedInvoker(method).invoke(proxy, method, args, sqlSession); } catch (Throwable e) { throw ExceptionUtil.unwrapThrowable(e); } finally { if (needClearDbType) { - if (userDbType != null) { - DialectFactory.setHintDbType(userDbType); - } else { - DialectFactory.clearHintDbType(); - } + DialectFactory.clearHintDbType(); } if (needClearDsKey) { if (userDsKey != null) {