feat(pig-common-datasource): 修复写死为MySQL驱动的问题

1.此处存在疑问,一般情况下的设置,都是需要写driver class name的,完全不需要写死成MySQL
This commit is contained in:
MicLng 2021-10-18 09:51:52 +08:00
parent 5d14faa40a
commit 14eb346f1c
5 changed files with 12 additions and 114 deletions

View File

@ -96,6 +96,7 @@ CREATE TABLE `sys_dict` (
BEGIN;
INSERT INTO `sys_dict` VALUES (1, 'dict_type', '字典类型', '系统类不能修改', '1', '0', '2019-05-16 14:16:20', NULL, NULL, '2019-05-16 14:20:16');
INSERT INTO `sys_dict` VALUES (2, 'log_type', '日志类型', '0-正常 1 异常', '1', '0', '2020-03-13 14:21:01', NULL, NULL, '2020-03-13 14:21:01');
INSERT INTO `sys_dict` VALUES (3, 'ds_type', '驱动类型', '数据库驱动类型', '1', '0', '2021-10-15 16:24:35', NULL, NULL, '2021-10-15 16:24:38');
COMMIT;
-- ----------------------------
@ -130,6 +131,14 @@ INSERT INTO `sys_dict_item` VALUES (1, 1, '1', '系统类', 'dict_type', '系统
INSERT INTO `sys_dict_item` VALUES (2, 1, '0', '业务类', 'dict_type', '业务类字典', 0, '可以修改', '0', '2019-05-16 14:20:59', NULL, NULL, '2019-05-16 14:20:59');
INSERT INTO `sys_dict_item` VALUES (3, 2, '0', '正常', 'log_type', '正常', 0, '正常', '0', '2020-03-13 14:23:22', NULL, NULL, '2020-03-13 14:23:22');
INSERT INTO `sys_dict_item` VALUES (4, 2, '9', '异常', 'log_type', '异常', 1, '异常', '0', '2020-03-13 14:23:35', NULL, NULL, '2020-03-13 14:23:35');
INSERT INTO `sys_dict_item` VALUES (5, 3, 'com.mysql.cj.jdbc.Driver', 'MYSQL8', 'ds_type', 'MYSQL8', 0, NULL, '0', NULL, NULL, NULL, NULL);
INSERT INTO `sys_dict_item` VALUES (6, 3, 'com.mysql.jdbc.Driver', 'MYSQL5', 'ds_type', 'MYSQL5', 0, NULL, '0', NULL, NULL, NULL, NULL);
INSERT INTO `sys_dict_item` VALUES (7, 3, 'oracle.jdbc.OracleDriver', 'Oracle', 'ds_type', 'Oracle', 0, NULL, '0', NULL, NULL, NULL, NULL);
INSERT INTO `sys_dict_item` VALUES (8, 3, 'org.mariadb.jdbc.Driver', 'mariadb', 'ds_type', 'mariadb', 0, NULL, '0', NULL, NULL, NULL, NULL);
INSERT INTO `sys_dict_item` VALUES (9, 3, 'com.microsoft.sqlserver.jdbc.SQLServerDriver', 'sqlserver2005+', 'ds_type', 'sqlserver2005+', 0, NULL, '0', NULL, NULL, NULL, NULL);
INSERT INTO `sys_dict_item` VALUES (10, 3, 'com.microsoft.jdbc.sqlserver.SQLServerDriver', 'sqlserver2000', 'ds_type', 'sqlserver2000', 0, NULL, '0', NULL, NULL, NULL, NULL);
INSERT INTO `sys_dict_item` VALUES (11, 3, 'com.ibm.db2.jcc.DB2Driver', 'db2', 'ds_type', 'db2', 0, NULL, '0', NULL, NULL, NULL, NULL);
INSERT INTO `sys_dict_item` VALUES (12, 3, 'org.postgresql.Driver', 'postgresql', 'ds_type', 'postgresql', 0, NULL, '0', NULL, NULL, NULL, NULL);
COMMIT;
-- ----------------------------

View File

@ -47,7 +47,6 @@ public class JdbcDynamicDataSourceProvider extends AbstractJdbcDataSourceProvide
/**
* 执行语句获得数据源参数
*
* @param statement 语句
* @return 数据源参数
* @throws SQLException sql异常

View File

@ -1,76 +0,0 @@
package com.pig4cloud.pig.common.datasource.support;
/**
* 数据库驱动ClassName
*
* @author huyuanxin
* @date 2021-10-08
*/
public enum DriverClassNameConstants {
/**
* MySQL Driver
* After mysql-connector-java 6
*/
MYSQL_DRIVER("com.mysql.cj.jdbc.Driver"),
/**
* Old MySQL Driver
* Before mysql-connector-java 5
*/
OLD_MYSQL_DRIVER("com.mysql.jdbc.Driver"),
/**
* Oracle Driver
*/
ORACLE_DRIVER("oracle.jdbc.OracleDriver"),
/**
* Mariadb Driver
*/
MARIADB("org.mariadb.jdbc.Driver"),
/**
* SqlServer Driver
* SqlServer 2005+
*/
SQLSERVER_DRIVER("com.microsoft.sqlserver.jdbc.SQLServerDriver"),
/**
* Old SqlServer Driver
* SqlServer 2000
*/
OLD_SQLSERVER_DRIVER(" com.microsoft.jdbc.sqlserver.SQLServerDriver"),
/**
* DB2 Driver
*/
DB2("com.ibm.db2.jcc.DB2Driver"),
/**
* PostgreSQL Driver
*/
POSTGRE_SQL("org.postgresql.Driver"),
/**
* Neo4j Bolt Driver
*/
NEO4J_BOLT("org.neo4j.jdbc.bolt.BoltDriver"),
/**
* Neo4j Http Driver
*/
NEO4J_HTTP("org.neo4j.jdbc.http.HttpDriver");
private final String driverClassName;
DriverClassNameConstants(String driverClassName) {
this.driverClassName = driverClassName;
}
public String getDriverClassName() {
return driverClassName;
}
}

View File

@ -20,16 +20,11 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.codegen.entity.GenDatasourceConf;
import com.pig4cloud.pig.codegen.service.GenDatasourceConfService;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.datasource.support.DriverClassNameConstants;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
* 数据源管理
*
@ -42,14 +37,11 @@ import java.util.Optional;
@Api(value = "dsconf", tags = "数据源管理模块")
public class GenDsConfController {
private static List<String> driverList = null;
private final GenDatasourceConfService datasourceConfService;
/**
* 分页查询
*
* @param page 分页对象
* @param page 分页对象
* @param datasourceConf 数据源表
* @return
*/
@ -60,7 +52,6 @@ public class GenDsConfController {
/**
* 查询全部数据源
*
* @return
*/
@GetMapping("/list")
@ -70,7 +61,6 @@ public class GenDsConfController {
/**
* 通过id查询数据源表
*
* @param id id
* @return R
*/
@ -81,7 +71,6 @@ public class GenDsConfController {
/**
* 新增数据源表
*
* @param datasourceConf 数据源表
* @return R
*/
@ -93,7 +82,6 @@ public class GenDsConfController {
/**
* 修改数据源表
*
* @param conf 数据源表
* @return R
*/
@ -105,7 +93,6 @@ public class GenDsConfController {
/**
* 通过id删除数据源表
*
* @param id id
* @return R
*/
@ -115,21 +102,4 @@ public class GenDsConfController {
return R.ok(datasourceConfService.removeByDsId(id));
}
/**
* 获得支持的数据库驱动
*
* @return 数据库驱动列表
*/
@SysLog("获得支持的数据库驱动")
@GetMapping("/driver")
public R<List<String>> driverList() {
return Optional.ofNullable(driverList).map(R::ok).orElseGet(() -> {
driverList = new ArrayList<>();
for (DriverClassNameConstants driverClassNameConstant : DriverClassNameConstants.values()) {
driverList.add(driverClassNameConstant.getDriverClassName());
}
return R.ok(driverList);
});
}
}

View File

@ -51,7 +51,6 @@ public class GenDatasourceConfServiceImpl extends ServiceImpl<GenDatasourceConfM
/**
* 保存数据源并且加密
*
* @param conf
* @return
*/
@ -73,7 +72,6 @@ public class GenDatasourceConfServiceImpl extends ServiceImpl<GenDatasourceConfM
/**
* 更新数据源
*
* @param conf 数据源信息
* @return
*/
@ -99,7 +97,6 @@ public class GenDatasourceConfServiceImpl extends ServiceImpl<GenDatasourceConfM
/**
* 通过数据源名称删除
*
* @param dsId 数据源ID
* @return
*/
@ -113,7 +110,6 @@ public class GenDatasourceConfServiceImpl extends ServiceImpl<GenDatasourceConfM
/**
* 添加动态数据源
*
* @param conf 数据源信息
*/
@Override
@ -132,7 +128,6 @@ public class GenDatasourceConfServiceImpl extends ServiceImpl<GenDatasourceConfM
/**
* 校验数据源配置是否有效
*
* @param conf 数据源信息
* @return 有效/无效
*/
@ -140,7 +135,8 @@ public class GenDatasourceConfServiceImpl extends ServiceImpl<GenDatasourceConfM
public Boolean checkDataSource(GenDatasourceConf conf) {
try {
DriverManager.getConnection(conf.getUrl(), conf.getUsername(), conf.getPassword());
} catch (SQLException e) {
}
catch (SQLException e) {
log.error("数据源配置 {} , 获取链接失败", conf.getName(), e);
return Boolean.FALSE;
}