From 6ce1adf57ab022f7d5a1f5f57868269589e63b63 Mon Sep 17 00:00:00 2001 From: taojinlong Date: Mon, 5 Jul 2021 12:17:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=95=B0=E6=8D=AE=E6=BA=90):=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0oracle=20=E6=95=B0=E6=8D=AE=E6=BA=90=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E6=8C=87=E5=AE=9Aschema?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DatasourceController.java | 7 +++ .../datasource/dto/OracleConfigration.java | 1 + .../provider/DatasourceProvider.java | 2 + .../datasource/provider/JdbcProvider.java | 46 ++++++++++++++++++- .../datasource/service/DatasourceService.java | 7 +++ .../resources/i18n/messages_en_US.properties | 1 + .../resources/i18n/messages_zh_CN.properties | 1 + .../resources/i18n/messages_zh_TW.properties | 1 + frontend/src/api/system/datasource.js | 11 ++++- frontend/src/lang/en.js | 8 +++- frontend/src/lang/tw.js | 8 +++- frontend/src/lang/zh.js | 5 +- frontend/src/views/system/datasource/form.vue | 43 +++++++++++++++-- 13 files changed, 131 insertions(+), 10 deletions(-) diff --git a/backend/src/main/java/io/dataease/datasource/controller/DatasourceController.java b/backend/src/main/java/io/dataease/datasource/controller/DatasourceController.java index 6cf2e10c85..5445953b0a 100644 --- a/backend/src/main/java/io/dataease/datasource/controller/DatasourceController.java +++ b/backend/src/main/java/io/dataease/datasource/controller/DatasourceController.java @@ -61,4 +61,11 @@ public class DatasourceController { public List getTables(@RequestBody Datasource datasource) throws Exception { return datasourceService.getTables(datasource); } + + @PostMapping("/getSchema") + public List getSchema(@RequestBody Datasource datasource) throws Exception { + return datasourceService.getSchema(datasource); + } + + } diff --git a/backend/src/main/java/io/dataease/datasource/dto/OracleConfigration.java b/backend/src/main/java/io/dataease/datasource/dto/OracleConfigration.java index 6323791f90..6cebb06f13 100644 --- a/backend/src/main/java/io/dataease/datasource/dto/OracleConfigration.java +++ b/backend/src/main/java/io/dataease/datasource/dto/OracleConfigration.java @@ -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() { // 连接参数先写死,后边要把编码、时区等参数放到数据源的设置中 diff --git a/backend/src/main/java/io/dataease/datasource/provider/DatasourceProvider.java b/backend/src/main/java/io/dataease/datasource/provider/DatasourceProvider.java index 62cf6476cc..405d4a17c5 100644 --- a/backend/src/main/java/io/dataease/datasource/provider/DatasourceProvider.java +++ b/backend/src/main/java/io/dataease/datasource/provider/DatasourceProvider.java @@ -30,4 +30,6 @@ public abstract class DatasourceProvider { abstract public Map fetchResultAndField(DatasourceRequest datasourceRequest) throws Exception; abstract public void handleDatasource(DatasourceRequest datasourceRequest, String type) throws Exception; + + abstract public List getSchema(DatasourceRequest datasourceRequest) throws Exception; } diff --git a/backend/src/main/java/io/dataease/datasource/provider/JdbcProvider.java b/backend/src/main/java/io/dataease/datasource/provider/JdbcProvider.java index 98f70cb58d..b0da9a2813 100644 --- a/backend/src/main/java/io/dataease/datasource/provider/JdbcProvider.java +++ b/backend/src/main/java/io/dataease/datasource/provider/JdbcProvider.java @@ -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 getSchema(DatasourceRequest datasourceRequest) throws Exception { + List 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 getTableFileds(DatasourceRequest datasourceRequest) throws Exception { List 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;"; } diff --git a/backend/src/main/java/io/dataease/datasource/service/DatasourceService.java b/backend/src/main/java/io/dataease/datasource/service/DatasourceService.java index ca40861717..0697f38db3 100644 --- a/backend/src/main/java/io/dataease/datasource/service/DatasourceService.java +++ b/backend/src/main/java/io/dataease/datasource/service/DatasourceService.java @@ -120,6 +120,13 @@ public class DatasourceService { datasourceProvider.checkStatus(datasourceRequest); } + public List getSchema(Datasource datasource) throws Exception { + DatasourceProvider datasourceProvider = ProviderFactory.getProvider(datasource.getType()); + DatasourceRequest datasourceRequest = new DatasourceRequest(); + datasourceRequest.setDatasource(datasource); + return datasourceProvider.getSchema(datasourceRequest); + } + public List getTables(Datasource datasource) throws Exception { Datasource ds = datasourceMapper.selectByPrimaryKey(datasource.getId()); DatasourceProvider datasourceProvider = ProviderFactory.getProvider(ds.getType()); diff --git a/backend/src/main/resources/i18n/messages_en_US.properties b/backend/src/main/resources/i18n/messages_en_US.properties index 6d9f527bea..e0a4e80cf9 100644 --- a/backend/src/main/resources/i18n/messages_en_US.properties +++ b/backend/src/main/resources/i18n/messages_en_US.properties @@ -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 \ No newline at end of file diff --git a/backend/src/main/resources/i18n/messages_zh_CN.properties b/backend/src/main/resources/i18n/messages_zh_CN.properties index 530abfe53f..4ab1ba93ff 100644 --- a/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -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 为空 diff --git a/backend/src/main/resources/i18n/messages_zh_TW.properties b/backend/src/main/resources/i18n/messages_zh_TW.properties index e267a71858..a2653b9066 100644 --- a/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -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 為空 \ No newline at end of file diff --git a/frontend/src/api/system/datasource.js b/frontend/src/api/system/datasource.js index 87b607b940..2f069d430d 100644 --- a/frontend/src/api/system/datasource.js +++ b/frontend/src/api/system/datasource.js @@ -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 } diff --git a/frontend/src/lang/en.js b/frontend/src/lang/en.js index 42db324cf2..2357dc9779 100644 --- a/frontend/src/lang/en.js +++ b/frontend/src/lang/en.js @@ -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', diff --git a/frontend/src/lang/tw.js b/frontend/src/lang/tw.js index 235c84a14f..7c2292d328 100644 --- a/frontend/src/lang/tw.js +++ b/frontend/src/lang/tw.js @@ -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: '請輸入密碼打開鏈接', diff --git a/frontend/src/lang/zh.js b/frontend/src/lang/zh.js index 2f2f0a20ea..dff422724a 100644 --- a/frontend/src/lang/zh.js +++ b/frontend/src/lang/zh.js @@ -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: '请输入密码打开链接', diff --git a/frontend/src/views/system/datasource/form.vue b/frontend/src/views/system/datasource/form.vue index 0d74dedcbf..6e3865bb76 100644 --- a/frontend/src/views/system/datasource/form.vue +++ b/frontend/src/views/system/datasource/form.vue @@ -46,6 +46,23 @@ + + + {{ $t('datasource.get_schema') }} + + + + + + + + +