| | |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; |
| | | import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.DATA_SOURCE_CONFIG_IMPORT_LIST_IS_EMPTY; |
| | | import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.DATA_SOURCE_CONFIG_IMPORT_NAME_EXISTS; |
| | | import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.DATA_SOURCE_CONFIG_DB_TYPE_UNSUPPORTED; |
| | | import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.DATA_SOURCE_CONFIG_NOT_EXISTS; |
| | | import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.DATA_SOURCE_CONFIG_NOT_OK; |
| | | |
| | |
| | | } |
| | | |
| | | private void validateConnectionOK(DataSourceConfigDO config) { |
| | | validateDatabaseTypeSupported(config.getUrl()); |
| | | boolean success = JdbcUtils.isConnectionOK(config.getUrl(), config.getUsername(), config.getPassword()); |
| | | if (!success) { |
| | | throw exception(DATA_SOURCE_CONFIG_NOT_OK); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 默认轻量包只携带 MySQL 驱动。提前给出明确提示,避免缺少驱动时表现成含糊的连接失败。 |
| | | */ |
| | | private void validateDatabaseTypeSupported(String url) { |
| | | if (!StrUtil.startWithIgnoreCase(url, "jdbc:mysql:")) { |
| | | throw exception(DATA_SOURCE_CONFIG_DB_TYPE_UNSUPPORTED, url); |
| | | } |
| | | } |
| | | |
| | |
| | | .build(); |
| | | importDataSourceConfigs.forEach(importConfig -> { |
| | | try { |
| | | validateDatabaseTypeSupported(importConfig.getUrl()); |
| | | DataSourceConfigDO existConfig = dataSourceConfigMapper.selectByName(importConfig.getName()); |
| | | if (existConfig == null) { |
| | | // 新增 |