mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-06 16:48:24 +08:00
!206 fix:多数据源嵌套使用问题
Merge pull request !206 from barql/272378774@qq.com
This commit is contained in:
commit
0aa5443ccf
@ -19,13 +19,24 @@ import java.util.function.Supplier;
|
||||
|
||||
public class DataSourceKey {
|
||||
|
||||
private static final ThreadLocal<String> keyThreadLocal = new ThreadLocal<>();
|
||||
|
||||
public static String manualKey;
|
||||
|
||||
private DataSourceKey() {
|
||||
}
|
||||
|
||||
private static final ThreadLocal<String> keyThreadLocal = new ThreadLocal<>();
|
||||
|
||||
public static void use(String dataSourceKey) {
|
||||
keyThreadLocal.set(dataSourceKey.trim());
|
||||
manualKey = dataSourceKey;
|
||||
}
|
||||
|
||||
public static void use(String dataSourceKey, boolean isManual) {
|
||||
if (isManual)
|
||||
use(dataSourceKey);
|
||||
else {
|
||||
keyThreadLocal.set(dataSourceKey.trim());
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T use(String dataSourceKey, Supplier<T> supplier) {
|
||||
@ -48,6 +59,7 @@ public class DataSourceKey {
|
||||
|
||||
public static void clear() {
|
||||
keyThreadLocal.remove();
|
||||
manualKey = null;
|
||||
}
|
||||
|
||||
public static String get() {
|
||||
|
||||
@ -43,7 +43,7 @@ public class DataSourceInterceptor implements MethodInterceptor {
|
||||
|
||||
@Override
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
String dsKey = DataSourceKey.get();
|
||||
String dsKey = DataSourceKey.manualKey;
|
||||
if (StringUtil.isNotBlank(dsKey)) {
|
||||
return invocation.proceed();
|
||||
}
|
||||
@ -53,7 +53,7 @@ public class DataSourceInterceptor implements MethodInterceptor {
|
||||
return invocation.proceed();
|
||||
}
|
||||
|
||||
DataSourceKey.use(dsKey);
|
||||
DataSourceKey.use(dsKey, false);
|
||||
try {
|
||||
return invocation.proceed();
|
||||
} finally {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user