Merge pull request #6426 from dataease/pr@dev-v2@fixDatasource

Pr@dev v2@fix datasource
This commit is contained in:
taojinlong 2023-10-30 02:39:28 -05:00 committed by GitHub
commit cdbf52fb5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 43 deletions

View File

@ -319,7 +319,7 @@ public class ApiUtils {
} }
} }
for (JsonNode node : jsonArray) { for (JsonNode node : jsonArray) {
handleStr(apiDefinition, node.toString(), childrenField, rootPath + "." + fieldName + "[*]"); handleStr(apiDefinition, node.toString(), childrenField, rootPath + "." + String.format(path, fieldName) + "[*]");
} }
o.put("children", childrenField); o.put("children", childrenField);
o.put("childrenDataType", "LIST"); o.put("childrenDataType", "LIST");

View File

@ -47,7 +47,6 @@ import java.util.stream.Collectors;
@Component("calciteProvider") @Component("calciteProvider")
public class CalciteProvider { public class CalciteProvider {
//TODO mongo impala es hive
@Resource @Resource
protected CoreDatasourceMapper coreDatasourceMapper; protected CoreDatasourceMapper coreDatasourceMapper;
@Resource @Resource
@ -93,7 +92,7 @@ public class CalciteProvider {
schemas.add(resultSet.getString(1)); schemas.add(resultSet.getString(1));
} }
} catch (Exception e) { } catch (Exception e) {
DEException.throwException(e); DEException.throwException(e.getMessage());
} }
return schemas; return schemas;
} }
@ -107,7 +106,7 @@ public class CalciteProvider {
tables.add(getTableDesc(datasourceRequest, resultSet)); tables.add(getTableDesc(datasourceRequest, resultSet));
} }
} catch (Exception e) { } catch (Exception e) {
DEException.throwException(e); DEException.throwException(e.getMessage());
} }
} }
return tables; return tables;
@ -145,15 +144,11 @@ public class CalciteProvider {
String querySql = getTablesSql(datasourceRequest).get(0); String querySql = getTablesSql(datasourceRequest).get(0);
try (Connection con = getConnection(datasourceRequest.getDatasource()); Statement statement = getStatement(con, 30); ResultSet resultSet = statement.executeQuery(querySql)) { try (Connection con = getConnection(datasourceRequest.getDatasource()); Statement statement = getStatement(con, 30); ResultSet resultSet = statement.executeQuery(querySql)) {
} catch (Exception e) { } catch (Exception e) {
DEException.throwException(e); DEException.throwException(e.getMessage());
} }
return "Success"; return "Success";
} }
public List<TableField> getTableFields(DatasourceRequest datasourceRequest) throws Exception {
return null;
}
public Map<String, Object> fetchResultField(DatasourceRequest datasourceRequest) throws DEException { public Map<String, Object> fetchResultField(DatasourceRequest datasourceRequest) throws DEException {
List<TableField> datasetTableFields = new ArrayList<>(); List<TableField> datasetTableFields = new ArrayList<>();
List<String[]> list = new LinkedList<>(); List<String[]> list = new LinkedList<>();
@ -242,7 +237,7 @@ public class CalciteProvider {
Class.forName("org.apache.calcite.jdbc.Driver"); Class.forName("org.apache.calcite.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:calcite:", info); connection = DriverManager.getConnection("jdbc:calcite:", info);
} catch (Exception e) { } catch (Exception e) {
DEException.throwException(e); DEException.throwException(e.getMessage());
} }
return connection; return connection;
} }
@ -433,7 +428,7 @@ public class CalciteProvider {
list.add(row); list.add(row);
} }
} catch (Exception e) { } catch (Exception e) {
DEException.throwException(e); DEException.throwException(e.getMessage());
} }
return list; return list;
} }
@ -573,7 +568,7 @@ public class CalciteProvider {
Driver driverClass = (Driver) jdbcClassLoader.loadClass(driverClassName).newInstance(); Driver driverClass = (Driver) jdbcClassLoader.loadClass(driverClassName).newInstance();
conn = driverClass.connect(configuration.getJdbc(), props); conn = driverClass.connect(configuration.getJdbc(), props);
} catch (Exception e) { } catch (Exception e) {
DEException.throwException(e); DEException.throwException(e.getMessage());
} }
return conn; return conn;
} }
@ -587,7 +582,7 @@ public class CalciteProvider {
stat = connection.createStatement(); stat = connection.createStatement();
stat.setQueryTimeout(queryTimeout); stat.setQueryTimeout(queryTimeout);
} catch (Exception e) { } catch (Exception e) {
DEException.throwException(e); DEException.throwException(e.getMessage());
} }
return stat; return stat;
} }
@ -640,7 +635,7 @@ public class CalciteProvider {
customJdbcClassLoaders.put(coreDriver.getId(), customJdbcClassLoader); customJdbcClassLoaders.put(coreDriver.getId(), customJdbcClassLoader);
return customJdbcClassLoader; return customJdbcClassLoader;
} catch (Exception e) { } catch (Exception e) {
DEException.throwException(e); DEException.throwException(e.getMessage());
} }
return null; return null;
} }
@ -691,7 +686,7 @@ public class CalciteProvider {
SchemaPlus rootSchema = buildSchema(datasourceRequest, calciteConnection); SchemaPlus rootSchema = buildSchema(datasourceRequest, calciteConnection);
addCustomFunctions(rootSchema); addCustomFunctions(rootSchema);
} catch (Exception e) { } catch (Exception e) {
DEException.throwException(e); DEException.throwException(e.getMessage());
} }
} }
@ -709,7 +704,7 @@ public class CalciteProvider {
rootSchema.removeSubSchema(datasourceSchemaDTO.getSchemaAlias()); rootSchema.removeSubSchema(datasourceSchemaDTO.getSchemaAlias());
} }
} catch (Exception e) { } catch (Exception e) {
DEException.throwException(e); DEException.throwException(e.getMessage());
} }
} }

