后台资产展示代码
parent
b8fa4d417c
commit
0879134c24
|
@ -110,37 +110,45 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
|||
/**
|
||||
* 测试连接
|
||||
*
|
||||
* @param dataSource 数据源
|
||||
* @param etlDataScore 数据源
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public Boolean testConnection(DataSource dataSource) {
|
||||
DataType dataType = dataTypeService.getOne(new LambdaQueryWrapper<>() {{
|
||||
eq(DataType::getType, dataSource.getDataType());
|
||||
}});
|
||||
String jdbcUrl = "";
|
||||
String className = "";
|
||||
boolean flag = false;
|
||||
try {
|
||||
//判空
|
||||
if (dataType.getDriverManager() != null && dataType.getPrefix() != null) {
|
||||
if ("MySql".equals(dataType.getType())) {
|
||||
className = dataType.getDriverManager();
|
||||
//mysql拼接连接路径
|
||||
jdbcUrl = dataType.getDriverManager() + dataType.getPrefix() + dataSource.getIp() + ":" + dataSource.getPort() + "/" + dataSource.getDatabaseName() + "?" + dataSource.getConnectionParam();
|
||||
}
|
||||
if ("Oracle".equals(dataType.getType())) {
|
||||
className = dataType.getDriverManager();
|
||||
//oracle拼接连接路径
|
||||
jdbcUrl = dataType.getDriverManager() + dataType.getPrefix() + dataSource.getIp() + ":" + dataSource.getPort() + ":" + dataSource.getDatabaseName() + "?" + dataSource.getConnectionParam();
|
||||
}
|
||||
flag = testConnection(className, jdbcUrl, dataSource.getUserName(), dataSource.getPassword());
|
||||
}
|
||||
return flag;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
public Boolean testConnection(DataSource etlDataScore) {
|
||||
// DataType dataType = dataTypeService.getOne(new LambdaQueryWrapper<>() {{
|
||||
// eq(DataType::getType, dataSource.getDataType());
|
||||
// }});
|
||||
// String jdbcUrl = "";
|
||||
// String className = "";
|
||||
// boolean flag = false;
|
||||
// try {
|
||||
// //判空
|
||||
// if (dataType.getDriverManager() != null && dataType.getPrefix() != null) {
|
||||
// if ("MySql".equals(dataType.getType())) {
|
||||
// className = dataType.getDriverManager();
|
||||
// //mysql拼接连接路径
|
||||
// jdbcUrl = dataType.getDriverManager() + dataType.getPrefix() + dataSource.getIp() + ":" + dataSource.getPort() + "/" + dataSource.getDatabaseName() + "?" + dataSource.getConnectionParam();
|
||||
// }
|
||||
// if ("Oracle".equals(dataType.getType())) {
|
||||
// className = dataType.getDriverManager();
|
||||
// //oracle拼接连接路径
|
||||
// jdbcUrl = dataType.getDriverManager() + dataType.getPrefix() + dataSource.getIp() + ":" + dataSource.getPort() + ":" + dataSource.getDatabaseName() + "?" + dataSource.getConnectionParam();
|
||||
// }
|
||||
// flag = testConnection(className, jdbcUrl, dataSource.getUserName(), dataSource.getPassword());
|
||||
// }
|
||||
// return flag;
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return flag;
|
||||
if (etlDataScore.getDataType().equals(MYSQL)) {
|
||||
MysqlPool mysqlPool = new MysqlPool(etlDataScore);
|
||||
mysqlPool.init();
|
||||
Connection conn = mysqlPool.getConn();
|
||||
mysqlPool.replease(conn);
|
||||
mysqlPool.closeConn();
|
||||
}
|
||||
return flag;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -340,18 +348,21 @@ public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSou
|
|||
* @param password 密码
|
||||
* @return 结果
|
||||
*/
|
||||
private boolean testConnection(String driverManager, String jdbcUrl, String userName, String password) {
|
||||
// 判断参数是否为空
|
||||
if (StringUtils.isNotEmpty(driverManager) && StringUtils.isNotEmpty(jdbcUrl) && StringUtils.isNotEmpty(userName) && StringUtils.isNotEmpty(password)) {
|
||||
try {
|
||||
// 加载驱动
|
||||
Class.forName(driverManager);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// private boolean testConnection(String driverManager, String jdbcUrl, String userName, String password) {
|
||||
// // 判断参数是否为空
|
||||
// if (StringUtils.isNotEmpty(driverManager) && StringUtils.isNotEmpty(jdbcUrl) && StringUtils.isNotEmpty(userName) && StringUtils.isNotEmpty(password)) {
|
||||
// try {
|
||||
// // 加载驱动
|
||||
// Class.forName(driverManager);
|
||||
// return true;
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue