mirror of
https://github.com/hs-web/hsweb-framework.git
synced 2026-06-06 05:17:46 +08:00
优化动态数据源是否生效判断
This commit is contained in:
@@ -21,6 +21,10 @@ public final class DataSourceHolder {
|
||||
*/
|
||||
static DynamicDataSourceService dynamicDataSourceService;
|
||||
|
||||
public static void checkDynamicDataSourceReady() {
|
||||
if (dynamicDataSourceService == null) throw new UnsupportedOperationException("dynamicDataSourceService not ready");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 动态数据源切换器
|
||||
*/
|
||||
@@ -41,6 +45,7 @@ public final class DataSourceHolder {
|
||||
public static DynamicDataSource currentDataSource() {
|
||||
String id = dataSourceSwitcher.currentDataSourceId();
|
||||
if (id == null) return defaultDataSource();
|
||||
checkDynamicDataSourceReady();
|
||||
return dynamicDataSourceService.getDataSource(id);
|
||||
}
|
||||
|
||||
@@ -59,6 +64,7 @@ public final class DataSourceHolder {
|
||||
*/
|
||||
public static boolean existing(String id) {
|
||||
try {
|
||||
checkDynamicDataSourceReady();
|
||||
return dynamicDataSourceService.getDataSource(id) != null;
|
||||
} catch (DataSourceNotFoundException e) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user