diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/datasource/DataSourceKey.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/datasource/DataSourceKey.java index dbb65038..122271ee 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/datasource/DataSourceKey.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/datasource/DataSourceKey.java @@ -34,9 +34,11 @@ public class DataSourceKey { public static void use(String dataSourceKey) { Deque deque = lookup.get(); - if (deque != null) { - deque.push(dataSourceKey); + if (deque == null) { + deque = new ArrayDeque<>(1); + lookup.set(deque); } + deque.push(dataSourceKey); } public static String get() { @@ -95,31 +97,4 @@ public class DataSourceKey { return shardingDsKey != null ? shardingDsKey : dataSource; } - // === For Removal === - - @Deprecated - public static String getByManual() { - throw new UnsupportedOperationException("使用 DataSource.get() 代替。"); - } - - @Deprecated - public static String getByAnnotation() { - throw new UnsupportedOperationException("使用 DataSource.get() 代替。"); - } - - @Deprecated - public static void useWithAnnotation(String dataSourceKey) { - throw new UnsupportedOperationException("使用 DataSource.use(String) 代替。"); - } - - @Deprecated - public static void setAnnotationKeyThreadLocal(ThreadLocal annotationKeyThreadLocal) { - throw new UnsupportedOperationException("使用 DataSource.setThreadLocal(ThreadLocal>) 代替。"); - } - - @Deprecated - public static void setManualKeyThreadLocal(ThreadLocal manualKeyThreadLocal) { - throw new UnsupportedOperationException("使用 DataSource.setThreadLocal(ThreadLocal>) 代替。"); - } - }