|
|
@@ -18,10 +18,11 @@ import com.usoftchina.bi.server.service.chart.GetChartsDataUtilService;
|
|
|
import com.usoftchina.bi.core.jdbc.DynamicDataSource;
|
|
|
import com.usoftchina.bi.core.jdbc.DynamicDataSourceContextHolder;
|
|
|
import com.usoftchina.bi.core.jdbc.DynamicDataSourceRegister;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
@@ -39,6 +40,8 @@ public class DataBasesService {
|
|
|
GetChartsDataUtilService getChartsDataUtilService;
|
|
|
@Autowired
|
|
|
private ImplementSqlService implementSqlService;
|
|
|
+
|
|
|
+ private static final Logger LOGGER = LoggerFactory.getLogger(DataBasesService.class);
|
|
|
/*
|
|
|
保存数据库连接
|
|
|
*/
|
|
|
@@ -200,12 +203,15 @@ public class DataBasesService {
|
|
|
if (target.size() == 0) {
|
|
|
target.putAll(dataSourceRegister.getSlaveDataSources());
|
|
|
}
|
|
|
- target.put(databasesInfo.getId(), dataSourceRegister.buildDataSource(dsMap));
|
|
|
- DynamicDataSource datasource = (DynamicDataSource) ContextUtil.getBean("dataSource");
|
|
|
- datasource.setTargetDataSources(target);
|
|
|
- datasource.afterPropertiesSet();
|
|
|
-
|
|
|
- DynamicDataSourceContextHolder.dataSourceIds.add(String.valueOf(databasesInfo.getId()));
|
|
|
+ if (!target.containsKey(databasesInfo.getId())) {
|
|
|
+ target.put(databasesInfo.getId(), dataSourceRegister.buildDataSource(dsMap));
|
|
|
+ DynamicDataSource datasource = (DynamicDataSource) ContextUtil.getBean("dataSource");
|
|
|
+ datasource.setTargetDataSources(target);
|
|
|
+ datasource.afterPropertiesSet();
|
|
|
+
|
|
|
+ DynamicDataSourceContextHolder.dataSourceIds.add(String.valueOf(databasesInfo.getId()));
|
|
|
+ LOGGER.info("注册数据源,id={}", databasesInfo.getId());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|