forked from github/dataease
feat(数据源): 添加oracle 数据源时,指定schema
This commit is contained in:
parent
b9ac54b67e
commit
6ce1adf57a
@ -61,4 +61,11 @@ public class DatasourceController {
|
||||
public List<DBTableDTO> getTables(@RequestBody Datasource datasource) throws Exception {
|
||||
return datasourceService.getTables(datasource);
|
||||
}
|
||||
|
||||
@PostMapping("/getSchema")
|
||||
public List<String> getSchema(@RequestBody Datasource datasource) throws Exception {
|
||||
return datasourceService.getSchema(datasource);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ public class OracleConfigration extends JdbcDTO {
|
||||
|
||||
private String driver = "oracle.jdbc.driver.OracleDriver";
|
||||
private String connectionType;
|
||||
private String schema;
|
||||
|
||||
public String getJdbc() {
|
||||
// 连接参数先写死,后边要把编码、时区等参数放到数据源的设置中
|
||||
|
@ -30,4 +30,6 @@ public abstract class DatasourceProvider {
|
||||
abstract public Map<String, List> fetchResultAndField(DatasourceRequest datasourceRequest) throws Exception;
|
||||
|
||||
abstract public void handleDatasource(DatasourceRequest datasourceRequest, String type) throws Exception;
|
||||
|
||||
abstract public List<String> getSchema(DatasourceRequest datasourceRequest) throws Exception;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package io.dataease.datasource.provider;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.mchange.v2.c3p0.ComboPooledDataSource;
|
||||
import io.dataease.controller.handler.annotation.I18n;
|
||||
import io.dataease.datasource.constants.DatasourceTypes;
|
||||
import io.dataease.datasource.dto.MysqlConfigration;
|
||||
import io.dataease.datasource.dto.OracleConfigration;
|
||||
@ -9,10 +10,12 @@ import io.dataease.datasource.dto.SqlServerConfigration;
|
||||
import io.dataease.datasource.dto.TableFiled;
|
||||
import io.dataease.datasource.request.DatasourceRequest;
|
||||
import io.dataease.exception.DataEaseException;
|
||||
import io.dataease.i18n.Translator;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.beans.PropertyVetoException;
|
||||
import java.sql.*;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.*;
|
||||
|
||||
@Service("jdbc")
|
||||
@ -212,6 +215,31 @@ public class JdbcProvider extends DatasourceProvider {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSchema(DatasourceRequest datasourceRequest) throws Exception {
|
||||
List<String> schemas = new ArrayList<>();
|
||||
String queryStr = getSchemaSql(datasourceRequest);
|
||||
Connection con = null;
|
||||
try {
|
||||
con = getConnection(datasourceRequest);
|
||||
Statement statement = con.createStatement();
|
||||
ResultSet resultSet = statement.executeQuery(queryStr);
|
||||
while (resultSet.next()) {
|
||||
schemas.add(resultSet.getString(1));
|
||||
}
|
||||
resultSet.close();
|
||||
statement.close();
|
||||
return schemas;
|
||||
} catch (Exception e) {
|
||||
DataEaseException.throwException(e);
|
||||
} finally {
|
||||
if(con != null){
|
||||
con.close();
|
||||
}
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TableFiled> getTableFileds(DatasourceRequest datasourceRequest) throws Exception {
|
||||
List<TableFiled> list = new LinkedList<>();
|
||||
@ -466,7 +494,7 @@ public class JdbcProvider extends DatasourceProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private String getTablesSql(DatasourceRequest datasourceRequest) {
|
||||
private String getTablesSql(DatasourceRequest datasourceRequest) throws Exception {
|
||||
DatasourceTypes datasourceType = DatasourceTypes.valueOf(datasourceRequest.getDatasource().getType());
|
||||
switch (datasourceType) {
|
||||
case mysql:
|
||||
@ -477,7 +505,21 @@ public class JdbcProvider extends DatasourceProvider {
|
||||
SqlServerConfigration sqlServerConfigration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), SqlServerConfigration.class);
|
||||
return "SELECT TABLE_NAME FROM DATABASE.INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE';".replace("DATABASE", sqlServerConfigration.getDataBase());
|
||||
case oracle:
|
||||
return "select TABLE_NAME from USER_TABLES";
|
||||
OracleConfigration oracleConfigration = new Gson().fromJson(datasourceRequest.getDatasource().getConfiguration(), OracleConfigration.class);
|
||||
if(StringUtils.isEmpty(oracleConfigration.getSchema())){
|
||||
throw new Exception(Translator.get("i18n_schema_is_empty"));
|
||||
}
|
||||
return "select table_name, owner from all_tables where owner='" + oracleConfigration.getSchema() + "'";
|
||||
default:
|
||||
return "show tables;";
|
||||
}
|
||||
}
|
||||
|
||||
private String getSchemaSql(DatasourceRequest datasourceRequest) {
|
||||
DatasourceTypes datasourceType = DatasourceTypes.valueOf(datasourceRequest.getDatasource().getType());
|
||||
switch (datasourceType) {
|
||||
case oracle:
|
||||
return "select * from all_users";
|
||||
default:
|
||||
return "show tables;";
|
||||
}
|
||||
|
@ -120,6 +120,13 @@ public class DatasourceService {
|
||||
datasourceProvider.checkStatus(datasourceRequest);
|
||||
}
|
||||
|
||||
public List<String> getSchema(Datasource datasource) throws Exception {
|
||||
DatasourceProvider datasourceProvider = ProviderFactory.getProvider(datasource.getType());
|
||||
DatasourceRequest datasourceRequest = new DatasourceRequest();
|
||||
datasourceRequest.setDatasource(datasource);
|
||||
return datasourceProvider.getSchema(datasourceRequest);
|
||||
}
|
||||
|
||||
public List<DBTableDTO> getTables(Datasource datasource) throws Exception {
|
||||
Datasource ds = datasourceMapper.selectByPrimaryKey(datasource.getId());
|
||||
DatasourceProvider datasourceProvider = ProviderFactory.getProvider(ds.getType());
|
||||
|
@ -261,3 +261,4 @@ i18n_sql_delete_not_matching=The data column of incremental delete SQL does not
|
||||
i18n_cst_ds_tb_or_field_deleted=Custom dataset union data is deleted or field changed,can not display
|
||||
i18n_no_all_delete_privilege_folder=This folder have sources which have no manage or view privilege,Can Not Be Deleted.
|
||||
i18n_excel_field_repeat=Excel exists repeat field,please fix and upload again.
|
||||
i18n_schema_is_empty=Database schema is empty
|
@ -260,3 +260,4 @@ i18n_sql_delete_not_matching=增量删除 sql 的数据列与数据集不匹配,
|
||||
i18n_cst_ds_tb_or_field_deleted=自定义数据集所关联数据被删除或字段发生变化,无法正常显示
|
||||
i18n_no_all_delete_privilege_folder=该目录下存在没有管理权限或查看权限的资源,无法删除
|
||||
i18n_excel_field_repeat=Excel存在重复字段,请修改后重新上传
|
||||
i18n_schema_is_empty=数据库 Schema 为空
|
||||
|
@ -263,3 +263,4 @@ i18n_sql_delete_not_matching=增量刪除 sql 的數據列與數據集不匹配,
|
||||
i18n_cst_ds_tb_or_field_deleted=自定義數據集所關聯數據被刪除或字段發生變化,無法正常顯示
|
||||
i18n_no_all_delete_privilege_folder=該目錄下存在沒有管理權限或查看權限的資源,無法刪除
|
||||
i18n_excel_field_repeat=Excel存在重復字段,請修改後重新上傳
|
||||
i18n_schema_is_empty=數據庫 Schema 為空
|
@ -50,4 +50,13 @@ export function validateDs(data) {
|
||||
})
|
||||
}
|
||||
|
||||
export default { dsGrid, addDs, editDs, delDs, validateDs, listDatasource }
|
||||
export function getSchema(data) {
|
||||
return request({
|
||||
url: 'datasource/getSchema/',
|
||||
method: 'post',
|
||||
loading: true,
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
export default { dsGrid, addDs, editDs, delDs, validateDs, listDatasource, getSchema }
|
||||
|
@ -890,7 +890,13 @@ export default {
|
||||
delete_warning: 'Confirm to delete?',
|
||||
input_name: 'Please input name',
|
||||
input_limit_2_25: '2-25 chars',
|
||||
input_limit_0_50: '0-50 chars'
|
||||
input_limit_0_50: '0-50 chars',
|
||||
oracle_connection_type: 'Service Name/SID',
|
||||
oracle_sid: 'SID',
|
||||
oracle_service_name: 'Service Name',
|
||||
get_schema: 'Get Schema',
|
||||
schema: 'Database Schema',
|
||||
please_choose_schema: 'Please select Schema',
|
||||
},
|
||||
pblink: {
|
||||
key_pwd: 'Please enter the password to open the link',
|
||||
|
@ -932,7 +932,13 @@ export default {
|
||||
delete_warning: '確認刪除?',
|
||||
input_name: '請輸入名稱',
|
||||
input_limit_2_25: '2-25字符',
|
||||
input_limit_0_50: '0-50字符'
|
||||
input_limit_0_50: '0-50字符',
|
||||
oracle_connection_type: '服务名/SID',
|
||||
oracle_sid: 'SID',
|
||||
oracle_service_name: '服务名',
|
||||
get_schema: '获取 Schema',
|
||||
schema: '数据库 Schema',
|
||||
please_choose_schema: '请选择数据库 Schema',
|
||||
},
|
||||
pblink: {
|
||||
key_pwd: '請輸入密碼打開鏈接',
|
||||
|
@ -894,7 +894,10 @@ export default {
|
||||
input_limit_0_50: '0-50字符',
|
||||
oracle_connection_type: '服务名/SID',
|
||||
oracle_sid: 'SID',
|
||||
oracle_service_name: '服务名'
|
||||
oracle_service_name: '服务名',
|
||||
get_schema: '获取 Schema',
|
||||
schema: '数据库 Schema',
|
||||
please_choose_schema: '请选择数据库 Schema',
|
||||
},
|
||||
pblink: {
|
||||
key_pwd: '请输入密码打开链接',
|
||||
|
@ -46,6 +46,23 @@
|
||||
<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>
|
||||
<el-form-item v-if="form.type=='oracle'">
|
||||
<el-button icon="el-icon-plus" size="mini" @click="getSchema()">
|
||||
{{ $t('datasource.get_schema') }}
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item :label="$t('datasource.schema')" v-if="form.type=='oracle'">
|
||||
<el-select v-model="form.configuration.schema" :placeholder="$t('datasource.please_choose_schema')" class="select-width" :disabled="formType=='modify'" >
|
||||
<el-option
|
||||
v-for="item in schemas"
|
||||
:key="item"
|
||||
:label="item"
|
||||
:value="item"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
</el-form>
|
||||
<div v-if="canEdit" slot="footer" class="dialog-footer">
|
||||
<el-button v-if="formType==='add'?true: hasDataPermission('manage',params.privileges)" @click="validaDatasource">{{ $t('commons.validate') }}</el-button>
|
||||
@ -61,7 +78,7 @@
|
||||
|
||||
<script>
|
||||
import LayoutContent from '@/components/business/LayoutContent'
|
||||
import { addDs, editDs, validateDs } from '@/api/system/datasource'
|
||||
import {addDs, editDs, getSchema, validateDs} from '@/api/system/datasource'
|
||||
export default {
|
||||
name: 'DsForm',
|
||||
components: { LayoutContent },
|
||||
@ -84,9 +101,11 @@ export default {
|
||||
'configuration.username': [{ required: true, message: this.$t('datasource.please_input_user_name'), trigger: 'blur' }],
|
||||
'configuration.password': [{ required: true, message: this.$t('datasource.please_input_password'), trigger: 'change' }],
|
||||
'configuration.host': [{ required: true, message: this.$t('datasource.please_input_host'), trigger: 'change' }],
|
||||
'configuration.port': [{ required: true, message: this.$t('datasource.please_input_port'), trigger: 'change' }]
|
||||
'configuration.port': [{ required: true, message: this.$t('datasource.please_input_port'), trigger: 'change' }],
|
||||
'configuration.schema': [{ required: true, message: this.$t('datasource.please_choose_schema'), trigger: 'change' }]
|
||||
},
|
||||
allTypes: [{ name: 'mysql', label: 'MySQL', type: 'jdbc' }, { name: 'oracle', label: 'Oracle', type: 'jdbc' }],
|
||||
schemas: [],
|
||||
canEdit: false
|
||||
}
|
||||
},
|
||||
@ -129,10 +148,13 @@ export default {
|
||||
this.$refs.dsForm.resetFields()
|
||||
},
|
||||
save() {
|
||||
if(!this.form.configuration.schema){
|
||||
this.$message.error(this.$t('datasource.please_choose_schema'))
|
||||
return
|
||||
}
|
||||
this.$refs.dsForm.validate(valid => {
|
||||
if (valid) {
|
||||
const method = this.formType === 'add' ? addDs : editDs
|
||||
// this.form.configuration = JSON.stringify(this.form.configuration)
|
||||
const form = JSON.parse(JSON.stringify(this.form))
|
||||
form.configuration = JSON.stringify(form.configuration)
|
||||
method(form).then(res => {
|
||||
@ -145,12 +167,25 @@ export default {
|
||||
}
|
||||
})
|
||||
},
|
||||
getSchema(){
|
||||
this.$refs.dsForm.validate(valid => {
|
||||
if (valid) {
|
||||
const data = JSON.parse(JSON.stringify(this.form))
|
||||
data.configuration = JSON.stringify(data.configuration)
|
||||
getSchema(data).then(res => {
|
||||
this.schemas = res.data
|
||||
this.$success(this.$t('datasource.validate_success'))
|
||||
})
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
})
|
||||
},
|
||||
validaDatasource() {
|
||||
this.$refs.dsForm.validate(valid => {
|
||||
if (valid) {
|
||||
const data = JSON.parse(JSON.stringify(this.form))
|
||||
data.configuration = JSON.stringify(data.configuration)
|
||||
|
||||
validateDs(data).then(res => {
|
||||
this.$success(this.$t('datasource.validate_success'))
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user