From 13682f33279f15f52c8c5a7a89c1be4dea5e219e Mon Sep 17 00:00:00 2001 From: fjn <1194361820@qq.com> Date: Tue, 19 Jan 2021 15:42:17 +0800 Subject: [PATCH] =?UTF-8?q?*=20=E5=8F=91=E5=B8=833.4.4=20=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../factory/dynamicdatasource/DynamicSqlSessionTemplate.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sqlhelper-mybatis-spring-common/src/main/java/com/jn/sqlhelper/mybatis/spring/session/factory/dynamicdatasource/DynamicSqlSessionTemplate.java b/sqlhelper-mybatis-spring-common/src/main/java/com/jn/sqlhelper/mybatis/spring/session/factory/dynamicdatasource/DynamicSqlSessionTemplate.java index 507b8bdd8..68c2f2e52 100644 --- a/sqlhelper-mybatis-spring-common/src/main/java/com/jn/sqlhelper/mybatis/spring/session/factory/dynamicdatasource/DynamicSqlSessionTemplate.java +++ b/sqlhelper-mybatis-spring-common/src/main/java/com/jn/sqlhelper/mybatis/spring/session/factory/dynamicdatasource/DynamicSqlSessionTemplate.java @@ -15,6 +15,7 @@ package com.jn.sqlhelper.mybatis.spring.session.factory.dynamicdatasource; import com.jn.langx.annotation.NonNull; +import com.jn.langx.util.Preconditions; import com.jn.langx.util.collection.Collects; import com.jn.langx.util.function.Consumer2; import com.jn.langx.util.reflect.Reflects; @@ -125,7 +126,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl DynamicSqlSessionFactory dynamicSqlSessionFactory = DynamicSqlSessionTemplate.this.getDynamicSqlSessionFactory(); @NonNull DataSourceKey key = MethodInvocationDataSourceKeySelector.getCurrent(); - + Preconditions.checkNotNull(key, "the selected datasource key is null"); DelegatingSqlSessionFactory sqlSessionFactory = dynamicSqlSessionFactory.getDelegatingSqlSessionFactory(); ExecutorType executorType = sqlSessionFactory.getConfiguration().getDefaultExecutorType(); PersistenceExceptionTranslator exceptionTranslator = sqlSessionFactory.getPersistenceExceptionTranslator(); @@ -147,7 +148,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl sqlSession = getSqlSession(sqlSessionFactory, executorType, exceptionTranslator); // 当改调用发生在sqlhelper transaction manager 范围内时,需要注册 - if (key != null && transaction != null) { + if (transaction != null) { TransactionThreadContext.bindTransactionResource(key, new SqlSessionTransactionalResource(Reflects.getMethodString(method), sqlSession, sqlSessionFactory)); } }