From 9b3e74d13a4895307f8a8e15a4ebbff432d750f8 Mon Sep 17 00:00:00 2001 From: alan Date: Tue, 19 Nov 2019 14:31:04 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20DEC-11030=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E9=A9=B1=E5=8A=A8=E6=97=B6=E8=A7=A3=E6=9E=90?= =?UTF-8?q?url=E7=9A=84=E9=97=AE=E9=A2=98=E5=B9=B6=E8=A1=A5=E5=85=85?= =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/__test__/app.test.ts | 31 ++++++++++++++++++- src/modules/app.service.ts | 14 +++++++-- src/modules/constants/constant.ts | 4 +-- .../maintain/forms/components/form.jdbc.ts | 19 ++++++------ 4 files changed, 54 insertions(+), 14 deletions(-) diff --git a/src/modules/__test__/app.test.ts b/src/modules/__test__/app.test.ts index 07ded52..27d080c 100644 --- a/src/modules/__test__/app.test.ts +++ b/src/modules/__test__/app.test.ts @@ -1,10 +1,18 @@ -import { connectionCanEdit, resolveUrlInfo } from '../app.service'; +import { connectionCanEdit, resolveUrlInfo, splitUrl } from '../app.service'; const connection = { connectionId: '', connectionType: '', connectionName: '', connectionData: '', }; + +/** + * test_author_alan + */ +test('DEC-11030', () => { + expect(splitUrl('localhost', '22', 'dbname', 'jdbc:pivotal:greenplum://hostname:port;dbname')).toEqual('jdbc:pivotal:greenplum://localhost:22;dbname'); +}); + /** * test_author_alan */ @@ -17,6 +25,27 @@ test('DEC-10992 数据连接名称带-', () => { }); }); +test('解析url', () => { + expect(resolveUrlInfo('jdbc:postgresql://endpoint:port/database')).toEqual({ + host: 'endpoint', + port: '', + databaseName: 'database', + urlInfo: '', + }); + expect(resolveUrlInfo('jdbc:pivotal:greenplum://hostname:port;dbname')).toEqual({ + host: 'hostname', + port: '', + databaseName: 'dbname', + urlInfo: '', + }); + expect(resolveUrlInfo('jdbc:mysql://hostname:22/database')).toEqual({ + host: 'hostname', + port: '22', + databaseName: 'database', + urlInfo: '', + }); +}); + /** * test_author_alan */ diff --git a/src/modules/app.service.ts b/src/modules/app.service.ts index c51f1d9..bcc6268 100644 --- a/src/modules/app.service.ts +++ b/src/modules/app.service.ts @@ -47,7 +47,16 @@ export function getJdbcDatabaseType(database: string, driver: string): DatabaseT export function resolveUrlInfo (url: string) { if (BI.isNull(url)) return {}; - const result = url.match(/^jdbc:(oracle|mysql|sqlserver|db2|impala|kylin|phoenix|derby|gbase|gbasedbt-sqli|informix-sqli|h2|postgresql|hive2|vertica|kingbase|presto):(thin:([0-9a-zA-Z/]*)?@|thin:([0-9a-zA-Z/]*)?@\/\/|\/\/|)([0-9a-zA-Z_\\.-]+)(:([0-9|port]+))?(:|\/|;DatabaseName=)([^]+)(.*)/i); + const greenplumUrl = url.match(/^jdbc:(pivotal:greenplum):(thin:([0-9a-zA-Z/]*)?@\/\/|\/\/|)([0-9a-zA-Z_\\.-]+)(:([0-9|port]+))?(:|\/|;)([^]+)(.*)/i); + if (greenplumUrl) { + return { + host: greenplumUrl[4], + port: greenplumUrl[6] === 'port' ? '' : greenplumUrl[6], + databaseName: greenplumUrl[8], + urlInfo: greenplumUrl[9], + }; + } + const result = url.match(/^jdbc:(oracle|mysql|sqlserver|db2|impala|kylin|phoenix|derby|gbase|gbasedbt-sqli|informix-sqli|h2|postgresql|hive2|vertica|kingbase|presto|redshift|postgresql):(thin:([0-9a-zA-Z/]*)?@|thin:([0-9a-zA-Z/]*)?@\/\/|\/\/|)([0-9a-zA-Z_\\.-]+)(:([0-9|port]+))?(:|\/|;DatabaseName=)([^]+)(.*)/i); if (result) { return { host: result[5], @@ -87,7 +96,8 @@ export function splitUrl(host: string, port: string, database: string, baseUrl: } return baseUrl.replace('hostname', host).replace(':port', port ? `:${port}` : '') - .replace('database', database); + .replace('database', database) + .replace('dbname', database); } export function connectionCanEdit(connection: Connection) { diff --git a/src/modules/constants/constant.ts b/src/modules/constants/constant.ts index 863c4f7..f63fb59 100644 --- a/src/modules/constants/constant.ts +++ b/src/modules/constants/constant.ts @@ -446,8 +446,8 @@ export const DATA_BASE_TYPES = [ hasSchema: false, kerberos: false, urls: { - 'com.mysql.jdbc.Driver': 'jdbc:mysql://localhost/dbname', - 'org.gjt.mm.mysql.Driver': 'jdbc:mysql://localhost/dbname', + 'com.mysql.jdbc.Driver': 'jdbc:mysql://hostname:port/database', + 'org.gjt.mm.mysql.Driver': 'jdbc:mysql://hostname:port/database', }, }, { diff --git a/src/modules/pages/maintain/forms/components/form.jdbc.ts b/src/modules/pages/maintain/forms/components/form.jdbc.ts index 637e1bd..a39b3c1 100644 --- a/src/modules/pages/maintain/forms/components/form.jdbc.ts +++ b/src/modules/pages/maintain/forms/components/form.jdbc.ts @@ -98,13 +98,12 @@ export class FormJdbc extends BI.Widget { const value = this.form.driver.getValue(); const connectionData = this.options.formData.connectionData as ConnectionJDBC; const connectionType = getJdbcDatabaseType(connectionData.database, connectionData.driver); - if (connectionType.urls) { - this.form.url.setValue(connectionType.urls[value]); - const urlInfo = resolveUrlInfo(connectionType.urls[value]); - this.form.host.setValue(urlInfo.host); - this.form.database.setValue(urlInfo.databaseName); - this.form.port.setValue(urlInfo.port); - } + const url = connectionType.urls ? connectionType.urls[value] : connectionType.url; + this.form.url.setValue(url); + const urlInfo = resolveUrlInfo(url); + this.form.host.setValue(urlInfo.host); + this.form.database.setValue(urlInfo.databaseName); + this.form.port.setValue(urlInfo.port); }, }], }], @@ -692,11 +691,13 @@ export class FormJdbc extends BI.Widget { } private onHostPortChange(databaseType) { - const { url = '' } = databaseType; + const { urls, url } = databaseType; + const driver = this.form.driver.getValue(); + const selectUrl = BI.get(urls, driver) || url; const host = this.form.host.getValue(); const port = this.form.port.getValue(); const database = this.form.database.getValue(); - this.form.url.setValue(splitUrl(host, port, database, url)); + this.form.url.setValue(splitUrl(host, port, database, selectUrl)); } public setSchemas(schemas: string[]) { From fe1e00b2f8af9731ab6646a17b4ed008abf61e9b Mon Sep 17 00:00:00 2001 From: alan Date: Tue, 19 Nov 2019 15:00:41 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/__test__/app.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/__test__/app.test.ts b/src/modules/__test__/app.test.ts index 27d080c..5cea84c 100644 --- a/src/modules/__test__/app.test.ts +++ b/src/modules/__test__/app.test.ts @@ -9,7 +9,7 @@ const connection = { /** * test_author_alan */ -test('DEC-11030', () => { +test('DEC-11030 拼接url', () => { expect(splitUrl('localhost', '22', 'dbname', 'jdbc:pivotal:greenplum://hostname:port;dbname')).toEqual('jdbc:pivotal:greenplum://localhost:22;dbname'); });