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

Pr@dev v2@fix datasource
This commit is contained in:
taojinlong 2023-10-26 23:17:31 -05:00 committed by GitHub
commit 5ae30cc181
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 3 deletions

View File

@ -34,6 +34,7 @@ import io.dataease.datasource.provider.ApiUtils;
import io.dataease.datasource.provider.CalciteProvider;
import io.dataease.datasource.provider.ExcelUtils;
import io.dataease.datasource.request.DatasourceRequest;
import io.dataease.datasource.type.Pg;
import io.dataease.engine.constant.SQLConstants;
import io.dataease.exception.DEException;
import io.dataease.i18n.Translator;
@ -265,7 +266,9 @@ public class DatasourceServer implements DatasourceApi {
DEException.throwException("Failed to create table " + datasourceRequest.getTable());
}
}
datasourceSyncManage.extractExcelData(coreDatasource, "all_scope");
commonThreadPool.addTask(() -> {
datasourceSyncManage.extractExcelData(coreDatasource, "all_scope");
});
} else if (dataSourceDTO.getType().equals(DatasourceConfiguration.DatasourceType.API.name())) {
CoreDatasourceTask coreDatasourceTask = new CoreDatasourceTask();
BeanUtils.copyBean(coreDatasourceTask, dataSourceDTO.getSyncSetting());
@ -298,11 +301,28 @@ public class DatasourceServer implements DatasourceApi {
}
}
} else {
checkParams(dataSourceDTO.getConfiguration());
calciteProvider.update(dataSourceDTO);
}
return dataSourceDTO;
}
private static void checkParams(String configurationStr) {
DatasourceConfiguration configuration = JsonUtil.parseObject(configurationStr, DatasourceConfiguration.class);
if(configuration.getInitialPoolSize() < configuration.getMinPoolSize()){
DEException.throwException("初始连接数不能小于最小连接数!");
}
if(configuration.getInitialPoolSize() > configuration.getMaxPoolSize()){
DEException.throwException("初始连接数不能大于最大连接数!");
}
if(configuration.getMaxPoolSize() < configuration.getMinPoolSize()){
DEException.throwException("最大连接数不能小于最小连接数!");
}
if(configuration.getQueryTimeout() < 0){
DEException.throwException("查询超时不能小于0");
}
}
private static void checkName(List<String> tables) {
for (int i = 0; i < tables.size() - 1; i++) {
for (int j = i + 1; j < tables.size(); j++) {
@ -419,6 +439,7 @@ public class DatasourceServer implements DatasourceApi {
dataSourceManage.innerEdit(requestDatasource);
}
} else {
checkParams(dataSourceDTO.getConfiguration());
dataSourceManage.innerEdit(requestDatasource);
calciteProvider.update(dataSourceDTO);
}

View File

@ -13,7 +13,7 @@ import java.util.List;
public class Mysql extends DatasourceConfiguration {
private String driver = "com.mysql.cj.jdbc.Driver";
private String extraParams = "characterEncoding=UTF-8&connectTimeout=5000&useSSL=false&allowPublicKeyRetrieval=true&zeroDateTimeBehavior=convertToNull";
private List<String> illegalParameters = Arrays.asList("autoDeserialize", "queryInterceptors", "statementInterceptors", "detectCustomCollations");
private List<String> illegalParameters = Arrays.asList("autoDeserialize", "queryInterceptors", "statementInterceptors", "detectCustomCollations", "allowloadlocalinfile", "allowUrlInLocalInfile", "allowLoadLocalInfileInPath");
private List<String> showTableSqls = Arrays.asList("show tables");
public String getJdbc() {
@ -24,7 +24,7 @@ public class Mysql extends DatasourceConfiguration {
.replace("DATABASE", getDataBase().trim());
} else {
for (String illegalParameter : illegalParameters) {
if (getExtraParams().contains(illegalParameter)) {
if (getExtraParams().toLowerCase().contains(illegalParameter.toLowerCase())) {
throw new RuntimeException("Illegal parameter: " + illegalParameter);
}
}