mirror of
https://github.com/dataease/dataease.git
synced 2026-05-23 13:58:26 +08:00
perf: 使用 JdbcUrl 连接方式的数据源无法使用 SQLBot 问数
This commit is contained in:
committed by
fit2cloud-chenyw
parent
f2b4572220
commit
cf400dc0d5
@@ -472,6 +472,7 @@ public class DatasetSQLBotManage {
|
||||
} else {
|
||||
config_json = EncryptUtils.aesDecrypt(dsConfig.toString()).toString();
|
||||
config = JsonUtil.parseObject(config_json, Configuration.class);
|
||||
config.convertJdbcUrl();
|
||||
}
|
||||
DataSQLBotAssistantVO vo = new DataSQLBotAssistantVO();
|
||||
vo.setDataBase(config.getDataBase());
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.springframework.stereotype.Component;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Data
|
||||
@Component("impala")
|
||||
@@ -60,4 +61,28 @@ public class Impala extends DatasourceConfiguration {
|
||||
}
|
||||
return jdbcUrl;
|
||||
}
|
||||
|
||||
private static final Pattern DB_NAME_PATTERN = Pattern.compile("//[^/]+/([^?;]+)");
|
||||
|
||||
@Override
|
||||
protected Pattern getDatabasePattern() {
|
||||
return DB_NAME_PATTERN;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void parseParameters(String jdbcUrl) {
|
||||
if (jdbcUrl.contains(";")) {
|
||||
String[] parts = jdbcUrl.split(";");
|
||||
for (int i = 1; i < parts.length; i++) {
|
||||
String[] keyValue = parts[i].split("=", 2);
|
||||
if (keyValue.length == 2) {
|
||||
getParameters().put(keyValue[0], keyValue[1]);
|
||||
}
|
||||
}
|
||||
if (getParameters().containsKey("AuthMech")) {
|
||||
getParameters().put("authentication", getParameters().get("AuthMech"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@ import lombok.Data;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Data
|
||||
@Component("oracle")
|
||||
public class Oracle extends DatasourceConfiguration {
|
||||
@@ -31,4 +34,19 @@ public class Oracle extends DatasourceConfiguration {
|
||||
.replace("DATABASE", getDataBase().trim());
|
||||
}
|
||||
}
|
||||
|
||||
private static final Pattern SERVICE_PATTERN = Pattern.compile(":@//[^/]+/([^?]+)");
|
||||
private static final Pattern SID_PATTERN = Pattern.compile(":@[^:]+:(\\d+):([^?]+)");
|
||||
@Override
|
||||
protected void convertDatabase(String jdbcUrl) {
|
||||
Matcher serviceMatcher = SERVICE_PATTERN.matcher(jdbcUrl);
|
||||
if (serviceMatcher.find()) {
|
||||
setDataBase(serviceMatcher.group(1));
|
||||
} else {
|
||||
Matcher sidMatcher = SID_PATTERN.matcher(jdbcUrl);
|
||||
if (sidMatcher.find()) {
|
||||
setDataBase(sidMatcher.group(2));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.springframework.stereotype.Component;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Data
|
||||
@Component("pg")
|
||||
@@ -58,4 +59,10 @@ public class Pg extends DatasourceConfiguration {
|
||||
}
|
||||
return jdbcUrl;
|
||||
}
|
||||
|
||||
private static final Pattern DB_NAME_PATTERN = Pattern.compile("//[^/]+/([^?]+)");
|
||||
@Override
|
||||
protected Pattern getDatabasePattern() {
|
||||
return DB_NAME_PATTERN;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,10 @@ import org.springframework.stereotype.Component;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static java.awt.SystemColor.info;
|
||||
|
||||
@Data
|
||||
@Component("redshift")
|
||||
@@ -40,4 +44,22 @@ public class Redshift extends DatasourceConfiguration {
|
||||
}
|
||||
return jdbcUrl;
|
||||
}
|
||||
|
||||
private static final Pattern DB_NAME_PATTERN = Pattern.compile("//[^/]+/([^?]+)");
|
||||
|
||||
@Override
|
||||
protected Pattern getDatabasePattern() {
|
||||
return DB_NAME_PATTERN;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void convertParameters() {
|
||||
Map<String, String> parameters = getParameters();
|
||||
if (parameters.containsKey("UID")) {
|
||||
setUsername(parameters.get("UID"));
|
||||
}
|
||||
if (parameters.containsKey("PWD")) {
|
||||
setPassword(parameters.get("PWD"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Data
|
||||
@Component("sqlServer")
|
||||
@@ -37,4 +38,11 @@ public class Sqlserver extends DatasourceConfiguration {
|
||||
.replace("EXTRA_PARAMS", getExtraParams().trim());
|
||||
}
|
||||
}
|
||||
|
||||
private static final Pattern DB_NAME_PATTERN = Pattern.compile(";databaseName=([^;]+)");
|
||||
|
||||
@Override
|
||||
protected Pattern getDatabasePattern() {
|
||||
return DB_NAME_PATTERN;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user