View File

@ -125,11 +125,13 @@ public class DatasourceServer implements DatasourceApi {
if (Objects.equals(dataSourceDTO.getId(), dataSourceDTO.getPid())) { if (Objects.equals(dataSourceDTO.getId(), dataSourceDTO.getPid())) {
DEException.throwException(Translator.get("i18n_pid_not_eq_id")); DEException.throwException(Translator.get("i18n_pid_not_eq_id"));
} }
if (dataSourceDTO.getPid() != 0) {
List<Long> ids = new ArrayList<>(); List<Long> ids = new ArrayList<>();
getParents(dataSourceDTO.getPid(), ids); getParents(dataSourceDTO.getPid(), ids);
if (ids.contains(dataSourceDTO.getId())) { if (ids.contains(dataSourceDTO.getId())) {
DEException.throwException(Translator.get("i18n_pid_not_eq_id")); DEException.throwException(Translator.get("i18n_pid_not_eq_id"));
} }
}
dataSourceManage.move(dataSourceDTO); dataSourceManage.move(dataSourceDTO);
} }
case "rename" -> { case "rename" -> {

View File

@ -1,6 +1,7 @@
package io.dataease.datasource.type; package io.dataease.datasource.type;
import io.dataease.api.ds.vo.DatasourceConfiguration; import io.dataease.api.ds.vo.DatasourceConfiguration;
import io.dataease.exception.DEException;
import lombok.Data; import lombok.Data;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -25,7 +26,7 @@ public class Mysql extends DatasourceConfiguration {
} else { } else {
for (String illegalParameter : illegalParameters) { for (String illegalParameter : illegalParameters) {
if (getExtraParams().toLowerCase().contains(illegalParameter.toLowerCase())) { if (getExtraParams().toLowerCase().contains(illegalParameter.toLowerCase())) {
throw new RuntimeException("Illegal parameter: " + illegalParameter); DEException.throwException("Illegal parameter: " + illegalParameter);
} }
} }

View File

@ -78,13 +78,14 @@ public class HttpClientUtil {
* @return 响应结果字符串 * @return 响应结果字符串
*/ */
public static String get(String url, HttpClientConfig config) { public static String get(String url, HttpClientConfig config) {
CloseableHttpClient httpClient = buildHttpClient(url); CloseableHttpClient httpClient = null;
try {
httpClient = buildHttpClient(url);
HttpGet httpGet = new HttpGet(url); HttpGet httpGet = new HttpGet(url);
if (config == null) { if (config == null) {
config = new HttpClientConfig(); config = new HttpClientConfig();
} }
try {
httpGet.setConfig(config.buildRequestConfig()); httpGet.setConfig(config.buildRequestConfig());
Map<String, String> header = config.getHeader(); Map<String, String> header = config.getHeader();
@ -98,7 +99,9 @@ public class HttpClientUtil {
throw new DEException(SYSTEM_INNER_ERROR.code(), "HttpClient查询失败: " + e.getMessage()); throw new DEException(SYSTEM_INNER_ERROR.code(), "HttpClient查询失败: " + e.getMessage());
} finally { } finally {
try { try {
if(httpClient != null){
httpClient.close(); httpClient.close();
}
} catch (Exception e) { } catch (Exception e) {
logger.error("HttpClient关闭连接失败", e); logger.error("HttpClient关闭连接失败", e);
} }
@ -143,14 +146,14 @@ public class HttpClientUtil {
* @return 响应结果字符串 * @return 响应结果字符串
*/ */
public static String post(String url, String json, HttpClientConfig config) { public static String post(String url, String json, HttpClientConfig config) {
CloseableHttpClient httpClient = buildHttpClient(url); CloseableHttpClient httpClient = null;
try {
buildHttpClient(url);
HttpPost httpPost = new HttpPost(url); HttpPost httpPost = new HttpPost(url);
if (config == null) { if (config == null) {
config = new HttpClientConfig(); config = new HttpClientConfig();
} }
try {
httpPost.setConfig(config.buildRequestConfig()); httpPost.setConfig(config.buildRequestConfig());
Map<String, String> header = config.getHeader(); Map<String, String> header = config.getHeader();
for (String key : header.keySet()) { for (String key : header.keySet()) {
httpPost.addHeader(key, header.get(key)); httpPost.addHeader(key, header.get(key));
@ -168,7 +171,9 @@ public class HttpClientUtil {
throw new DEException(SYSTEM_INNER_ERROR.code(), "HttpClient查询失败: " + e.getMessage()); throw new DEException(SYSTEM_INNER_ERROR.code(), "HttpClient查询失败: " + e.getMessage());
} finally { } finally {
try { try {
if(httpClient != null){
httpClient.close(); httpClient.close();
}
} catch (Exception e) { } catch (Exception e) {
logger.error("HttpClient关闭连接失败", e); logger.error("HttpClient关闭连接失败", e);
} }
@ -195,14 +200,15 @@ public class HttpClientUtil {
* @return 响应结果字符串 * @return 响应结果字符串
*/ */
public static String post(String url, Map<String, String> body, HttpClientConfig config) { public static String post(String url, Map<String, String> body, HttpClientConfig config) {
CloseableHttpClient httpClient = buildHttpClient(url); CloseableHttpClient httpClient = null;
try {
buildHttpClient(url);
HttpPost httpPost = new HttpPost(url); HttpPost httpPost = new HttpPost(url);
if (config == null) { if (config == null) {
config = new HttpClientConfig(); config = new HttpClientConfig();
} }
try {
httpPost.setConfig(config.buildRequestConfig()); httpPost.setConfig(config.buildRequestConfig());
Map<String, String> header = config.getHeader(); Map<String, String> header = config.getHeader();
for (String key : header.keySet()) { for (String key : header.keySet()) {
httpPost.addHeader(key, header.get(key)); httpPost.addHeader(key, header.get(key));
@ -227,7 +233,9 @@ public class HttpClientUtil {
throw new DEException(SYSTEM_INNER_ERROR.code(), "HttpClient查询失败: " + e.getMessage()); throw new DEException(SYSTEM_INNER_ERROR.code(), "HttpClient查询失败: " + e.getMessage());
} finally { } finally {
try { try {
if(httpClient != null){
httpClient.close(); httpClient.close();
}
} catch (Exception e) { } catch (Exception e) {
logger.error("HttpClient关闭连接失败", e); logger.error("HttpClient关闭连接失败", e);
} }