forked from github/dataease
feat: 【数据源】用户可以通过JDBC连接字符串的配置连接到任意支持JDBC的数据库
This commit is contained in:
parent
814aee0e15
commit
bc1462c415
@ -2,18 +2,28 @@ package io.dataease.datasource.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class CHConfigration extends JdbcDTO {
|
||||
|
||||
private String driver = "ru.yandex.clickhouse.ClickHouseDriver";
|
||||
private String extraParams = "";
|
||||
|
||||
public String getJdbc() {
|
||||
// 连接参数先写死,后边要把编码、时区等参数放到数据源的设置中
|
||||
return "jdbc:clickhouse://HOSTNAME:PORT/DATABASE"
|
||||
.replace("HOSTNAME", getHost().trim())
|
||||
.replace("PORT", getPort().toString().trim())
|
||||
.replace("DATABASE", getDataBase().trim());
|
||||
if(StringUtils.isEmpty(extraParams.trim())){
|
||||
return "jdbc:clickhouse://HOSTNAME:PORT/DATABASE"
|
||||
.replace("HOSTNAME", getHost().trim())
|
||||
.replace("PORT", getPort().toString().trim())
|
||||
.replace("DATABASE", getDataBase().trim());
|
||||
}else {
|
||||
return "jdbc:clickhouse://HOSTNAME:PORT/DATABASE?EXTRA_PARAMS"
|
||||
.replace("HOSTNAME", getHost().trim())
|
||||
.replace("PORT", getPort().toString().trim())
|
||||
.replace("DATABASE", getDataBase().trim())
|
||||
.replace("EXTRA_PARAMS", getExtraParams().trim());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -2,18 +2,27 @@ package io.dataease.datasource.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class MysqlConfigration extends JdbcDTO {
|
||||
|
||||
private String driver = "com.mysql.cj.jdbc.Driver";
|
||||
private String extraParams = "characterEncoding=UTF-8&connectTimeout=5000&useSSL=false&allowPublicKeyRetrieval=true";
|
||||
|
||||
public String getJdbc() {
|
||||
// 连接参数先写死,后边要把编码、时区等参数放到数据源的设置中
|
||||
return "jdbc:mysql://HOSTNAME:PORT/DATABASE?characterEncoding=UTF-8&connectTimeout=5000&useSSL=false&allowPublicKeyRetrieval=true"
|
||||
.replace("HOSTNAME", getHost().trim())
|
||||
.replace("PORT", getPort().toString().trim())
|
||||
.replace("DATABASE", getDataBase().trim());
|
||||
if(StringUtils.isEmpty(extraParams.trim())){
|
||||
return "jdbc:mysql://HOSTNAME:PORT/DATABASE"
|
||||
.replace("HOSTNAME", getHost().trim())
|
||||
.replace("PORT", getPort().toString().trim())
|
||||
.replace("DATABASE", getDataBase().trim());
|
||||
}else {
|
||||
return "jdbc:mysql://HOSTNAME:PORT/DATABASE?EXTRA_PARAMS"
|
||||
.replace("HOSTNAME", getHost().trim())
|
||||
.replace("PORT", getPort().toString().trim())
|
||||
.replace("DATABASE", getDataBase().trim())
|
||||
.replace("EXTRA_PARAMS", getExtraParams().trim());
|
||||
}
|
||||
}
|
||||
}
|
@ -2,18 +2,27 @@ package io.dataease.datasource.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class PgConfigration extends JdbcDTO {
|
||||
|
||||
private String driver = "org.postgresql.Driver";
|
||||
|
||||
private String extraParams = "";
|
||||
public String getJdbc() {
|
||||
// 连接参数先写死,后边要把编码、时区等参数放到数据源的设置中
|
||||
return "jdbc:postgresql://HOSTNAME:PORT/DATABASE"
|
||||
.replace("HOSTNAME", getHost().trim())
|
||||
.replace("PORT", getPort().toString().trim())
|
||||
.replace("DATABASE", getDataBase().trim());
|
||||
if(StringUtils.isEmpty(extraParams.trim())){
|
||||
return "jdbc:postgresql://HOSTNAME:PORT/DATABASE"
|
||||
.replace("HOSTNAME", getHost().trim())
|
||||
.replace("PORT", getPort().toString().trim())
|
||||
.replace("DATABASE", getDataBase().trim());
|
||||
}else {
|
||||
return "jdbc:postgresql://HOSTNAME:PORT/DATABASE?EXTRA_PARAMS"
|
||||
.replace("HOSTNAME", getHost().trim())
|
||||
.replace("PORT", getPort().toString().trim())
|
||||
.replace("DATABASE", getDataBase().trim())
|
||||
.replace("EXTRA_PARAMS", getExtraParams().trim());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -2,17 +2,26 @@ package io.dataease.datasource.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class SqlServerConfigration extends JdbcDTO {
|
||||
private String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
|
||||
|
||||
private String extraParams = "";
|
||||
public String getJdbc(){
|
||||
return "jdbc:sqlserver://HOSTNAME:PORT;DatabaseName=DATABASE"
|
||||
.replace("HOSTNAME", getHost().trim())
|
||||
.replace("PORT", getPort().toString().trim())
|
||||
.replace("DATABASE", getDataBase().trim());
|
||||
if(StringUtils.isEmpty(extraParams.trim())){
|
||||
return "jdbc:sqlserver://HOSTNAME:PORT;DatabaseName=DATABASE"
|
||||
.replace("HOSTNAME", getHost().trim())
|
||||
.replace("PORT", getPort().toString().trim())
|
||||
.replace("DATABASE", getDataBase().trim());
|
||||
}else {
|
||||
return "jdbc:sqlserver://HOSTNAME:PORT;DatabaseName=DATABASE;EXTRA_PARAMS"
|
||||
.replace("HOSTNAME", getHost().trim())
|
||||
.replace("PORT", getPort().toString().trim())
|
||||
.replace("DATABASE", getDataBase().trim())
|
||||
.replace("EXTRA_PARAMS", getExtraParams().trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,8 @@ import io.dataease.controller.ResultHolder;
|
||||
import io.dataease.controller.request.DatasourceUnionRequest;
|
||||
import io.dataease.controller.sys.base.BaseGridRequest;
|
||||
import io.dataease.controller.sys.base.ConditionEntity;
|
||||
import io.dataease.datasource.dto.DBTableDTO;
|
||||
import io.dataease.datasource.dto.MysqlConfigration;
|
||||
import io.dataease.datasource.dto.OracleConfigration;
|
||||
import io.dataease.datasource.constants.DatasourceTypes;
|
||||
import io.dataease.datasource.dto.*;
|
||||
import io.dataease.datasource.provider.DatasourceProvider;
|
||||
import io.dataease.datasource.provider.ProviderFactory;
|
||||
import io.dataease.datasource.request.DatasourceRequest;
|
||||
@ -90,12 +89,32 @@ public class DatasourceService {
|
||||
request.setSort("update_time desc");
|
||||
List<DatasourceDTO> datasourceDTOS = extDataSourceMapper.queryUnion(request);
|
||||
datasourceDTOS.forEach(datasourceDTO -> {
|
||||
if(datasourceDTO.getType().equalsIgnoreCase("mysql")){
|
||||
datasourceDTO.setConfiguration(JSONObject.toJSONString(new Gson().fromJson(datasourceDTO.getConfiguration(), MysqlConfigration.class)) );
|
||||
};
|
||||
if(datasourceDTO.getType().equalsIgnoreCase("oracle")){
|
||||
datasourceDTO.setConfiguration(JSONObject.toJSONString(new Gson().fromJson(datasourceDTO.getConfiguration(), OracleConfigration.class)));
|
||||
};
|
||||
DatasourceTypes datasourceType = DatasourceTypes.valueOf(datasourceDTO.getType());
|
||||
try{
|
||||
switch (datasourceType) {
|
||||
case mysql:
|
||||
case mariadb:
|
||||
case de_doris:
|
||||
case ds_doris:
|
||||
datasourceDTO.setConfiguration(JSONObject.toJSONString(new Gson().fromJson(datasourceDTO.getConfiguration(), MysqlConfigration.class)) );
|
||||
break;
|
||||
case sqlServer:
|
||||
datasourceDTO.setConfiguration(JSONObject.toJSONString(new Gson().fromJson(datasourceDTO.getConfiguration(), SqlServerConfigration.class)) );
|
||||
break;
|
||||
case oracle:
|
||||
datasourceDTO.setConfiguration(JSONObject.toJSONString(new Gson().fromJson(datasourceDTO.getConfiguration(), OracleConfigration.class)) );
|
||||
break;
|
||||
case pg:
|
||||
datasourceDTO.setConfiguration(JSONObject.toJSONString(new Gson().fromJson(datasourceDTO.getConfiguration(), PgConfigration.class)) );
|
||||
break;
|
||||
case ck:
|
||||
datasourceDTO.setConfiguration(JSONObject.toJSONString(new Gson().fromJson(datasourceDTO.getConfiguration(), CHConfigration.class)) );
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}catch (Exception ignore){}
|
||||
|
||||
});
|
||||
return datasourceDTOS;
|
||||
}
|
||||
|
@ -1150,7 +1150,8 @@ export default {
|
||||
please_input_acquire_increment: 'Please enter the growth number',
|
||||
please_input_connect_timeout: 'Please enter the connection timeout (seconds)',
|
||||
no_less_then_0: 'Parameters in advanced settings cannot be less than zero',
|
||||
priority: 'Advanced setting'
|
||||
priority: 'Advanced setting',
|
||||
extra_params: 'Extra JDBC connection string'
|
||||
},
|
||||
pblink: {
|
||||
key_pwd: 'Please enter the password to open the link',
|
||||
|
@ -1153,7 +1153,8 @@ export default {
|
||||
please_input_acquire_increment: '請輸入增長數',
|
||||
please_input_connect_timeout: '請輸入連接超時(秒)',
|
||||
no_less_then_0: '高級設置中的參數不能小于零',
|
||||
priority: '高級設置'
|
||||
priority: '高級設置',
|
||||
extra_params: '額外的JDBC連接字符串'
|
||||
},
|
||||
pblink: {
|
||||
key_pwd: '請輸入密碼打開鏈接',
|
||||
|
@ -1158,7 +1158,8 @@ export default {
|
||||
data_mode: '数据模式',
|
||||
direct: '直连模式',
|
||||
extract: '抽取模式',
|
||||
all_compute_mode: '直连、抽取模式'
|
||||
all_compute_mode: '直连、抽取模式',
|
||||
extra_params: '额外的JDBC连接字符串'
|
||||
},
|
||||
pblink: {
|
||||
key_pwd: '请输入密码打开链接',
|
||||
|
@ -52,6 +52,10 @@
|
||||
<el-input v-model="form.configuration.esPassword" autocomplete="off" show-password />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item v-if="form.configuration.dataSourceType=='jdbc' && form.type!=='oracle'" :label="$t('datasource.extra_params')" >
|
||||
<el-input v-model="form.configuration.extraParams" autocomplete="off" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item v-if="form.configuration.dataSourceType=='jdbc'" :label="$t('datasource.port')" prop="configuration.port">
|
||||
<el-input v-model="form.configuration.port" autocomplete="off" />
|
||||
</el-form-item>
|
||||
@ -155,14 +159,14 @@ export default {
|
||||
'configuration.connectTimeout': [{ required: true, message: this.$t('datasource.please_input_connect_timeout'), trigger: 'change' }]
|
||||
},
|
||||
allTypes: [
|
||||
{ name: 'mysql', label: 'MySQL', type: 'jdbc'},
|
||||
{ name: 'oracle', label: 'Oracle', type: 'jdbc' },
|
||||
{ name: 'sqlServer', label: 'SQL Server', type: 'jdbc' },
|
||||
{ name: 'pg', label: 'PostgreSQL', type: 'jdbc' },
|
||||
{ name: 'mysql', label: 'MySQL', type: 'jdbc', extraParams: 'characterEncoding=UTF-8&connectTimeout=5000&useSSL=false&allowPublicKeyRetrieval=true'},
|
||||
{ name: 'oracle', label: 'Oracle', type: 'jdbc'},
|
||||
{ name: 'sqlServer', label: 'SQL Server', type: 'jdbc', extraParams: ''},
|
||||
{ name: 'pg', label: 'PostgreSQL', type: 'jdbc', extraParams: '' },
|
||||
{ name: 'es', label: 'Elasticsearch', type: 'es' },
|
||||
{ name: 'mariadb', label: 'MariaDB', type: 'jdbc' },
|
||||
{ name: 'ds_doris', label: 'Doris', type: 'jdbc' },
|
||||
{ name: 'ck', label: 'ClickHouse', type: 'jdbc' }
|
||||
{ name: 'mariadb', label: 'MariaDB', type: 'jdbc', extraParams: 'characterEncoding=UTF-8&connectTimeout=5000&useSSL=false&allowPublicKeyRetrieval=true' },
|
||||
{ name: 'ds_doris', label: 'Doris', type: 'jdbc', extraParams: 'characterEncoding=UTF-8&connectTimeout=5000&useSSL=false&allowPublicKeyRetrieval=true' },
|
||||
{ name: 'ck', label: 'ClickHouse', type: 'jdbc', extraParams: '' }
|
||||
],
|
||||
schemas: [],
|
||||
canEdit: false,
|
||||
@ -303,6 +307,7 @@ export default {
|
||||
for (let i = 0; i < this.allTypes.length; i++) {
|
||||
if (this.allTypes[i].name === this.form.type) {
|
||||
this.form.configuration.dataSourceType = this.allTypes[i].type
|
||||
this.form.configuration.extraParams = this.allTypes[i].extraParams
|
||||
}
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user