You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@linkis.apache.org by ca...@apache.org on 2022/07/19 08:12:29 UTC
[incubator-linkis] branch dev-1.2.1 updated: [Feature] Dev 1.2.1 linkis metadata query add database (#2444)
This is an automated email from the ASF dual-hosted git repository.
casion pushed a commit to branch dev-1.2.1
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git
The following commit(s) were added to refs/heads/dev-1.2.1 by this push:
new 52ae800c2 [Feature] Dev 1.2.1 linkis metadata query add database (#2444)
52ae800c2 is described below
commit 52ae800c2169479b268e7dde041b7cab024266f8
Author: Dlimeng <me...@gmail.com>
AuthorDate: Tue Jul 19 16:12:25 2022 +0800
[Feature] Dev 1.2.1 linkis metadata query add database (#2444)
* add linkis metadata (oracle,dm,kingbase,postgresql,sqlserver,db2,greenplum)
* ps-metadataquery info-1.2.1.md
Co-authored-by: Casion <ca...@gmail.com>
---
docs/info-1.2.1.md | 11 +
linkis-dist/package/db/linkis_dml.sql | 68 ++++++
.../db/upgrade/1.2.1_schema/mysql/linkis_dml.sql | 85 +++++++
.../query/common/cache/CacheConfiguration.java | 5 +
.../query/common/domain/MetaColumnInfo.java | 18 ++
.../server/loader/MetaClassLoaderManager.java | 9 +-
.../linkis-metadata-query/service/mysql/pom.xml | 7 +-
.../{MysqlMetaService.java => Db2MetaService.java} | 21 +-
.../{MysqlMetaService.java => DmMetaService.java} | 18 +-
...lMetaService.java => GreenplumMetaService.java} | 36 ++-
...qlMetaService.java => KingbaseMetaService.java} | 19 +-
.../metadata/query/service/MysqlMetaService.java | 2 +
...ysqlMetaService.java => OracleMetaService.java} | 31 ++-
...MetaService.java => PostgresqlMetaService.java} | 33 ++-
...lMetaService.java => SqlserverMetaService.java} | 4 +-
.../query/service/conf/SqlParamsMapper.java | 40 ++++
.../metadata/query/service/db2/SqlConnection.java | 247 +++++++++++++++++++
.../metadata/query/service/dm/SqlConnection.java | 262 +++++++++++++++++++++
.../query/service/greenplum/SqlConnection.java | 243 +++++++++++++++++++
.../query/service/kingbase/SqlConnection.java | 261 ++++++++++++++++++++
.../query/service/mysql/SqlConnection.java | 235 ++++++++++++++++++
.../query/service/oracle/SqlConnection.java | 261 ++++++++++++++++++++
.../query/service/postgres/SqlConnection.java | 240 +++++++++++++++++++
.../query/service/sqlserver/SqlConnection.java | 257 ++++++++++++++++++++
24 files changed, 2364 insertions(+), 49 deletions(-)
diff --git a/docs/info-1.2.1.md b/docs/info-1.2.1.md
new file mode 100644
index 000000000..70451d4c9
--- /dev/null
+++ b/docs/info-1.2.1.md
@@ -0,0 +1,11 @@
+## 参数变化
+
+
+| 模块名(服务名)| 类型 | 参数名 | 默认值 | 描述 |
+| ----------- | ----- | -------------------------------------------------------- | ---------------- | ------------------------------------------------------- |
+|ps-metadataquery | 新增 | wds.linkis.server.mdq.mysql.relationship | oracle,kingbase,postgresql,sqlserver,db2,greenplum,dm,mysql | 在mysql元数据服务兼容oracle,kingbase,postgresql,sqlserver,db2,greenplum,dm,驱动外部引入 |
+
+## 特性说明
+| 模块名(服务名)| 类型 | 特性 |
+| ----------- | ---------------- | ------------------------------------------------------- |
+|linkis-metadata-query-service-mysql | 新增 | 基于mysql 模块融合dm,greenplum,kingbase,oracle,postgres,sqlserver ,协议和sql 区分开,metadata-query 反射多个数据源,基于mysql模块扩展,融合为一个模块。|
diff --git a/linkis-dist/package/db/linkis_dml.sql b/linkis-dist/package/db/linkis_dml.sql
index a538ee6bc..6a86031dd 100644
--- a/linkis-dist/package/db/linkis_dml.sql
+++ b/linkis-dist/package/db/linkis_dml.sql
@@ -454,6 +454,13 @@ INSERT INTO `linkis_ps_dm_datasource_type` (`name`, `description`, `option`, `cl
INSERT INTO `linkis_ps_dm_datasource_type` (`name`, `description`, `option`, `classifier`, `icon`, `layers`) VALUES ('presto', 'presto SQL', 'presto', '大数据存储', '', 3);
INSERT INTO `linkis_ps_dm_datasource_type` (`name`, `description`, `option`, `classifier`, `icon`, `layers`) VALUES ('hive', 'hive数据库', 'hive', '大数据存储', '', 3);
INSERT INTO `linkis_ps_dm_datasource_type` (`name`, `description`, `option`, `classifier`, `icon`, `layers`) VALUES ('mongodb', 'default', 'default', 'DEFAULT', NULL, 3);
+INSERT INTO `linkis_ps_dm_datasource_type` (`name`, `description`, `option`, `classifier`, `icon`, `layers`) VALUES ('oracle','oracle数据库','oracle','关系型数据库','',3);
+INSERT INTO `linkis_ps_dm_datasource_type` (`name`, `description`, `option`, `classifier`, `icon`, `layers`) VALUES ('dm','达梦数据库','dm','关系型数据库','',3);
+INSERT INTO `linkis_ps_dm_datasource_type` (`name`, `description`, `option`, `classifier`, `icon`, `layers`) VALUES ('kingbase','人大金仓数据库','kingbase','关系型数据库','',3);
+INSERT INTO `linkis_ps_dm_datasource_type` (`name`, `description`, `option`, `classifier`, `icon`, `layers`) VALUES ('postgresql','postgresql数据库','postgresql','关系型数据库','',3);
+INSERT INTO `linkis_ps_dm_datasource_type` (`name`, `description`, `option`, `classifier`, `icon`, `layers`) VALUES ('sqlserver','sqlserver数据库','sqlserver','关系型数据库','',3);
+INSERT INTO `linkis_ps_dm_datasource_type` (`name`, `description`, `option`, `classifier`, `icon`, `layers`) VALUES ('db2','db2数据库','db2','关系型数据库','',3);
+INSERT INTO `linkis_ps_dm_datasource_type` (`name`, `description`, `option`, `classifier`, `icon`, `layers`) VALUES ('greenplum','greenplum数据库','greenplum','关系型数据库','',3);
INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `name_en`, `default_value`, `value_type`, `scope`, `require`, `description`, `description_en`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (1, 'host', '主机名(Host)', 'Host', NULL, 'TEXT', NULL, 1, '主机名(Host)', 'Host', NULL, NULL, NULL, NULL, now(), now());
@@ -465,6 +472,67 @@ INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `n
INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `name_en`, `default_value`, `value_type`, `scope`, `require`, `description`, `description_en`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (1, 'databaseName', '数据库名(Database name)', 'Database name', NULL, 'TEXT', NULL, 0, '数据库名(Database name)', 'Database name', NULL, NULL, NULL, NULL, now(), now());
INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `name_en`, `default_value`, `value_type`, `scope`, `require`, `description`, `description_en`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (4, 'envId', '集群环境(Cluster env)', 'Cluster env', NULL, 'SELECT', NULL, 1, '集群环境(Cluster env)', 'Cluster env', NULL, NULL, NULL, '/data-source-manager/env-list/all/type/4', now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (6, 'host', '主机名(Host)', NULL, 'TEXT', NULL, 1, '主机名(Host)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (6, 'port', '端口号(Port)', NULL, 'TEXT', NULL, 1, '端口号(Port)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (6, 'driverClassName', '驱动类名(Driver class name)', 'oracle.jdbc.driver.OracleDriver', 'TEXT', NULL, 1, '驱动类名(Driver class name)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (6, 'params', '连接参数(Connection params)', NULL, 'TEXT', NULL, 0, '输入JSON格式(Input JSON format): {"param":"value"}', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (6, 'username', '用户名(Username)', NULL, 'TEXT', NULL, 1, '用户名(Username)', '^[0-9A-Za-z_-]+$', NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (6, 'password', '密码(Password)', NULL, 'PASSWORD', NULL, 1, '密码(Password)', '', NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (6, 'instance', '实例名(instance)', NULL, 'TEXT', NULL, 0, '实例名(instance)', NULL, NULL, NULL, NULL, now(), now());
+
+
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (7, 'host', '主机名(Host)', NULL, 'TEXT', NULL, 1, '主机名(Host)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (7, 'port', '端口号(Port)', NULL, 'TEXT', NULL, 1, '端口号(Port)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (7, 'driverClassName', '驱动类名(Driver class name)', 'dm.jdbc.driver.DmDriver', 'TEXT', NULL, 1, '驱动类名(Driver class name)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (7, 'params', '连接参数(Connection params)', NULL, 'TEXT', NULL, 0, '输入JSON格式(Input JSON format): {"param":"value"}', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (7, 'username', '用户名(Username)', NULL, 'TEXT', NULL, 1, '用户名(Username)', '^[0-9A-Za-z_-]+$', NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (7, 'password', '密码(Password)', NULL, 'PASSWORD', NULL, 1, '密码(Password)', '', NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (7, 'instance', '实例名(instance)', NULL, 'TEXT', NULL, 1, '实例名(instance)', NULL, NULL, NULL, NULL, now(), now());
+
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (8, 'host', '主机名(Host)', NULL, 'TEXT', NULL, 1, '主机名(Host)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (8, 'port', '端口号(Port)', NULL, 'TEXT', NULL, 1, '端口号(Port)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (8, 'driverClassName', '驱动类名(Driver class name)', 'com.kingbase8.Driver', 'TEXT', NULL, 1, '驱动类名(Driver class name)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (8, 'params', '连接参数(Connection params)', NULL, 'TEXT', NULL, 0, '输入JSON格式(Input JSON format): {"param":"value"}', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (8, 'username', '用户名(Username)', NULL, 'TEXT', NULL, 1, '用户名(Username)', '^[0-9A-Za-z_-]+$', NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (8, 'password', '密码(Password)', NULL, 'PASSWORD', NULL, 1, '密码(Password)', '', NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (8, 'instance', '实例名(instance)', NULL, 'TEXT', NULL, 1, '实例名(instance)', NULL, NULL, NULL, NULL, now(), now());
+
+
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (9, 'host', '主机名(Host)', NULL, 'TEXT', NULL, 1, '主机名(Host)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (9, 'port', '端口号(Port)', NULL, 'TEXT', NULL, 1, '端口号(Port)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (9, 'driverClassName', '驱动类名(Driver class name)', 'org.postgresql.Driver', 'TEXT', NULL, 1, '驱动类名(Driver class name)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (9, 'params', '连接参数(Connection params)', NULL, 'TEXT', NULL, 0, '输入JSON格式(Input JSON format): {"param":"value"}', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (9, 'username', '用户名(Username)', NULL, 'TEXT', NULL, 1, '用户名(Username)', '^[0-9A-Za-z_-]+$', NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (9, 'password', '密码(Password)', NULL, 'PASSWORD', NULL, 1, '密码(Password)', '', NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (9, 'instance', '实例名(instance)', NULL, 'TEXT', NULL, 1, '实例名(instance)', NULL, NULL, NULL, NULL, now(), now());
+
+
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (10, 'host', '主机名(Host)', NULL, 'TEXT', NULL, 1, '主机名(Host)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (10, 'port', '端口号(Port)', NULL, 'TEXT', NULL, 1, '端口号(Port)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (10, 'driverClassName', '驱动类名(Driver class name)', 'com.microsoft.jdbc.sqlserver.SQLServerDriver', 'TEXT', NULL, 1, '驱动类名(Driver class name)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (10, 'params', '连接参数(Connection params)', NULL, 'TEXT', NULL, 0, '输入JSON格式(Input JSON format): {"param":"value"}', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (10, 'username', '用户名(Username)', NULL, 'TEXT', NULL, 1, '用户名(Username)', '^[0-9A-Za-z_-]+$', NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (10, 'password', '密码(Password)', NULL, 'PASSWORD', NULL, 1, '密码(Password)', '', NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (10, 'instance', '实例名(instance)', NULL, 'TEXT', NULL, 1, '实例名(instance)', NULL, NULL, NULL, NULL, now(), now());
+
+
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (11, 'host', '主机名(Host)', NULL, 'TEXT', NULL, 1, '主机名(Host)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (11, 'port', '端口号(Port)', NULL, 'TEXT', NULL, 1, '端口号(Port)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (11, 'driverClassName', '驱动类名(Driver class name)', 'com.ibm.db2.jcc.DB2Driver', 'TEXT', NULL, 1, '驱动类名(Driver class name)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (11, 'params', '连接参数(Connection params)', NULL, 'TEXT', NULL, 0, '输入JSON格式(Input JSON format): {"param":"value"}', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (11, 'username', '用户名(Username)', NULL, 'TEXT', NULL, 1, '用户名(Username)', '^[0-9A-Za-z_-]+$', NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (11, 'password', '密码(Password)', NULL, 'PASSWORD', NULL, 1, '密码(Password)', '', NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (11, 'instance', '实例名(instance)', NULL, 'TEXT', NULL, 1, '实例名(instance)', NULL, NULL, NULL, NULL, now(), now());
+
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (12, 'host', '主机名(Host)', NULL, 'TEXT', NULL, 1, '主机名(Host)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (12, 'port', '端口号(Port)', NULL, 'TEXT', NULL, 1, '端口号(Port)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (12, 'driverClassName', '驱动类名(Driver class name)', 'com.pivotal.jdbc.GreenplumDriver', 'TEXT', NULL, 1, '驱动类名(Driver class name)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (12, 'params', '连接参数(Connection params)', NULL, 'TEXT', NULL, 0, '输入JSON格式(Input JSON format): {"param":"value"}', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (12, 'username', '用户名(Username)', NULL, 'TEXT', NULL, 1, '用户名(Username)', '^[0-9A-Za-z_-]+$', NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (12, 'password', '密码(Password)', NULL, 'PASSWORD', NULL, 1, '密码(Password)', '', NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (12, 'instance', '实例名(instance)', NULL, 'TEXT', NULL, 1, '实例名(instance)', NULL, NULL, NULL, NULL, now(), now());
+
+
INSERT INTO `linkis_ps_dm_datasource_env` (`env_name`, `env_desc`, `datasource_type_id`, `parameter`, `create_time`, `create_user`, `modify_time`, `modify_user`) VALUES ('测试环境SIT', '测试环境SIT', 4, '{"uris":"thrift://localhost:9083", "hadoopConf":{"hive.metastore.execute.setugi":"true"}}', now(), NULL, now(), NULL);
INSERT INTO `linkis_ps_dm_datasource_env` (`env_name`, `env_desc`, `datasource_type_id`, `parameter`, `create_time`, `create_user`, `modify_time`, `modify_user`) VALUES ('测试环境UAT', '测试环境UAT', 4, '{"uris":"thrift://localhost:9083", "hadoopConf":{"hive.metastore.execute.setugi":"true"}}', now(), NULL, now(), NULL);
diff --git a/linkis-dist/package/db/upgrade/1.2.1_schema/mysql/linkis_dml.sql b/linkis-dist/package/db/upgrade/1.2.1_schema/mysql/linkis_dml.sql
new file mode 100644
index 000000000..b09256848
--- /dev/null
+++ b/linkis-dist/package/db/upgrade/1.2.1_schema/mysql/linkis_dml.sql
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+INSERT INTO `linkis_ps_dm_datasource_type` (`name`, `description`, `option`, `classifier`, `icon`, `layers`) VALUES ('oracle','oracle数据库','oracle','关系型数据库','',3);
+INSERT INTO `linkis_ps_dm_datasource_type` (`name`, `description`, `option`, `classifier`, `icon`, `layers`) VALUES ('dm','达梦数据库','dm','关系型数据库','',3);
+INSERT INTO `linkis_ps_dm_datasource_type` (`name`, `description`, `option`, `classifier`, `icon`, `layers`) VALUES ('kingbase','人大金仓数据库','kingbase','关系型数据库','',3);
+INSERT INTO `linkis_ps_dm_datasource_type` (`name`, `description`, `option`, `classifier`, `icon`, `layers`) VALUES ('postgresql','postgresql数据库','postgresql','关系型数据库','',3);
+INSERT INTO `linkis_ps_dm_datasource_type` (`name`, `description`, `option`, `classifier`, `icon`, `layers`) VALUES ('sqlserver','sqlserver数据库','sqlserver','关系型数据库','',3);
+INSERT INTO `linkis_ps_dm_datasource_type` (`name`, `description`, `option`, `classifier`, `icon`, `layers`) VALUES ('db2','db2数据库','db2','关系型数据库','',3);
+INSERT INTO `linkis_ps_dm_datasource_type` (`name`, `description`, `option`, `classifier`, `icon`, `layers`) VALUES ('greenplum','greenplum数据库','greenplum','关系型数据库','',3);
+
+
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (6, 'host', '主机名(Host)', NULL, 'TEXT', NULL, 1, '主机名(Host)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (6, 'port', '端口号(Port)', NULL, 'TEXT', NULL, 1, '端口号(Port)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (6, 'driverClassName', '驱动类名(Driver class name)', 'oracle.jdbc.driver.OracleDriver', 'TEXT', NULL, 1, '驱动类名(Driver class name)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (6, 'params', '连接参数(Connection params)', NULL, 'TEXT', NULL, 0, '输入JSON格式(Input JSON format): {"param":"value"}', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (6, 'username', '用户名(Username)', NULL, 'TEXT', NULL, 1, '用户名(Username)', '^[0-9A-Za-z_-]+$', NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (6, 'password', '密码(Password)', NULL, 'PASSWORD', NULL, 1, '密码(Password)', '', NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (6, 'instance', '实例名(instance)', NULL, 'TEXT', NULL, 0, '实例名(instance)', NULL, NULL, NULL, NULL, now(), now());
+
+
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (7, 'host', '主机名(Host)', NULL, 'TEXT', NULL, 1, '主机名(Host)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (7, 'port', '端口号(Port)', NULL, 'TEXT', NULL, 1, '端口号(Port)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (7, 'driverClassName', '驱动类名(Driver class name)', 'dm.jdbc.driver.DmDriver', 'TEXT', NULL, 1, '驱动类名(Driver class name)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (7, 'params', '连接参数(Connection params)', NULL, 'TEXT', NULL, 0, '输入JSON格式(Input JSON format): {"param":"value"}', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (7, 'username', '用户名(Username)', NULL, 'TEXT', NULL, 1, '用户名(Username)', '^[0-9A-Za-z_-]+$', NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (7, 'password', '密码(Password)', NULL, 'PASSWORD', NULL, 1, '密码(Password)', '', NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (7, 'instance', '实例名(instance)', NULL, 'TEXT', NULL, 1, '实例名(instance)', NULL, NULL, NULL, NULL, now(), now());
+
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (8, 'host', '主机名(Host)', NULL, 'TEXT', NULL, 1, '主机名(Host)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (8, 'port', '端口号(Port)', NULL, 'TEXT', NULL, 1, '端口号(Port)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (8, 'driverClassName', '驱动类名(Driver class name)', 'com.kingbase8.Driver', 'TEXT', NULL, 1, '驱动类名(Driver class name)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (8, 'params', '连接参数(Connection params)', NULL, 'TEXT', NULL, 0, '输入JSON格式(Input JSON format): {"param":"value"}', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (8, 'username', '用户名(Username)', NULL, 'TEXT', NULL, 1, '用户名(Username)', '^[0-9A-Za-z_-]+$', NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (8, 'password', '密码(Password)', NULL, 'PASSWORD', NULL, 1, '密码(Password)', '', NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (8, 'instance', '实例名(instance)', NULL, 'TEXT', NULL, 1, '实例名(instance)', NULL, NULL, NULL, NULL, now(), now());
+
+
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (9, 'host', '主机名(Host)', NULL, 'TEXT', NULL, 1, '主机名(Host)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (9, 'port', '端口号(Port)', NULL, 'TEXT', NULL, 1, '端口号(Port)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (9, 'driverClassName', '驱动类名(Driver class name)', 'org.postgresql.Driver', 'TEXT', NULL, 1, '驱动类名(Driver class name)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (9, 'params', '连接参数(Connection params)', NULL, 'TEXT', NULL, 0, '输入JSON格式(Input JSON format): {"param":"value"}', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (9, 'username', '用户名(Username)', NULL, 'TEXT', NULL, 1, '用户名(Username)', '^[0-9A-Za-z_-]+$', NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (9, 'password', '密码(Password)', NULL, 'PASSWORD', NULL, 1, '密码(Password)', '', NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (9, 'instance', '实例名(instance)', NULL, 'TEXT', NULL, 1, '实例名(instance)', NULL, NULL, NULL, NULL, now(), now());
+
+
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (10, 'host', '主机名(Host)', NULL, 'TEXT', NULL, 1, '主机名(Host)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (10, 'port', '端口号(Port)', NULL, 'TEXT', NULL, 1, '端口号(Port)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (10, 'driverClassName', '驱动类名(Driver class name)', 'com.microsoft.jdbc.sqlserver.SQLServerDriver', 'TEXT', NULL, 1, '驱动类名(Driver class name)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (10, 'params', '连接参数(Connection params)', NULL, 'TEXT', NULL, 0, '输入JSON格式(Input JSON format): {"param":"value"}', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (10, 'username', '用户名(Username)', NULL, 'TEXT', NULL, 1, '用户名(Username)', '^[0-9A-Za-z_-]+$', NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (10, 'password', '密码(Password)', NULL, 'PASSWORD', NULL, 1, '密码(Password)', '', NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (10, 'instance', '实例名(instance)', NULL, 'TEXT', NULL, 1, '实例名(instance)', NULL, NULL, NULL, NULL, now(), now());
+
+
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (11, 'host', '主机名(Host)', NULL, 'TEXT', NULL, 1, '主机名(Host)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (11, 'port', '端口号(Port)', NULL, 'TEXT', NULL, 1, '端口号(Port)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (11, 'driverClassName', '驱动类名(Driver class name)', 'com.ibm.db2.jcc.DB2Driver', 'TEXT', NULL, 1, '驱动类名(Driver class name)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (11, 'params', '连接参数(Connection params)', NULL, 'TEXT', NULL, 0, '输入JSON格式(Input JSON format): {"param":"value"}', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (11, 'username', '用户名(Username)', NULL, 'TEXT', NULL, 1, '用户名(Username)', '^[0-9A-Za-z_-]+$', NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (11, 'password', '密码(Password)', NULL, 'PASSWORD', NULL, 1, '密码(Password)', '', NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (11, 'instance', '实例名(instance)', NULL, 'TEXT', NULL, 1, '实例名(instance)', NULL, NULL, NULL, NULL, now(), now());
+
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (12, 'host', '主机名(Host)', NULL, 'TEXT', NULL, 1, '主机名(Host)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (12, 'port', '端口号(Port)', NULL, 'TEXT', NULL, 1, '端口号(Port)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (12, 'driverClassName', '驱动类名(Driver class name)', 'com.pivotal.jdbc.GreenplumDriver', 'TEXT', NULL, 1, '驱动类名(Driver class name)', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (12, 'params', '连接参数(Connection params)', NULL, 'TEXT', NULL, 0, '输入JSON格式(Input JSON format): {"param":"value"}', NULL, NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (12, 'username', '用户名(Username)', NULL, 'TEXT', NULL, 1, '用户名(Username)', '^[0-9A-Za-z_-]+$', NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (12, 'password', '密码(Password)', NULL, 'PASSWORD', NULL, 1, '密码(Password)', '', NULL, NULL, NULL, now(), now());
+INSERT INTO `linkis_ps_dm_datasource_type_key` (`data_source_type_id`, `key`, `name`, `default_value`, `value_type`, `scope`, `require`, `description`, `value_regex`, `ref_id`, `ref_value`, `data_source`, `update_time`, `create_time`) VALUES (12, 'instance', '实例名(instance)', NULL, 'TEXT', NULL, 1, '实例名(instance)', NULL, NULL, NULL, NULL, now(), now());
+
diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/common/src/main/java/org/apache/linkis/metadata/query/common/cache/CacheConfiguration.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/common/src/main/java/org/apache/linkis/metadata/query/common/cache/CacheConfiguration.java
index 1f4b14395..050eddeed 100644
--- a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/common/src/main/java/org/apache/linkis/metadata/query/common/cache/CacheConfiguration.java
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/common/src/main/java/org/apache/linkis/metadata/query/common/cache/CacheConfiguration.java
@@ -30,4 +30,9 @@ public class CacheConfiguration {
/** Make a pool for each cache element */
public static final CommonVars<Integer> CACHE_IN_POOL_SIZE =
CommonVars.apply("wds.linkis.server.mdm.service.cache.in-pool.size", 5);
+
+ public static final CommonVars<String> MYSQL_RELATIONSHIP_LIST =
+ CommonVars.apply(
+ "wds.linkis.server.mdq.mysql.relationship",
+ "oracle,kingbase,postgresql,sqlserver,db2,greenplum,dm,mysql");
}
diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/common/src/main/java/org/apache/linkis/metadata/query/common/domain/MetaColumnInfo.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/common/src/main/java/org/apache/linkis/metadata/query/common/domain/MetaColumnInfo.java
index a12de2d40..f865a33ef 100644
--- a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/common/src/main/java/org/apache/linkis/metadata/query/common/domain/MetaColumnInfo.java
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/common/src/main/java/org/apache/linkis/metadata/query/common/domain/MetaColumnInfo.java
@@ -30,6 +30,24 @@ public class MetaColumnInfo implements Serializable {
private boolean primaryKey;
private String name;
private String type;
+ private int length;
+ private String colComment;
+
+ public String getColComment() {
+ return colComment;
+ }
+
+ public void setColComment(String colComment) {
+ this.colComment = colComment;
+ }
+
+ public int getLength() {
+ return length;
+ }
+
+ public void setLength(int length) {
+ this.length = length;
+ }
public int getIndex() {
return index;
diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/server/src/main/java/org/apache/linkis/metadata/query/server/loader/MetaClassLoaderManager.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/server/src/main/java/org/apache/linkis/metadata/query/server/loader/MetaClassLoaderManager.java
index c74088cc0..91bcc4a28 100644
--- a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/server/src/main/java/org/apache/linkis/metadata/query/server/loader/MetaClassLoaderManager.java
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/server/src/main/java/org/apache/linkis/metadata/query/server/loader/MetaClassLoaderManager.java
@@ -20,6 +20,7 @@ package org.apache.linkis.metadata.query.server.loader;
import org.apache.linkis.common.conf.CommonVars;
import org.apache.linkis.common.conf.Configuration;
import org.apache.linkis.common.exception.ErrorException;
+import org.apache.linkis.metadata.query.common.cache.CacheConfiguration;
import org.apache.linkis.metadata.query.common.exception.MetaRuntimeException;
import org.apache.linkis.metadata.query.common.service.AbstractMetaService;
import org.apache.linkis.metadata.query.common.service.MetadataService;
@@ -60,10 +61,13 @@ public class MetaClassLoaderManager {
private static final String META_CLASS_NAME =
"org.apache.linkis.metadata.query.service.%sMetaService";
+ private static final String MYSQL_BASE_DIR = "mysql";
+
private static final Logger LOG = LoggerFactory.getLogger(MetaClassLoaderManager.class);
public BiFunction<String, Object[], Object> getInvoker(String dsType) throws ErrorException {
boolean needToLoad = true;
+
MetaServiceInstance serviceInstance = metaServiceInstances.get(dsType);
if (Objects.nonNull(serviceInstance)) {
Integer expireTimeInSec = INSTANCE_EXPIRE_TIME.getValue();
@@ -78,6 +82,9 @@ public class MetaClassLoaderManager {
}
if (needToLoad) {
MetaServiceInstance finalServiceInstance1 = serviceInstance;
+ boolean isContains =
+ CacheConfiguration.MYSQL_RELATIONSHIP_LIST.getValue().contains(dsType);
+ String finalBaseType = isContains ? MYSQL_BASE_DIR : dsType;
serviceInstance =
metaServiceInstances.compute(
dsType,
@@ -88,7 +95,7 @@ public class MetaClassLoaderManager {
}
String lib = LIB_DIR.getValue();
String stdLib = lib.endsWith("/") ? lib.replaceAll(".$", "") : lib;
- String componentLib = stdLib + "/" + dsType;
+ String componentLib = stdLib + "/" + finalBaseType;
LOG.info(
"Start to load/reload meta instance of data source type: ["
+ dsType
diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/pom.xml b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/pom.xml
index 926fa7500..039ba73ad 100644
--- a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/pom.xml
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/pom.xml
@@ -30,6 +30,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mysql.version>8.0.28</mysql.version>
+ <postgresql.version>42.3.1</postgresql.version>
</properties>
<dependencies>
@@ -55,11 +56,7 @@
</exclusions>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>${mysql.version}</version>
- </dependency>
+
</dependencies>
<build>
diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/MysqlMetaService.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/Db2MetaService.java
similarity index 84%
copy from linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/MysqlMetaService.java
copy to linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/Db2MetaService.java
index a43e7048f..d163f3080 100644
--- a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/MysqlMetaService.java
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/Db2MetaService.java
@@ -21,13 +21,18 @@ import org.apache.linkis.datasourcemanager.common.util.json.Json;
import org.apache.linkis.metadata.query.common.domain.MetaColumnInfo;
import org.apache.linkis.metadata.query.common.service.AbstractMetaService;
import org.apache.linkis.metadata.query.common.service.MetadataConnection;
+import org.apache.linkis.metadata.query.service.conf.SqlParamsMapper;
+import org.apache.linkis.metadata.query.service.db2.SqlConnection;
+
+import org.springframework.stereotype.Component;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-public class MysqlMetaService extends AbstractMetaService<SqlConnection> {
+@Component
+public class Db2MetaService extends AbstractMetaService<SqlConnection> {
@Override
public MetadataConnection<SqlConnection> getConnection(
String operator, Map<String, Object> params) throws Exception {
@@ -46,6 +51,10 @@ public class MysqlMetaService extends AbstractMetaService<SqlConnection> {
String password =
String.valueOf(
params.getOrDefault(SqlParamsMapper.PARAM_SQL_PASSWORD.getValue(), ""));
+
+ String database =
+ String.valueOf(
+ params.getOrDefault(SqlParamsMapper.PARAM_SQL_DATABASE.getValue(), ""));
Map<String, Object> extraParams = new HashMap<>();
Object sqlParamObj = params.get(SqlParamsMapper.PARAM_SQL_EXTRA_PARAMS.getValue());
if (null != sqlParamObj) {
@@ -59,7 +68,7 @@ public class MysqlMetaService extends AbstractMetaService<SqlConnection> {
}
assert extraParams != null;
return new MetadataConnection<>(
- new SqlConnection(host, port, username, password, extraParams));
+ new SqlConnection(host, port, username, password, database, extraParams));
}
@Override
@@ -72,9 +81,9 @@ public class MysqlMetaService extends AbstractMetaService<SqlConnection> {
}
@Override
- public List<String> queryTables(SqlConnection connection, String database) {
+ public List<String> queryTables(SqlConnection connection, String schemaname) {
try {
- return connection.getAllTables(database);
+ return connection.getAllTables(schemaname);
} catch (SQLException e) {
throw new RuntimeException("Fail to get Sql tables(获取表列表失败)", e);
}
@@ -82,9 +91,9 @@ public class MysqlMetaService extends AbstractMetaService<SqlConnection> {
@Override
public List<MetaColumnInfo> queryColumns(
- SqlConnection connection, String database, String table) {
+ SqlConnection connection, String schemaname, String table) {
try {
- return connection.getColumns(database, table);
+ return connection.getColumns(schemaname, table);
} catch (SQLException | ClassNotFoundException e) {
throw new RuntimeException("Fail to get Sql columns(获取字段列表失败)", e);
}
diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/MysqlMetaService.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/DmMetaService.java
similarity index 85%
copy from linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/MysqlMetaService.java
copy to linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/DmMetaService.java
index a43e7048f..9c8ee19e8 100644
--- a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/MysqlMetaService.java
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/DmMetaService.java
@@ -21,13 +21,15 @@ import org.apache.linkis.datasourcemanager.common.util.json.Json;
import org.apache.linkis.metadata.query.common.domain.MetaColumnInfo;
import org.apache.linkis.metadata.query.common.service.AbstractMetaService;
import org.apache.linkis.metadata.query.common.service.MetadataConnection;
+import org.apache.linkis.metadata.query.service.conf.SqlParamsMapper;
+import org.apache.linkis.metadata.query.service.dm.SqlConnection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-public class MysqlMetaService extends AbstractMetaService<SqlConnection> {
+public class DmMetaService extends AbstractMetaService<SqlConnection> {
@Override
public MetadataConnection<SqlConnection> getConnection(
String operator, Map<String, Object> params) throws Exception {
@@ -46,6 +48,10 @@ public class MysqlMetaService extends AbstractMetaService<SqlConnection> {
String password =
String.valueOf(
params.getOrDefault(SqlParamsMapper.PARAM_SQL_PASSWORD.getValue(), ""));
+
+ String database =
+ String.valueOf(
+ params.getOrDefault(SqlParamsMapper.PARAM_SQL_DATABASE.getValue(), ""));
Map<String, Object> extraParams = new HashMap<>();
Object sqlParamObj = params.get(SqlParamsMapper.PARAM_SQL_EXTRA_PARAMS.getValue());
if (null != sqlParamObj) {
@@ -59,7 +65,7 @@ public class MysqlMetaService extends AbstractMetaService<SqlConnection> {
}
assert extraParams != null;
return new MetadataConnection<>(
- new SqlConnection(host, port, username, password, extraParams));
+ new SqlConnection(host, port, username, password, database, extraParams));
}
@Override
@@ -72,9 +78,9 @@ public class MysqlMetaService extends AbstractMetaService<SqlConnection> {
}
@Override
- public List<String> queryTables(SqlConnection connection, String database) {
+ public List<String> queryTables(SqlConnection connection, String schemaname) {
try {
- return connection.getAllTables(database);
+ return connection.getAllTables(schemaname);
} catch (SQLException e) {
throw new RuntimeException("Fail to get Sql tables(获取表列表失败)", e);
}
@@ -82,9 +88,9 @@ public class MysqlMetaService extends AbstractMetaService<SqlConnection> {
@Override
public List<MetaColumnInfo> queryColumns(
- SqlConnection connection, String database, String table) {
+ SqlConnection connection, String schemaname, String table) {
try {
- return connection.getColumns(database, table);
+ return connection.getColumns(schemaname, table);
} catch (SQLException | ClassNotFoundException e) {
throw new RuntimeException("Fail to get Sql columns(获取字段列表失败)", e);
}
diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/MysqlMetaService.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/GreenplumMetaService.java
similarity index 74%
copy from linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/MysqlMetaService.java
copy to linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/GreenplumMetaService.java
index a43e7048f..bae60b82d 100644
--- a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/MysqlMetaService.java
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/GreenplumMetaService.java
@@ -21,13 +21,17 @@ import org.apache.linkis.datasourcemanager.common.util.json.Json;
import org.apache.linkis.metadata.query.common.domain.MetaColumnInfo;
import org.apache.linkis.metadata.query.common.service.AbstractMetaService;
import org.apache.linkis.metadata.query.common.service.MetadataConnection;
+import org.apache.linkis.metadata.query.service.conf.SqlParamsMapper;
+import org.apache.linkis.metadata.query.service.greenplum.SqlConnection;
+
+import org.apache.logging.log4j.util.Strings;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-public class MysqlMetaService extends AbstractMetaService<SqlConnection> {
+public class GreenplumMetaService extends AbstractMetaService<SqlConnection> {
@Override
public MetadataConnection<SqlConnection> getConnection(
String operator, Map<String, Object> params) throws Exception {
@@ -46,6 +50,15 @@ public class MysqlMetaService extends AbstractMetaService<SqlConnection> {
String password =
String.valueOf(
params.getOrDefault(SqlParamsMapper.PARAM_SQL_PASSWORD.getValue(), ""));
+ // In greenplum, each database under the same instance is completely independent, and the
+ // table is stored under the catalog with the same library name.
+ // \c (\connect) Behind the dbname command is to close the current connection and create a
+ // new connection to achieve database switching
+ // Cannot directly switch to another database under the current database connection, and
+ // cannot show tables from xxxx, select * from database.table like MySQL
+ String database =
+ String.valueOf(
+ params.getOrDefault(SqlParamsMapper.PARAM_SQL_DATABASE.getValue(), ""));
Map<String, Object> extraParams = new HashMap<>();
Object sqlParamObj = params.get(SqlParamsMapper.PARAM_SQL_EXTRA_PARAMS.getValue());
if (null != sqlParamObj) {
@@ -58,33 +71,36 @@ public class MysqlMetaService extends AbstractMetaService<SqlConnection> {
}
}
assert extraParams != null;
+ if (Strings.isBlank(database)) {
+ database = "";
+ }
return new MetadataConnection<>(
- new SqlConnection(host, port, username, password, extraParams));
+ new SqlConnection(host, port, username, password, database, extraParams));
}
@Override
- public List<String> queryDatabases(SqlConnection connection) {
+ public List<String> queryTables(SqlConnection connection, String schemaname) {
try {
- return connection.getAllDatabases();
+ return connection.getAllTables(schemaname);
} catch (SQLException e) {
- throw new RuntimeException("Fail to get Sql databases(获取数据库列表失败)", e);
+ throw new RuntimeException("Fail to get Sql tables(获取表列表失败)", e);
}
}
@Override
- public List<String> queryTables(SqlConnection connection, String database) {
+ public List<String> queryDatabases(SqlConnection connection) {
try {
- return connection.getAllTables(database);
+ return connection.getAllDatabases();
} catch (SQLException e) {
- throw new RuntimeException("Fail to get Sql tables(获取表列表失败)", e);
+ throw new RuntimeException("Fail to get Sql databases(获取数据库列表失败)", e);
}
}
@Override
public List<MetaColumnInfo> queryColumns(
- SqlConnection connection, String database, String table) {
+ SqlConnection connection, String schema, String table) {
try {
- return connection.getColumns(database, table);
+ return connection.getColumns(schema, table);
} catch (SQLException | ClassNotFoundException e) {
throw new RuntimeException("Fail to get Sql columns(获取字段列表失败)", e);
}
diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/MysqlMetaService.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/KingbaseMetaService.java
similarity index 85%
copy from linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/MysqlMetaService.java
copy to linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/KingbaseMetaService.java
index a43e7048f..46ee3e24f 100644
--- a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/MysqlMetaService.java
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/KingbaseMetaService.java
@@ -21,13 +21,16 @@ import org.apache.linkis.datasourcemanager.common.util.json.Json;
import org.apache.linkis.metadata.query.common.domain.MetaColumnInfo;
import org.apache.linkis.metadata.query.common.service.AbstractMetaService;
import org.apache.linkis.metadata.query.common.service.MetadataConnection;
+import org.apache.linkis.metadata.query.service.conf.SqlParamsMapper;
+import org.apache.linkis.metadata.query.service.kingbase.SqlConnection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-public class MysqlMetaService extends AbstractMetaService<SqlConnection> {
+public class KingbaseMetaService extends AbstractMetaService<SqlConnection> {
+
@Override
public MetadataConnection<SqlConnection> getConnection(
String operator, Map<String, Object> params) throws Exception {
@@ -46,6 +49,10 @@ public class MysqlMetaService extends AbstractMetaService<SqlConnection> {
String password =
String.valueOf(
params.getOrDefault(SqlParamsMapper.PARAM_SQL_PASSWORD.getValue(), ""));
+
+ String database =
+ String.valueOf(
+ params.getOrDefault(SqlParamsMapper.PARAM_SQL_DATABASE.getValue(), ""));
Map<String, Object> extraParams = new HashMap<>();
Object sqlParamObj = params.get(SqlParamsMapper.PARAM_SQL_EXTRA_PARAMS.getValue());
if (null != sqlParamObj) {
@@ -59,7 +66,7 @@ public class MysqlMetaService extends AbstractMetaService<SqlConnection> {
}
assert extraParams != null;
return new MetadataConnection<>(
- new SqlConnection(host, port, username, password, extraParams));
+ new SqlConnection(host, port, username, password, database, extraParams));
}
@Override
@@ -72,9 +79,9 @@ public class MysqlMetaService extends AbstractMetaService<SqlConnection> {
}
@Override
- public List<String> queryTables(SqlConnection connection, String database) {
+ public List<String> queryTables(SqlConnection connection, String schemaname) {
try {
- return connection.getAllTables(database);
+ return connection.getAllTables(schemaname);
} catch (SQLException e) {
throw new RuntimeException("Fail to get Sql tables(获取表列表失败)", e);
}
@@ -82,9 +89,9 @@ public class MysqlMetaService extends AbstractMetaService<SqlConnection> {
@Override
public List<MetaColumnInfo> queryColumns(
- SqlConnection connection, String database, String table) {
+ SqlConnection connection, String schemaname, String table) {
try {
- return connection.getColumns(database, table);
+ return connection.getColumns(schemaname, table);
} catch (SQLException | ClassNotFoundException e) {
throw new RuntimeException("Fail to get Sql columns(获取字段列表失败)", e);
}
diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/MysqlMetaService.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/MysqlMetaService.java
index a43e7048f..7045898b5 100644
--- a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/MysqlMetaService.java
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/MysqlMetaService.java
@@ -21,6 +21,8 @@ import org.apache.linkis.datasourcemanager.common.util.json.Json;
import org.apache.linkis.metadata.query.common.domain.MetaColumnInfo;
import org.apache.linkis.metadata.query.common.service.AbstractMetaService;
import org.apache.linkis.metadata.query.common.service.MetadataConnection;
+import org.apache.linkis.metadata.query.service.conf.SqlParamsMapper;
+import org.apache.linkis.metadata.query.service.mysql.SqlConnection;
import java.sql.SQLException;
import java.util.HashMap;
diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/MysqlMetaService.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/OracleMetaService.java
similarity index 77%
copy from linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/MysqlMetaService.java
copy to linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/OracleMetaService.java
index a43e7048f..e2f86c595 100644
--- a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/MysqlMetaService.java
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/OracleMetaService.java
@@ -21,13 +21,20 @@ import org.apache.linkis.datasourcemanager.common.util.json.Json;
import org.apache.linkis.metadata.query.common.domain.MetaColumnInfo;
import org.apache.linkis.metadata.query.common.service.AbstractMetaService;
import org.apache.linkis.metadata.query.common.service.MetadataConnection;
+import org.apache.linkis.metadata.query.service.conf.SqlParamsMapper;
+import org.apache.linkis.metadata.query.service.oracle.SqlConnection;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-public class MysqlMetaService extends AbstractMetaService<SqlConnection> {
+public class OracleMetaService extends AbstractMetaService<SqlConnection> {
+ private static final Logger LOG = LoggerFactory.getLogger(OracleMetaService.class);
+
@Override
public MetadataConnection<SqlConnection> getConnection(
String operator, Map<String, Object> params) throws Exception {
@@ -46,6 +53,10 @@ public class MysqlMetaService extends AbstractMetaService<SqlConnection> {
String password =
String.valueOf(
params.getOrDefault(SqlParamsMapper.PARAM_SQL_PASSWORD.getValue(), ""));
+
+ String database =
+ String.valueOf(
+ params.getOrDefault(SqlParamsMapper.PARAM_SQL_DATABASE.getValue(), ""));
Map<String, Object> extraParams = new HashMap<>();
Object sqlParamObj = params.get(SqlParamsMapper.PARAM_SQL_EXTRA_PARAMS.getValue());
if (null != sqlParamObj) {
@@ -58,8 +69,16 @@ public class MysqlMetaService extends AbstractMetaService<SqlConnection> {
}
}
assert extraParams != null;
+ LOG.info("oracle connection params:{}", params.toString());
+ LOG.info(
+ "oracle connection host:{},port:{},username:{},password:{},database:{}",
+ host,
+ port,
+ username,
+ password,
+ database);
return new MetadataConnection<>(
- new SqlConnection(host, port, username, password, extraParams));
+ new SqlConnection(host, port, username, password, database, extraParams));
}
@Override
@@ -72,9 +91,9 @@ public class MysqlMetaService extends AbstractMetaService<SqlConnection> {
}
@Override
- public List<String> queryTables(SqlConnection connection, String database) {
+ public List<String> queryTables(SqlConnection connection, String schemaname) {
try {
- return connection.getAllTables(database);
+ return connection.getAllTables(schemaname);
} catch (SQLException e) {
throw new RuntimeException("Fail to get Sql tables(获取表列表失败)", e);
}
@@ -82,9 +101,9 @@ public class MysqlMetaService extends AbstractMetaService<SqlConnection> {
@Override
public List<MetaColumnInfo> queryColumns(
- SqlConnection connection, String database, String table) {
+ SqlConnection connection, String schemaname, String table) {
try {
- return connection.getColumns(database, table);
+ return connection.getColumns(schemaname, table);
} catch (SQLException | ClassNotFoundException e) {
throw new RuntimeException("Fail to get Sql columns(获取字段列表失败)", e);
}
diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/MysqlMetaService.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/PostgresqlMetaService.java
similarity index 77%
copy from linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/MysqlMetaService.java
copy to linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/PostgresqlMetaService.java
index a43e7048f..b305fa58c 100644
--- a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/MysqlMetaService.java
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/PostgresqlMetaService.java
@@ -21,13 +21,17 @@ import org.apache.linkis.datasourcemanager.common.util.json.Json;
import org.apache.linkis.metadata.query.common.domain.MetaColumnInfo;
import org.apache.linkis.metadata.query.common.service.AbstractMetaService;
import org.apache.linkis.metadata.query.common.service.MetadataConnection;
+import org.apache.linkis.metadata.query.service.conf.SqlParamsMapper;
+import org.apache.linkis.metadata.query.service.postgres.SqlConnection;
+
+import org.apache.logging.log4j.util.Strings;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-public class MysqlMetaService extends AbstractMetaService<SqlConnection> {
+public class PostgresqlMetaService extends AbstractMetaService<SqlConnection> {
@Override
public MetadataConnection<SqlConnection> getConnection(
String operator, Map<String, Object> params) throws Exception {
@@ -46,6 +50,16 @@ public class MysqlMetaService extends AbstractMetaService<SqlConnection> {
String password =
String.valueOf(
params.getOrDefault(SqlParamsMapper.PARAM_SQL_PASSWORD.getValue(), ""));
+ // In PG, each database under the same instance is completely independent, and the table is
+ // stored under the catalog with the same library name.
+ // \c (\connect) Behind the dbname command is to close the current connection and create a
+ // new connection to achieve database switching
+ // Cannot directly switch to another database under the current database connection, and
+ // cannot show tables from xxxx, select * from database.table like MySQL
+
+ String database =
+ String.valueOf(
+ params.getOrDefault(SqlParamsMapper.PARAM_SQL_DATABASE.getValue(), ""));
Map<String, Object> extraParams = new HashMap<>();
Object sqlParamObj = params.get(SqlParamsMapper.PARAM_SQL_EXTRA_PARAMS.getValue());
if (null != sqlParamObj) {
@@ -58,25 +72,28 @@ public class MysqlMetaService extends AbstractMetaService<SqlConnection> {
}
}
assert extraParams != null;
+ if (Strings.isBlank(database)) {
+ database = "";
+ }
return new MetadataConnection<>(
- new SqlConnection(host, port, username, password, extraParams));
+ new SqlConnection(host, port, username, password, database, extraParams));
}
@Override
- public List<String> queryDatabases(SqlConnection connection) {
+ public List<String> queryTables(SqlConnection connection, String schemaname) {
try {
- return connection.getAllDatabases();
+ return connection.getAllTables(schemaname);
} catch (SQLException e) {
- throw new RuntimeException("Fail to get Sql databases(获取数据库列表失败)", e);
+ throw new RuntimeException("Fail to get Sql tables(获取表列表失败)", e);
}
}
@Override
- public List<String> queryTables(SqlConnection connection, String database) {
+ public List<String> queryDatabases(SqlConnection connection) {
try {
- return connection.getAllTables(database);
+ return connection.getAllDatabases();
} catch (SQLException e) {
- throw new RuntimeException("Fail to get Sql tables(获取表列表失败)", e);
+ throw new RuntimeException("Fail to get Sql databases(获取数据库列表失败)", e);
}
}
diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/MysqlMetaService.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/SqlserverMetaService.java
similarity index 94%
copy from linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/MysqlMetaService.java
copy to linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/SqlserverMetaService.java
index a43e7048f..1c8f57230 100644
--- a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/MysqlMetaService.java
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/SqlserverMetaService.java
@@ -21,13 +21,15 @@ import org.apache.linkis.datasourcemanager.common.util.json.Json;
import org.apache.linkis.metadata.query.common.domain.MetaColumnInfo;
import org.apache.linkis.metadata.query.common.service.AbstractMetaService;
import org.apache.linkis.metadata.query.common.service.MetadataConnection;
+import org.apache.linkis.metadata.query.service.conf.SqlParamsMapper;
+import org.apache.linkis.metadata.query.service.sqlserver.SqlConnection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-public class MysqlMetaService extends AbstractMetaService<SqlConnection> {
+public class SqlserverMetaService extends AbstractMetaService<SqlConnection> {
@Override
public MetadataConnection<SqlConnection> getConnection(
String operator, Map<String, Object> params) throws Exception {
diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/conf/SqlParamsMapper.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/conf/SqlParamsMapper.java
new file mode 100644
index 000000000..9287e6d73
--- /dev/null
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/conf/SqlParamsMapper.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.metadata.query.service.conf;
+
+import org.apache.linkis.common.conf.CommonVars;
+
+public class SqlParamsMapper {
+ public static final CommonVars<String> PARAM_SQL_HOST =
+ CommonVars.apply("wds.linkis.server.mdm.service.sql.host", "host");
+
+ public static final CommonVars<String> PARAM_SQL_PORT =
+ CommonVars.apply("wds.linkis.server.mdm.service.sql.port", "port");
+
+ public static final CommonVars<String> PARAM_SQL_USERNAME =
+ CommonVars.apply("wds.linkis.server.mdm.service.sql.username", "username");
+
+ public static final CommonVars<String> PARAM_SQL_PASSWORD =
+ CommonVars.apply("wds.linkis.server.mdm.service.sql.password", "password");
+
+ public static final CommonVars<String> PARAM_SQL_DATABASE =
+ CommonVars.apply("wds.linkis.server.mdm.service.sql.instance", "instance");
+
+ public static final CommonVars<String> PARAM_SQL_EXTRA_PARAMS =
+ CommonVars.apply("wds.linkis.server.mdm.service.sql.params", "params");
+}
diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/db2/SqlConnection.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/db2/SqlConnection.java
new file mode 100644
index 000000000..647e4b281
--- /dev/null
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/db2/SqlConnection.java
@@ -0,0 +1,247 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.metadata.query.service.db2;
+
+import org.apache.linkis.common.conf.CommonVars;
+import org.apache.linkis.metadata.query.common.domain.MetaColumnInfo;
+
+import org.apache.logging.log4j.util.Strings;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.sql.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class SqlConnection implements Closeable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SqlConnection.class);
+
+ private static final CommonVars<String> SQL_DRIVER_CLASS =
+ CommonVars.apply(
+ "wds.linkis.server.mdm.service.db2.driver", "com.ibm.db2.jcc.DB2Driver");
+
+ private static final CommonVars<String> SQL_CONNECT_URL =
+ CommonVars.apply("wds.linkis.server.mdm.service.db2.url", "jdbc:db2://%s:%s/%s");
+
+ private Connection conn;
+
+ private ConnectMessage connectMessage;
+
+ public SqlConnection(
+ String host,
+ Integer port,
+ String username,
+ String password,
+ String database,
+ Map<String, Object> extraParams)
+ throws ClassNotFoundException, SQLException {
+ if (Strings.isBlank(database)) {
+ database = "SAMPLE";
+ }
+ connectMessage = new ConnectMessage(host, port, username, password, extraParams);
+ conn = getDBConnection(connectMessage, database);
+ // Try to create statement
+ Statement statement = conn.createStatement();
+ statement.close();
+ }
+
+ public List<String> getAllDatabases() throws SQLException {
+ // db2 "select schemaname from syscat.schemata"
+ List<String> dataBaseName = new ArrayList<>();
+ Statement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = conn.createStatement();
+ rs = stmt.executeQuery("list database directory");
+ // rs = stmt.executeQuery("SELECT * FROM SYSIBMADM.APPLICATIONS WITH UR");
+ // rs = stmt.executeQuery("select * from syscat.tables");
+ while (rs.next()) {
+ dataBaseName.add(rs.getString(1));
+ }
+ } finally {
+ closeResource(null, stmt, rs);
+ }
+ return dataBaseName;
+ }
+
+ public List<String> getAllTables(String tabschema) throws SQLException {
+ List<String> tableNames = new ArrayList<>();
+ Statement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = conn.createStatement();
+ rs =
+ stmt.executeQuery(
+ "select tabname as table_name from syscat.tables where tabschema = '"
+ + tabschema
+ + "' and type = 'T' order by tabschema, tabname");
+ while (rs.next()) {
+ tableNames.add(rs.getString(1));
+ }
+ return tableNames;
+ } finally {
+ closeResource(null, stmt, rs);
+ }
+ }
+
+ public List<MetaColumnInfo> getColumns(String schemaname, String table)
+ throws SQLException, ClassNotFoundException {
+ List<MetaColumnInfo> columns = new ArrayList<>();
+ // String columnSql = "SELECT * FROM syscat.columns WHERE TABSCHEMA = '" + schemaname
+ // + "' AND TABNAME = '" + table + "'";
+ String columnSql = "SELECT * FROM " + schemaname + "." + table + " WHERE 1 = 2";
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+ ResultSetMetaData meta = null;
+ try {
+ // List<String> primaryKeys = getPrimaryKeys(getDBConnection(connectMessage,
+ // schemaname), table);
+ List<String> primaryKeys = getPrimaryKeys(conn, table);
+ ps = conn.prepareStatement(columnSql);
+ rs = ps.executeQuery();
+ meta = rs.getMetaData();
+ int columnCount = meta.getColumnCount();
+ for (int i = 1; i < columnCount + 1; i++) {
+ MetaColumnInfo info = new MetaColumnInfo();
+ info.setIndex(i);
+ info.setName(meta.getColumnName(i));
+ info.setType(meta.getColumnTypeName(i));
+ if (primaryKeys.contains(meta.getColumnName(i))) {
+ info.setPrimaryKey(true);
+ }
+ columns.add(info);
+ }
+ } finally {
+ closeResource(null, ps, rs);
+ }
+ return columns;
+ }
+
+ /**
+ * Get primary keys
+ *
+ * @param connection connection
+ * @param table table name
+ * @return
+ * @throws SQLException
+ */
+ private List<String> getPrimaryKeys(Connection connection, String table) throws SQLException {
+ ResultSet rs = null;
+ List<String> primaryKeys = new ArrayList<>();
+ try {
+ DatabaseMetaData dbMeta = connection.getMetaData();
+ rs = dbMeta.getPrimaryKeys(null, null, table);
+ while (rs.next()) {
+ primaryKeys.add(rs.getString("column_name"));
+ }
+ return primaryKeys;
+ } finally {
+ if (null != rs) {
+ rs.close();
+ }
+ // if(null != rs){
+ // closeResource(connection, null, rs);
+ // }
+ }
+ }
+
+ /**
+ * close database resource
+ *
+ * @param connection connection
+ * @param statement statement
+ * @param resultSet result set
+ */
+ private void closeResource(Connection connection, Statement statement, ResultSet resultSet) {
+ try {
+ if (null != resultSet && !resultSet.isClosed()) {
+ resultSet.close();
+ }
+ if (null != statement && !statement.isClosed()) {
+ statement.close();
+ }
+ if (null != connection && !connection.isClosed()) {
+ connection.close();
+ }
+ } catch (SQLException e) {
+ LOG.warn("Fail to release resource [" + e.getMessage() + "]", e);
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ closeResource(conn, null, null);
+ }
+
+ /**
+ * @param connectMessage
+ * @param database
+ * @return
+ * @throws ClassNotFoundException
+ */
+ private Connection getDBConnection(ConnectMessage connectMessage, String database)
+ throws ClassNotFoundException, SQLException {
+ String extraParamString =
+ connectMessage.extraParams.entrySet().stream()
+ .map(e -> String.join("=", e.getKey(), String.valueOf(e.getValue())))
+ .collect(Collectors.joining("&"));
+ Class.forName(SQL_DRIVER_CLASS.getValue());
+ String url =
+ String.format(
+ SQL_CONNECT_URL.getValue(),
+ connectMessage.host,
+ connectMessage.port,
+ database);
+ if (!connectMessage.extraParams.isEmpty()) {
+ url += "?" + extraParamString;
+ }
+ return DriverManager.getConnection(url, connectMessage.username, connectMessage.password);
+ }
+
+ /** Connect message */
+ private static class ConnectMessage {
+ private String host;
+
+ private Integer port;
+
+ private String username;
+
+ private String password;
+
+ private Map<String, Object> extraParams;
+
+ public ConnectMessage(
+ String host,
+ Integer port,
+ String username,
+ String password,
+ Map<String, Object> extraParams) {
+ this.host = host;
+ this.port = port;
+ this.username = username;
+ this.password = password;
+ this.extraParams = extraParams;
+ }
+ }
+}
diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/dm/SqlConnection.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/dm/SqlConnection.java
new file mode 100644
index 000000000..7b878b215
--- /dev/null
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/dm/SqlConnection.java
@@ -0,0 +1,262 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.metadata.query.service.dm;
+
+import org.apache.linkis.common.conf.CommonVars;
+import org.apache.linkis.metadata.query.common.domain.MetaColumnInfo;
+
+import org.apache.commons.lang.StringUtils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.sql.*;
+import java.util.*;
+import java.util.stream.Collectors;
+
+public class SqlConnection implements Closeable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SqlConnection.class);
+
+ private static final CommonVars<String> SQL_DRIVER_CLASS =
+ CommonVars.apply(
+ "wds.linkis.server.mdm.service.dameng.driver", "dm.jdbc.driver.DmDriver");
+
+ private static final CommonVars<String> SQL_CONNECT_URL =
+ CommonVars.apply("wds.linkis.server.mdm.service.dameng.url", "jdbc:dm://%s:%s/%s");
+
+ private Connection conn;
+
+ private ConnectMessage connectMessage;
+
+ public SqlConnection(
+ String host,
+ Integer port,
+ String username,
+ String password,
+ String database,
+ Map<String, Object> extraParams)
+ throws ClassNotFoundException, SQLException {
+ connectMessage = new ConnectMessage(host, port, username, password, extraParams);
+ conn = getDBConnection(connectMessage, database);
+ // Try to create statement
+ Statement statement = conn.createStatement();
+ statement.close();
+ }
+
+ public List<String> getAllDatabases() throws SQLException {
+ List<String> dataBaseName = new ArrayList<>();
+ Statement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = conn.createStatement();
+ rs =
+ stmt.executeQuery(
+ "select distinct object_name TABLE_SCHEMA from all_objects where object_type = 'SCH'");
+ while (rs.next()) {
+ dataBaseName.add(rs.getString(1));
+ }
+ } finally {
+ closeResource(null, stmt, rs);
+ }
+ return dataBaseName;
+ }
+
+ public List<String> getAllTables(String schema) throws SQLException {
+ List<String> tableNames = new ArrayList<>();
+ Statement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = conn.createStatement();
+ rs =
+ stmt.executeQuery(
+ "select TABLE_NAME from dba_tables where owner='" + schema + "'");
+ while (rs.next()) {
+ tableNames.add(rs.getString(1));
+ }
+ return tableNames;
+ } finally {
+ closeResource(null, stmt, rs);
+ }
+ }
+
+ public List<MetaColumnInfo> getColumns(String database, String table)
+ throws SQLException, ClassNotFoundException {
+ List<MetaColumnInfo> columns = new ArrayList<>();
+ String columnSql = "SELECT * FROM " + database + "." + table + " WHERE 1 = 2";
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+ ResultSetMetaData meta = null;
+ try {
+ List<String> primaryKeys = getPrimaryKeys(database, table);
+ Map<String, String> columnCommentMap = getColumnComment(database, table);
+ ps = conn.prepareStatement(columnSql);
+ rs = ps.executeQuery();
+ meta = rs.getMetaData();
+ int columnCount = meta.getColumnCount();
+ for (int i = 1; i < columnCount + 1; i++) {
+ MetaColumnInfo info = new MetaColumnInfo();
+ info.setIndex(i);
+ info.setLength(meta.getColumnDisplaySize(i));
+ info.setName(meta.getColumnName(i));
+ info.setType(meta.getColumnTypeName(i));
+ if (primaryKeys.contains(meta.getColumnName(i))) {
+ info.setPrimaryKey(true);
+ }
+ String colComment = columnCommentMap.get(meta.getColumnName(i));
+ if (StringUtils.isNotBlank(colComment)) {
+ info.setColComment(colComment);
+ } else {
+ info.setColComment(StringUtils.EMPTY);
+ }
+ columns.add(info);
+ }
+ } finally {
+ closeResource(null, ps, rs);
+ }
+ return columns;
+ }
+
+ private List<String> getPrimaryKeys(
+ /*Connection connection, */ String schema, String table) throws SQLException {
+ ResultSet rs = null;
+ List<String> primaryKeys = new ArrayList<>();
+ // try {
+ DatabaseMetaData dbMeta = conn.getMetaData();
+ rs = dbMeta.getPrimaryKeys(null, schema, table);
+ while (rs.next()) {
+ primaryKeys.add(rs.getString("COLUMN_NAME"));
+ }
+ return primaryKeys;
+ /*}finally{
+ if(null != rs){
+ closeResource(connection, null, rs);
+ }
+ }*/
+ }
+ /**
+ * Get Column Comment
+ *
+ * @param table table name
+ * @return
+ * @throws SQLException
+ */
+ private Map<String, String> getColumnComment(String schema, String table) throws SQLException {
+ ResultSet rs = null;
+ Map<String, String> columnComment = new HashMap();
+
+ DatabaseMetaData dbMeta = conn.getMetaData();
+ rs = dbMeta.getColumns(null, schema, table, "%");
+ while (rs.next()) {
+ columnComment.put(rs.getString("COlUMN_NAME"), rs.getString("REMARKS"));
+ }
+ return columnComment;
+ }
+
+ /**
+ * close database resource
+ *
+ * @param connection connection
+ * @param statement statement
+ * @param resultSet result set
+ */
+ private void closeResource(Connection connection, Statement statement, ResultSet resultSet) {
+ try {
+ if (null != resultSet && !resultSet.isClosed()) {
+ resultSet.close();
+ }
+ if (null != statement && !statement.isClosed()) {
+ statement.close();
+ }
+ if (null != connection && !connection.isClosed()) {
+ connection.close();
+ }
+ } catch (SQLException e) {
+ LOG.warn("Fail to release resource [" + e.getMessage() + "]", e);
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ closeResource(conn, null, null);
+ }
+
+ /**
+ * @param connectMessage
+ * @param database
+ * @return
+ * @throws ClassNotFoundException
+ */
+ private Connection getDBConnection(ConnectMessage connectMessage, String database)
+ throws ClassNotFoundException, SQLException {
+ String extraParamString =
+ connectMessage.extraParams.entrySet().stream()
+ .map(e -> String.join("=", e.getKey(), String.valueOf(e.getValue())))
+ .collect(Collectors.joining("&"));
+ Class.forName(SQL_DRIVER_CLASS.getValue());
+ String url =
+ String.format(
+ SQL_CONNECT_URL.getValue(),
+ connectMessage.host,
+ connectMessage.port,
+ database);
+ if (!connectMessage.extraParams.isEmpty()) {
+ url += "?" + extraParamString;
+ }
+ try {
+ // return DriverManager.getConnection(url, connectMessage.username,
+ // connectMessage.password);
+ Properties prop = new Properties();
+ prop.put("user", connectMessage.username);
+ prop.put("password", connectMessage.password);
+ prop.put("remarksReporting", "true");
+ return DriverManager.getConnection(url, prop);
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw e;
+ }
+ }
+
+ /** Connect message */
+ private static class ConnectMessage {
+ private String host;
+
+ private Integer port;
+
+ private String username;
+
+ private String password;
+
+ private Map<String, Object> extraParams;
+
+ public ConnectMessage(
+ String host,
+ Integer port,
+ String username,
+ String password,
+ Map<String, Object> extraParams) {
+ this.host = host;
+ this.port = port;
+ this.username = username;
+ this.password = password;
+ this.extraParams = extraParams;
+ }
+ }
+}
diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/greenplum/SqlConnection.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/greenplum/SqlConnection.java
new file mode 100644
index 000000000..a8a91e07f
--- /dev/null
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/greenplum/SqlConnection.java
@@ -0,0 +1,243 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.metadata.query.service.greenplum;
+
+import org.apache.linkis.common.conf.CommonVars;
+import org.apache.linkis.metadata.query.common.domain.MetaColumnInfo;
+
+import org.apache.logging.log4j.util.Strings;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.sql.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class SqlConnection implements Closeable {
+ private static final Logger LOG = LoggerFactory.getLogger(SqlConnection.class);
+
+ private static final CommonVars<String> SQL_DRIVER_CLASS =
+ CommonVars.apply(
+ "wds.linkis.server.mdm.service.greenplum.driver",
+ "com.pivotal.jdbc.GreenplumDriver");
+
+ private static final CommonVars<String> SQL_CONNECT_URL =
+ CommonVars.apply(
+ "wds.linkis.server.mdm.service.greenplum.url",
+ "jdbc:pivotal:greenplum://%s:%s;DatabaseName=%s");
+
+ private Connection conn;
+
+ private ConnectMessage connectMessage;
+
+ public SqlConnection(
+ String host,
+ Integer port,
+ String username,
+ String password,
+ String database,
+ Map<String, Object> extraParams)
+ throws ClassNotFoundException, SQLException {
+ connectMessage = new ConnectMessage(host, port, username, password, extraParams);
+ if (Strings.isBlank(database)) {
+ database = "";
+ }
+ conn = getDBConnection(connectMessage, database);
+ // Try to create statement
+ Statement statement = conn.createStatement();
+ statement.close();
+ }
+
+ public List<String> getAllDatabases() throws SQLException {
+ List<String> dataBaseName = new ArrayList<>();
+ Statement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = conn.createStatement();
+ rs = stmt.executeQuery("select datname from pg_database");
+ while (rs.next()) {
+ dataBaseName.add(rs.getString(1));
+ }
+ } finally {
+ closeResource(null, stmt, rs);
+ }
+ return dataBaseName;
+ }
+
+ public List<String> getAllTables(String schemaname) throws SQLException {
+ List<String> tableNames = new ArrayList<>();
+ Statement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = conn.createStatement();
+ rs =
+ stmt.executeQuery(
+ "SELECT tablename FROM pg_tables where schemaname = '"
+ + schemaname
+ + "'");
+ // rs = stmt.executeQuery("SELECT table_name FROM
+ // information_schema.tables");
+ while (rs.next()) {
+ tableNames.add(rs.getString(1));
+ }
+ return tableNames;
+ } finally {
+ closeResource(null, stmt, rs);
+ }
+ }
+
+ public List<MetaColumnInfo> getColumns(String schemaname, String table)
+ throws SQLException, ClassNotFoundException {
+ List<MetaColumnInfo> columns = new ArrayList<>();
+ String columnSql = "SELECT * FROM " + schemaname + "." + table + " WHERE 1 = 2";
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+ ResultSetMetaData meta;
+ try {
+ List<String> primaryKeys =
+ getPrimaryKeys(/*getDBConnection(connectMessage, schemaname), */ table);
+ ps = conn.prepareStatement(columnSql);
+ rs = ps.executeQuery();
+ meta = rs.getMetaData();
+ int columnCount = meta.getColumnCount();
+ for (int i = 1; i < columnCount + 1; i++) {
+ MetaColumnInfo info = new MetaColumnInfo();
+ info.setIndex(i);
+ info.setName(meta.getColumnName(i));
+ info.setType(meta.getColumnTypeName(i));
+ if (primaryKeys.contains(meta.getColumnName(i))) {
+ info.setPrimaryKey(true);
+ }
+ columns.add(info);
+ }
+ } finally {
+ closeResource(null, ps, rs);
+ }
+ return columns;
+ }
+
+ /**
+ * Get primary keys
+ *
+ * @param connection connection
+ * @param table table name
+ * @return
+ * @throws SQLException
+ */
+ private List<String> getPrimaryKeys(
+ /*Connection connection, */ String table) throws SQLException {
+ ResultSet rs = null;
+ List<String> primaryKeys = new ArrayList<>();
+ // try {
+ DatabaseMetaData dbMeta = conn.getMetaData();
+ rs = dbMeta.getPrimaryKeys(null, null, table);
+ while (rs.next()) {
+ primaryKeys.add(rs.getString("column_name"));
+ }
+ return primaryKeys;
+ /*}finally{
+ if(null != rs){
+ closeResource(connection, null, rs);
+ }
+ }*/
+ }
+
+ /**
+ * close database resource
+ *
+ * @param connection connection
+ * @param statement statement
+ * @param resultSet result set
+ */
+ private void closeResource(Connection connection, Statement statement, ResultSet resultSet) {
+ try {
+ if (null != resultSet && !resultSet.isClosed()) {
+ resultSet.close();
+ }
+ if (null != statement && !statement.isClosed()) {
+ statement.close();
+ }
+ if (null != connection && !connection.isClosed()) {
+ connection.close();
+ }
+ } catch (SQLException e) {
+ LOG.warn("Fail to release resource [" + e.getMessage() + "]", e);
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ closeResource(conn, null, null);
+ }
+
+ /**
+ * @param connectMessage
+ * @param database
+ * @return
+ * @throws ClassNotFoundException
+ */
+ private Connection getDBConnection(ConnectMessage connectMessage, String database)
+ throws ClassNotFoundException, SQLException {
+ String extraParamString =
+ connectMessage.extraParams.entrySet().stream()
+ .map(e -> String.join("=", e.getKey(), String.valueOf(e.getValue())))
+ .collect(Collectors.joining("&"));
+ Class.forName(SQL_DRIVER_CLASS.getValue());
+ String url =
+ String.format(
+ SQL_CONNECT_URL.getValue(),
+ connectMessage.host,
+ connectMessage.port,
+ database);
+ if (!connectMessage.extraParams.isEmpty()) {
+ url += "?" + extraParamString;
+ }
+ return DriverManager.getConnection(url, connectMessage.username, connectMessage.password);
+ }
+
+ /** Connect message */
+ private static class ConnectMessage {
+ private String host;
+
+ private Integer port;
+
+ private String username;
+
+ private String password;
+
+ private Map<String, Object> extraParams;
+
+ public ConnectMessage(
+ String host,
+ Integer port,
+ String username,
+ String password,
+ Map<String, Object> extraParams) {
+ this.host = host;
+ this.port = port;
+ this.username = username;
+ this.password = password;
+ this.extraParams = extraParams;
+ }
+ }
+}
diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/kingbase/SqlConnection.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/kingbase/SqlConnection.java
new file mode 100644
index 000000000..989eb3053
--- /dev/null
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/kingbase/SqlConnection.java
@@ -0,0 +1,261 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.metadata.query.service.kingbase;
+
+import org.apache.linkis.common.conf.CommonVars;
+import org.apache.linkis.metadata.query.common.domain.MetaColumnInfo;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.sql.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class SqlConnection implements Closeable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SqlConnection.class);
+
+ private static final CommonVars<String> SQL_DRIVER_CLASS =
+ CommonVars.apply(
+ "wds.linkis.server.mdm.service.kingbase.driver", "com.kingbase8.Driver");
+
+ private static final CommonVars<String> SQL_CONNECT_URL =
+ CommonVars.apply(
+ "wds.linkis.server.mdm.service.kingbase.url",
+ "jdbc:kingbase8://%s:%s/%s?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8");
+
+ private Connection conn;
+
+ private ConnectMessage connectMessage;
+
+ public SqlConnection(
+ String host,
+ Integer port,
+ String username,
+ String password,
+ String database,
+ Map<String, Object> extraParams)
+ throws ClassNotFoundException, SQLException {
+ connectMessage = new ConnectMessage(host, port, username, password, extraParams);
+ conn = getDBConnection(connectMessage, database);
+ // Try to create statement
+ Statement statement = conn.createStatement();
+ statement.close();
+ }
+
+ public List<String> getAllDatabases() throws SQLException {
+ List<String> dataBaseName = new ArrayList<>();
+ Statement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = conn.createStatement();
+ rs = stmt.executeQuery("select schema_name from information_schema.schemata");
+ while (rs.next()) {
+ dataBaseName.add(rs.getString(1));
+ }
+ } finally {
+ closeResource(null, stmt, rs);
+ }
+ return dataBaseName;
+ // throw new UnsupportedOperationException("kingbase数据库不能像mysql show
+ // databases来获取,应该是存在某个地方来获取的");
+ }
+
+ public List<String> getAllTables(String schema) throws SQLException {
+ List<String> tableNames = new ArrayList<>();
+ Statement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = conn.createStatement();
+ rs =
+ stmt.executeQuery(
+ "SELECT ('\"' || table_schema || '\".\"' || table_name || '\"') AS table_name "
+ + "FROM information_schema.TABLES WHERE table_schema ='"
+ + schema
+ + "'");
+ while (rs.next()) {
+ tableNames.add(rs.getString(1));
+ }
+ return tableNames;
+ } finally {
+ closeResource(null, stmt, rs);
+ }
+ }
+
+ public List<MetaColumnInfo> getColumns(String database, String table)
+ throws SQLException, ClassNotFoundException {
+ List<MetaColumnInfo> columns = new ArrayList<>();
+ String columnSql = "SELECT * FROM " + database + "." + table + " WHERE 1 = 2";
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+ ResultSetMetaData meta = null;
+ try {
+ List<String> primaryKeys = getPrimaryKeys(table);
+ ps = conn.prepareStatement(columnSql);
+ rs = ps.executeQuery();
+ meta = rs.getMetaData();
+ int columnCount = meta.getColumnCount();
+ for (int i = 1; i < columnCount + 1; i++) {
+ MetaColumnInfo info = new MetaColumnInfo();
+ info.setIndex(i);
+ info.setName(meta.getColumnName(i));
+ info.setType(meta.getColumnTypeName(i));
+ if (primaryKeys.contains(meta.getColumnName(i))) {
+ info.setPrimaryKey(true);
+ }
+ columns.add(info);
+ }
+ } finally {
+ closeResource(null, ps, rs);
+ }
+ return columns;
+ }
+
+ // /**
+ // * Get primary keys
+ // * @param connection connection
+ // * @param table table name
+ // * @return
+ // * @throws SQLException
+ // */
+ // private List<String> getPrimaryKeys(Connection connection, String table) throws
+ // SQLException {
+ // ResultSet rs = null;
+ // List<String> primaryKeys = new ArrayList<>();
+ // try {
+ // DatabaseMetaData dbMeta = connection.getMetaData();
+ // rs = dbMeta.getPrimaryKeys(null, null, table);
+ // while(rs.next()){
+ // primaryKeys.add(rs.getString("column_name"));
+ // }
+ // return primaryKeys;
+ // }finally{
+ // if(null != rs){
+ // closeResource(connection, null, rs);
+ // }
+ // }
+ // }
+
+ private List<String> getPrimaryKeys(
+ /*Connection connection, */ String table) throws SQLException {
+ ResultSet rs = null;
+ List<String> primaryKeys = new ArrayList<>();
+ // try {
+ DatabaseMetaData dbMeta = conn.getMetaData();
+ rs = dbMeta.getPrimaryKeys(null, null, table);
+ while (rs.next()) {
+ primaryKeys.add(rs.getString("column_name"));
+ }
+ return primaryKeys;
+ /*}finally{
+ if(null != rs){
+ closeResource(connection, null, rs);
+ }
+ }*/
+ }
+
+ /**
+ * close database resource
+ *
+ * @param connection connection
+ * @param statement statement
+ * @param resultSet result set
+ */
+ private void closeResource(Connection connection, Statement statement, ResultSet resultSet) {
+ try {
+ if (null != resultSet && !resultSet.isClosed()) {
+ resultSet.close();
+ }
+ if (null != statement && !statement.isClosed()) {
+ statement.close();
+ }
+ if (null != connection && !connection.isClosed()) {
+ connection.close();
+ }
+ } catch (SQLException e) {
+ LOG.warn("Fail to release resource [" + e.getMessage() + "]", e);
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ closeResource(conn, null, null);
+ }
+
+ /**
+ * @param connectMessage
+ * @param database
+ * @return
+ * @throws ClassNotFoundException
+ */
+ private Connection getDBConnection(ConnectMessage connectMessage, String database)
+ throws ClassNotFoundException, SQLException {
+ String extraParamString =
+ connectMessage.extraParams.entrySet().stream()
+ .map(e -> String.join("=", e.getKey(), String.valueOf(e.getValue())))
+ .collect(Collectors.joining("&"));
+ Class.forName(SQL_DRIVER_CLASS.getValue());
+ String url =
+ String.format(
+ SQL_CONNECT_URL.getValue(),
+ connectMessage.host,
+ connectMessage.port,
+ database);
+ if (!connectMessage.extraParams.isEmpty()) {
+ url += "?" + extraParamString;
+ }
+ try {
+ return DriverManager.getConnection(
+ url, connectMessage.username, connectMessage.password);
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw e;
+ }
+ }
+
+ /** Connect message */
+ private static class ConnectMessage {
+ private String host;
+
+ private Integer port;
+
+ private String username;
+
+ private String password;
+
+ private Map<String, Object> extraParams;
+
+ public ConnectMessage(
+ String host,
+ Integer port,
+ String username,
+ String password,
+ Map<String, Object> extraParams) {
+ this.host = host;
+ this.port = port;
+ this.username = username;
+ this.password = password;
+ this.extraParams = extraParams;
+ }
+ }
+}
diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/mysql/SqlConnection.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/mysql/SqlConnection.java
new file mode 100644
index 000000000..9acb280be
--- /dev/null
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/mysql/SqlConnection.java
@@ -0,0 +1,235 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.metadata.query.service.mysql;
+
+import org.apache.linkis.common.conf.CommonVars;
+import org.apache.linkis.metadata.query.common.domain.MetaColumnInfo;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.sql.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class SqlConnection implements Closeable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SqlConnection.class);
+
+ private static final CommonVars<String> SQL_DRIVER_CLASS =
+ CommonVars.apply("wds.linkis.server.mdm.service.sql.driver", "com.mysql.jdbc.Driver");
+
+ private static final CommonVars<String> SQL_CONNECT_URL =
+ CommonVars.apply("wds.linkis.server.mdm.service.sql.url", "jdbc:mysql://%s:%s/%s");
+
+ private static final CommonVars<Integer> SQL_CONNECT_TIMEOUT =
+ CommonVars.apply("wds.linkis.server.mdm.service.sql.connect.timeout", 3000);
+
+ private static final CommonVars<Integer> SQL_SOCKET_TIMEOUT =
+ CommonVars.apply("wds.linkis.server.mdm.service.sql.socket.timeout", 6000);
+
+ private Connection conn;
+
+ private ConnectMessage connectMessage;
+
+ public SqlConnection(
+ String host,
+ Integer port,
+ String username,
+ String password,
+ Map<String, Object> extraParams)
+ throws ClassNotFoundException, SQLException {
+ connectMessage = new ConnectMessage(host, port, username, password, extraParams);
+ conn = getDBConnection(connectMessage, "");
+ // Try to create statement
+ Statement statement = conn.createStatement();
+ statement.close();
+ }
+
+ public List<String> getAllDatabases() throws SQLException {
+ List<String> dataBaseName = new ArrayList<>();
+ Statement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = conn.createStatement();
+ rs = stmt.executeQuery("SHOW DATABASES");
+ while (rs.next()) {
+ dataBaseName.add(rs.getString(1));
+ }
+ } finally {
+ closeResource(null, stmt, rs);
+ }
+ return dataBaseName;
+ }
+
+ public List<String> getAllTables(String database) throws SQLException {
+ List<String> tableNames = new ArrayList<>();
+ Statement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = conn.createStatement();
+ rs = stmt.executeQuery("SHOW TABLES FROM `" + database + "`");
+ while (rs.next()) {
+ tableNames.add(rs.getString(1));
+ }
+ return tableNames;
+ } finally {
+ closeResource(null, stmt, rs);
+ }
+ }
+
+ public List<MetaColumnInfo> getColumns(String database, String table)
+ throws SQLException, ClassNotFoundException {
+ List<MetaColumnInfo> columns = new ArrayList<>();
+ String columnSql = "SELECT * FROM `" + database + "`.`" + table + "` WHERE 1 = 2";
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+ ResultSetMetaData meta = null;
+ try {
+ List<String> primaryKeys =
+ getPrimaryKeys(getDBConnection(connectMessage, database), table);
+ ps = conn.prepareStatement(columnSql);
+ rs = ps.executeQuery();
+ meta = rs.getMetaData();
+ int columnCount = meta.getColumnCount();
+ for (int i = 1; i < columnCount + 1; i++) {
+ MetaColumnInfo info = new MetaColumnInfo();
+ info.setIndex(i);
+ info.setName(meta.getColumnName(i));
+ info.setType(meta.getColumnTypeName(i));
+ if (primaryKeys.contains(meta.getColumnName(i))) {
+ info.setPrimaryKey(true);
+ }
+ columns.add(info);
+ }
+ } finally {
+ closeResource(null, ps, rs);
+ }
+ return columns;
+ }
+
+ /**
+ * Get primary keys
+ *
+ * @param connection connection
+ * @param table table name
+ * @return
+ * @throws SQLException
+ */
+ private List<String> getPrimaryKeys(Connection connection, String table) throws SQLException {
+ ResultSet rs = null;
+ List<String> primaryKeys = new ArrayList<>();
+ try {
+ DatabaseMetaData dbMeta = connection.getMetaData();
+ rs = dbMeta.getPrimaryKeys(null, null, table);
+ while (rs.next()) {
+ primaryKeys.add(rs.getString("column_name"));
+ }
+ return primaryKeys;
+ } finally {
+ if (null != rs) {
+ closeResource(connection, null, rs);
+ }
+ }
+ }
+
+ /**
+ * close database resource
+ *
+ * @param connection connection
+ * @param statement statement
+ * @param resultSet result set
+ */
+ private void closeResource(Connection connection, Statement statement, ResultSet resultSet) {
+ try {
+ if (null != resultSet && !resultSet.isClosed()) {
+ resultSet.close();
+ }
+ if (null != statement && !statement.isClosed()) {
+ statement.close();
+ }
+ if (null != connection && !connection.isClosed()) {
+ connection.close();
+ }
+ } catch (SQLException e) {
+ LOG.warn("Fail to release resource [" + e.getMessage() + "]", e);
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ closeResource(conn, null, null);
+ }
+
+ /**
+ * @param connectMessage
+ * @param database
+ * @return
+ * @throws ClassNotFoundException
+ */
+ private Connection getDBConnection(ConnectMessage connectMessage, String database)
+ throws ClassNotFoundException, SQLException {
+ String extraParamString =
+ connectMessage.extraParams.entrySet().stream()
+ .map(e -> String.join("=", e.getKey(), String.valueOf(e.getValue())))
+ .collect(Collectors.joining("&"));
+ Class.forName(SQL_DRIVER_CLASS.getValue());
+ String url =
+ String.format(
+ SQL_CONNECT_URL.getValue(),
+ connectMessage.host,
+ connectMessage.port,
+ database);
+ if (!connectMessage.extraParams.isEmpty()) {
+ url += "?" + extraParamString;
+ }
+ return DriverManager.getConnection(url, connectMessage.username, connectMessage.password);
+ }
+
+ /** Connect message */
+ private static class ConnectMessage {
+ private String host;
+
+ private Integer port;
+
+ private String username;
+
+ private String password;
+
+ private Map<String, Object> extraParams;
+
+ public ConnectMessage(
+ String host,
+ Integer port,
+ String username,
+ String password,
+ Map<String, Object> extraParams) {
+ this.host = host;
+ this.port = port;
+ this.username = username;
+ this.password = password;
+ this.extraParams = extraParams;
+ this.extraParams.put("connectTimeout", SQL_CONNECT_TIMEOUT.getValue());
+ this.extraParams.put("socketTimeout", SQL_SOCKET_TIMEOUT.getValue());
+ }
+ }
+}
diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/oracle/SqlConnection.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/oracle/SqlConnection.java
new file mode 100644
index 000000000..40a0efc39
--- /dev/null
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/oracle/SqlConnection.java
@@ -0,0 +1,261 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.metadata.query.service.oracle;
+
+import org.apache.linkis.common.conf.CommonVars;
+import org.apache.linkis.metadata.query.common.domain.MetaColumnInfo;
+
+import org.apache.commons.lang.StringUtils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.sql.*;
+import java.util.*;
+import java.util.stream.Collectors;
+
+public class SqlConnection implements Closeable {
+ private static final Logger LOG = LoggerFactory.getLogger(SqlConnection.class);
+
+ private static final CommonVars<String> SQL_DRIVER_CLASS =
+ CommonVars.apply(
+ "wds.linkis.server.mdm.service.oracle.driver",
+ "oracle.jdbc.driver.OracleDriver");
+
+ private static final CommonVars<String> SQL_CONNECT_URL =
+ CommonVars.apply(
+ "wds.linkis.server.mdm.service.oracle.url", "jdbc:oracle:thin:@%s:%s:%s");
+
+ private Connection conn;
+
+ private ConnectMessage connectMessage;
+
+ public SqlConnection(
+ String host,
+ Integer port,
+ String username,
+ String password,
+ String database,
+ Map<String, Object> extraParams)
+ throws ClassNotFoundException, SQLException {
+ connectMessage = new ConnectMessage(host, port, username, password, extraParams);
+ conn = getDBConnection(connectMessage, database);
+ // Try to create statement
+ Statement statement = conn.createStatement();
+ statement.close();
+ }
+
+ public List<String> getAllDatabases() throws SQLException {
+ List<String> dataBaseName = new ArrayList<>();
+ Statement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = conn.createStatement();
+ rs =
+ stmt.executeQuery(
+ "select username from sys.dba_users WHERE default_tablespace not in ('SYSTEM','SYSAUX') and ACCOUNT_STATUS = 'OPEN'\n");
+ while (rs.next()) {
+ dataBaseName.add(rs.getString("username"));
+ }
+ } finally {
+ closeResource(null, stmt, rs);
+ }
+ return dataBaseName;
+ }
+
+ public List<String> getAllTables(String schemaname) throws SQLException {
+ List<String> tableNames = new ArrayList<>();
+ Statement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = conn.createStatement();
+ rs =
+ stmt.executeQuery(
+ "SELECT table_name FROM sys.dba_tables WHERE owner = '"
+ + schemaname
+ + "'");
+ while (rs.next()) {
+ tableNames.add(rs.getString("TABLE_NAME"));
+ }
+ return tableNames;
+ } finally {
+ closeResource(null, stmt, rs);
+ }
+ }
+
+ public List<MetaColumnInfo> getColumns(String schemaname, String table)
+ throws SQLException, ClassNotFoundException {
+ List<MetaColumnInfo> columns = new ArrayList<>();
+ String columnSql = "SELECT * FROM " + schemaname + "." + table + " WHERE 1 = 2";
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+ ResultSetMetaData meta;
+ try {
+ List<String> primaryKeys =
+ getPrimaryKeys(/*getDBConnection(connectMessage, schemaname), */ table);
+ Map<String, String> columnCommentMap = getColumnComment(schemaname, table);
+ ps = conn.prepareStatement(columnSql);
+ rs = ps.executeQuery();
+ meta = rs.getMetaData();
+ int columnCount = meta.getColumnCount();
+ for (int i = 1; i < columnCount + 1; i++) {
+ MetaColumnInfo info = new MetaColumnInfo();
+ info.setIndex(i);
+ info.setLength(meta.getColumnDisplaySize(i));
+ info.setName(meta.getColumnName(i));
+ info.setType(meta.getColumnTypeName(i));
+ if (primaryKeys.contains(meta.getColumnName(i))) {
+ info.setPrimaryKey(true);
+ }
+ String colComment = columnCommentMap.get(meta.getColumnName(i));
+ if (StringUtils.isNotBlank(colComment)) {
+ info.setColComment(colComment);
+ } else {
+ info.setColComment(StringUtils.EMPTY);
+ }
+
+ columns.add(info);
+ }
+ } finally {
+ closeResource(null, ps, rs);
+ }
+ return columns;
+ }
+
+ /**
+ * Get primary keys // * @param connection connection
+ *
+ * @param table table name
+ * @return
+ * @throws SQLException
+ */
+ private List<String> getPrimaryKeys(
+ /*Connection connection, */ String table) throws SQLException {
+ ResultSet rs = null;
+ List<String> primaryKeys = new ArrayList<>();
+ DatabaseMetaData dbMeta = conn.getMetaData();
+ rs = dbMeta.getPrimaryKeys(null, null, table);
+ while (rs.next()) {
+ primaryKeys.add(rs.getString("column_name"));
+ }
+ return primaryKeys;
+ }
+ /**
+ * Get Column Comment
+ *
+ * @param table table name
+ * @return
+ * @throws SQLException
+ */
+ private Map<String, String> getColumnComment(String schema, String table) throws SQLException {
+ ResultSet rs = null;
+ Map<String, String> columnComment = new HashMap();
+
+ DatabaseMetaData dbMeta = conn.getMetaData();
+ rs = dbMeta.getColumns(null, schema, table, "%");
+ while (rs.next()) {
+ columnComment.put(rs.getString("COlUMN_NAME"), rs.getString("REMARKS"));
+ }
+ return columnComment;
+ }
+
+ /**
+ * close database resource
+ *
+ * @param connection connection
+ * @param statement statement
+ * @param resultSet result set
+ */
+ private void closeResource(Connection connection, Statement statement, ResultSet resultSet) {
+ try {
+ if (null != resultSet && !resultSet.isClosed()) {
+ resultSet.close();
+ }
+ if (null != statement && !statement.isClosed()) {
+ statement.close();
+ }
+ if (null != connection && !connection.isClosed()) {
+ connection.close();
+ }
+ } catch (SQLException e) {
+ LOG.warn("Fail to release resource [" + e.getMessage() + "]", e);
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ closeResource(conn, null, null);
+ }
+
+ /**
+ * @param connectMessage
+ * @param database
+ * @return
+ * @throws ClassNotFoundException
+ */
+ private Connection getDBConnection(ConnectMessage connectMessage, String database)
+ throws ClassNotFoundException, SQLException {
+ String extraParamString =
+ connectMessage.extraParams.entrySet().stream()
+ .map(e -> String.join("=", e.getKey(), String.valueOf(e.getValue())))
+ .collect(Collectors.joining("&"));
+ Class.forName(SQL_DRIVER_CLASS.getValue());
+ String url =
+ String.format(
+ SQL_CONNECT_URL.getValue(),
+ connectMessage.host,
+ connectMessage.port,
+ database);
+ if (!connectMessage.extraParams.isEmpty()) {
+ url += "?" + extraParamString;
+ }
+ Properties prop = new Properties();
+ prop.put("user", connectMessage.username);
+ prop.put("password", connectMessage.password);
+ prop.put("remarksReporting", "true");
+ return DriverManager.getConnection(url, prop);
+ }
+
+ /** Connect message */
+ private static class ConnectMessage {
+ private String host;
+
+ private Integer port;
+
+ private String username;
+
+ private String password;
+
+ private Map<String, Object> extraParams;
+
+ public ConnectMessage(
+ String host,
+ Integer port,
+ String username,
+ String password,
+ Map<String, Object> extraParams) {
+ this.host = host;
+ this.port = port;
+ this.username = username;
+ this.password = password;
+ this.extraParams = extraParams;
+ }
+ }
+}
diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/postgres/SqlConnection.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/postgres/SqlConnection.java
new file mode 100644
index 000000000..f6275c8b8
--- /dev/null
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/postgres/SqlConnection.java
@@ -0,0 +1,240 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.metadata.query.service.postgres;
+
+import org.apache.linkis.common.conf.CommonVars;
+import org.apache.linkis.metadata.query.common.domain.MetaColumnInfo;
+
+import org.apache.logging.log4j.util.Strings;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.sql.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class SqlConnection implements Closeable {
+ private static final Logger LOG = LoggerFactory.getLogger(SqlConnection.class);
+
+ private static final CommonVars<String> SQL_DRIVER_CLASS =
+ CommonVars.apply(
+ "wds.linkis.server.mdm.service.postgre.driver", "org.postgresql.Driver");
+
+ private static final CommonVars<String> SQL_CONNECT_URL =
+ CommonVars.apply(
+ "wds.linkis.server.mdm.service.postgre.url", "jdbc:postgresql://%s:%s/%s");
+
+ private Connection conn;
+
+ private ConnectMessage connectMessage;
+
+ public SqlConnection(
+ String host,
+ Integer port,
+ String username,
+ String password,
+ String database,
+ Map<String, Object> extraParams)
+ throws ClassNotFoundException, SQLException {
+ connectMessage = new ConnectMessage(host, port, username, password, extraParams);
+ if (Strings.isBlank(database)) {
+ database = "";
+ }
+ conn = getDBConnection(connectMessage, database);
+ // Try to create statement
+ Statement statement = conn.createStatement();
+ statement.close();
+ }
+
+ public List<String> getAllDatabases() throws SQLException {
+ List<String> dataBaseName = new ArrayList<>();
+ Statement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = conn.createStatement();
+ rs = stmt.executeQuery("select datname from pg_database");
+ while (rs.next()) {
+ dataBaseName.add(rs.getString(1));
+ }
+ } finally {
+ closeResource(null, stmt, rs);
+ }
+ return dataBaseName;
+ }
+
+ public List<String> getAllTables(String schemaname) throws SQLException {
+ List<String> tableNames = new ArrayList<>();
+ Statement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = conn.createStatement();
+ rs =
+ stmt.executeQuery(
+ "SELECT tablename FROM pg_tables where schemaname = '"
+ + schemaname
+ + "'");
+ // rs = stmt.executeQuery("SELECT table_name FROM
+ // information_schema.tables");
+ while (rs.next()) {
+ tableNames.add(rs.getString(1));
+ }
+ return tableNames;
+ } finally {
+ closeResource(null, stmt, rs);
+ }
+ }
+
+ public List<MetaColumnInfo> getColumns(String schemaname, String table)
+ throws SQLException, ClassNotFoundException {
+ List<MetaColumnInfo> columns = new ArrayList<>();
+ String columnSql = "SELECT * FROM " + schemaname + "." + table + " WHERE 1 = 2";
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+ ResultSetMetaData meta;
+ try {
+ List<String> primaryKeys =
+ getPrimaryKeys(/*getDBConnection(connectMessage, schemaname), */ table);
+ ps = conn.prepareStatement(columnSql);
+ rs = ps.executeQuery();
+ meta = rs.getMetaData();
+ int columnCount = meta.getColumnCount();
+ for (int i = 1; i < columnCount + 1; i++) {
+ MetaColumnInfo info = new MetaColumnInfo();
+ info.setIndex(i);
+ info.setName(meta.getColumnName(i));
+ info.setType(meta.getColumnTypeName(i));
+ if (primaryKeys.contains(meta.getColumnName(i))) {
+ info.setPrimaryKey(true);
+ }
+ columns.add(info);
+ }
+ } finally {
+ closeResource(null, ps, rs);
+ }
+ return columns;
+ }
+
+ /**
+ * Get primary keys // * @param connection connection
+ *
+ * @param table table name
+ * @return
+ * @throws SQLException
+ */
+ private List<String> getPrimaryKeys(
+ /*Connection connection, */ String table) throws SQLException {
+ ResultSet rs = null;
+ List<String> primaryKeys = new ArrayList<>();
+ // try {
+ DatabaseMetaData dbMeta = conn.getMetaData();
+ rs = dbMeta.getPrimaryKeys(null, null, table);
+ while (rs.next()) {
+ primaryKeys.add(rs.getString("column_name"));
+ }
+ return primaryKeys;
+ /*}finally{
+ if(null != rs){
+ closeResource(connection, null, rs);
+ }
+ }*/
+ }
+
+ /**
+ * close database resource
+ *
+ * @param connection connection
+ * @param statement statement
+ * @param resultSet result set
+ */
+ private void closeResource(Connection connection, Statement statement, ResultSet resultSet) {
+ try {
+ if (null != resultSet && !resultSet.isClosed()) {
+ resultSet.close();
+ }
+ if (null != statement && !statement.isClosed()) {
+ statement.close();
+ }
+ if (null != connection && !connection.isClosed()) {
+ connection.close();
+ }
+ } catch (SQLException e) {
+ LOG.warn("Fail to release resource [" + e.getMessage() + "]", e);
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ closeResource(conn, null, null);
+ }
+
+ /**
+ * @param connectMessage
+ * @param database
+ * @return
+ * @throws ClassNotFoundException
+ */
+ private Connection getDBConnection(ConnectMessage connectMessage, String database)
+ throws ClassNotFoundException, SQLException {
+ String extraParamString =
+ connectMessage.extraParams.entrySet().stream()
+ .map(e -> String.join("=", e.getKey(), String.valueOf(e.getValue())))
+ .collect(Collectors.joining("&"));
+ Class.forName(SQL_DRIVER_CLASS.getValue());
+ String url =
+ String.format(
+ SQL_CONNECT_URL.getValue(),
+ connectMessage.host,
+ connectMessage.port,
+ database);
+ if (!connectMessage.extraParams.isEmpty()) {
+ url += "?" + extraParamString;
+ }
+ return DriverManager.getConnection(url, connectMessage.username, connectMessage.password);
+ }
+
+ /** Connect message */
+ private static class ConnectMessage {
+ private String host;
+
+ private Integer port;
+
+ private String username;
+
+ private String password;
+
+ private Map<String, Object> extraParams;
+
+ public ConnectMessage(
+ String host,
+ Integer port,
+ String username,
+ String password,
+ Map<String, Object> extraParams) {
+ this.host = host;
+ this.port = port;
+ this.username = username;
+ this.password = password;
+ this.extraParams = extraParams;
+ }
+ }
+}
diff --git a/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/sqlserver/SqlConnection.java b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/sqlserver/SqlConnection.java
new file mode 100644
index 000000000..1dab48fb4
--- /dev/null
+++ b/linkis-public-enhancements/linkis-datasource/linkis-metadata-query/service/mysql/src/main/java/org/apache/linkis/metadata/query/service/sqlserver/SqlConnection.java
@@ -0,0 +1,257 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.metadata.query.service.sqlserver;
+
+import org.apache.linkis.common.conf.CommonVars;
+import org.apache.linkis.metadata.query.common.domain.MetaColumnInfo;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.sql.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class SqlConnection implements Closeable {
+ private static final Logger LOG = LoggerFactory.getLogger(SqlConnection.class);
+
+ private static final CommonVars<String> SQL_DRIVER_CLASS =
+ CommonVars.apply(
+ "wds.linkis.server.mdm.service.sqlserver.driver",
+ "com.microsoft.jdbc.sqlserver.SQLServerDriver");
+
+ private static final CommonVars<String> SQL_CONNECT_URL =
+ CommonVars.apply(
+ "wds.linkis.server.mdm.service.sqlserver.url",
+ "jdbc:sqlserver://%s:%s;DataBaseName=%s");
+
+ private Connection conn;
+
+ private ConnectMessage connectMessage;
+
+ public SqlConnection(
+ String host,
+ Integer port,
+ String username,
+ String password,
+ Map<String, Object> extraParams)
+ throws ClassNotFoundException, SQLException {
+ connectMessage = new ConnectMessage(host, port, username, password, extraParams);
+ conn = getDBConnection(connectMessage, "");
+ // Try to create statement
+ Statement statement = conn.createStatement();
+ statement.close();
+ }
+
+ public List<String> getAllDatabases() throws SQLException {
+ List<String> dataBaseName = new ArrayList<>();
+ Statement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = conn.createStatement();
+ rs = stmt.executeQuery("SELECT Name FROM Master..SysDatabases ORDER BY Name");
+ while (rs.next()) {
+ dataBaseName.add(rs.getString(1));
+ }
+ } finally {
+ closeResource(null, stmt, rs);
+ }
+ return dataBaseName;
+ }
+
+ /**
+ * XType = 'U' 表示所有用户表 XType = 'S' 表示所有系统表
+ *
+ * @param database 数据库名
+ * @return 数据表列表
+ * @throws SQLException 异常
+ */
+ public List<String> getAllTables(String database) throws SQLException {
+ List<String> tableNames = new ArrayList<>();
+ Statement stmt = null;
+ ResultSet rs = null;
+ try {
+ stmt = conn.createStatement();
+ rs =
+ stmt.executeQuery(
+ "SELECT Name FROM "
+ + database
+ + "..SysObjects Where XType='U' ORDER BY Name");
+ while (rs.next()) {
+ tableNames.add(rs.getString(1));
+ }
+ return tableNames;
+ } finally {
+ closeResource(null, stmt, rs);
+ }
+ }
+
+ /**
+ * 这里写死查询的是 database.[dbo].table 的数据
+ *
+ * @param database 数据库名
+ * @param table 表名
+ * @return 列信息
+ * @throws SQLException
+ * @throws ClassNotFoundException
+ */
+ public List<MetaColumnInfo> getColumns(String database, String table)
+ throws SQLException, ClassNotFoundException {
+ List<MetaColumnInfo> columns = new ArrayList<>();
+ // String columnSql = "SELECT a.name FieldName, b.name [Type], a.isnullable,
+ // ISNULL(g.[value], '') AS FieldRemark FROM SysColumns a LEFT JOIN systypes b on a.xtype =
+ // b.xusertype INNER JOIN sysobjects d ON a.id = d.id AND d.xtype = 'U' AND d.name IN
+ // ('"+table+"') LEFT JOIN syscomments e ON a.cdefault = e.id LEFT JOIN
+ // sys.extended_properties g ON a.id = g.major_id AND a.colid = g.minor_id";
+ String columnSql = "SELECT * FROM " + database + ".dbo." + table + " WHERE 1 = 2";
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+ ResultSetMetaData meta;
+ try {
+ List<String> primaryKeys =
+ getPrimaryKeys(getDBConnection(connectMessage, database), table);
+ ps = conn.prepareStatement(columnSql);
+ rs = ps.executeQuery();
+ meta = rs.getMetaData();
+ int columnCount = meta.getColumnCount();
+ for (int i = 1; i < columnCount + 1; i++) {
+ MetaColumnInfo info = new MetaColumnInfo();
+ info.setIndex(i);
+ info.setName(meta.getColumnName(i));
+ info.setType(meta.getColumnTypeName(i));
+ if (primaryKeys.contains(meta.getColumnName(i))) {
+ info.setPrimaryKey(true);
+ }
+ columns.add(info);
+ }
+ } finally {
+ closeResource(null, ps, rs);
+ }
+ return columns;
+ }
+
+ /**
+ * Get primary keys
+ *
+ * @param connection connection
+ * @param table table name
+ * @return
+ * @throws SQLException
+ */
+ private List<String> getPrimaryKeys(Connection connection, String table) throws SQLException {
+ ResultSet rs = null;
+ List<String> primaryKeys = new ArrayList<>();
+ try {
+ DatabaseMetaData dbMeta = connection.getMetaData();
+ rs = dbMeta.getPrimaryKeys(null, null, table);
+ while (rs.next()) {
+ primaryKeys.add(rs.getString("column_name"));
+ }
+ return primaryKeys;
+ } finally {
+ if (null != rs) {
+ closeResource(connection, null, rs);
+ }
+ }
+ }
+
+ /**
+ * close database resource
+ *
+ * @param connection connection
+ * @param statement statement
+ * @param resultSet result set
+ */
+ private void closeResource(Connection connection, Statement statement, ResultSet resultSet) {
+ try {
+ if (null != resultSet && !resultSet.isClosed()) {
+ resultSet.close();
+ }
+ if (null != statement /*&& !statement.isClosed()*/) {
+ statement.close();
+ }
+ if (null != connection && !connection.isClosed()) {
+ connection.close();
+ }
+ } catch (SQLException e) {
+ LOG.warn("Fail to release resource [" + e.getMessage() + "]", e);
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ closeResource(conn, null, null);
+ }
+
+ /**
+ * @param connectMessage
+ * @param database
+ * @return
+ * @throws ClassNotFoundException
+ */
+ private Connection getDBConnection(ConnectMessage connectMessage, String database)
+ throws ClassNotFoundException, SQLException {
+ String extraParamString =
+ connectMessage.extraParams.entrySet().stream()
+ .map(e -> String.join("=", e.getKey(), String.valueOf(e.getValue())))
+ .collect(Collectors.joining("&"));
+ Class.forName(SQL_DRIVER_CLASS.getValue());
+ String url =
+ String.format(
+ SQL_CONNECT_URL.getValue(),
+ connectMessage.host,
+ connectMessage.port,
+ database);
+ // String url = String.format(SQL_CONNECT_URL.getValue(), connectMessage.host,
+ // database);
+ if (!connectMessage.extraParams.isEmpty()) {
+ url += "?" + extraParamString;
+ }
+ return DriverManager.getConnection(url, connectMessage.username, connectMessage.password);
+ }
+
+ /** Connect message */
+ private static class ConnectMessage {
+ private String host;
+
+ private Integer port;
+
+ private String username;
+
+ private String password;
+
+ private Map<String, Object> extraParams;
+
+ public ConnectMessage(
+ String host,
+ Integer port,
+ String username,
+ String password,
+ Map<String, Object> extraParams) {
+ this.host = host;
+ this.port = port;
+ this.username = username;
+ this.password = password;
+ this.extraParams = extraParams;
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org