diff --git a/src/modules/app.provider.ts b/src/modules/app.provider.ts index 846d138..78a5cbd 100644 --- a/src/modules/app.provider.ts +++ b/src/modules/app.provider.ts @@ -11,18 +11,19 @@ BI.provider('dec.connection.provider.datebase', function () { return { host: result[1], port: result[2] === 'port' ? '' : result[2], - databaseName: result[4] || '', + catalog: result[3], + databaseName: result[4], urlInfo: result[0], }; } // 处理starRocks数据连接负载均衡模式 const loadBalance = url.match(/^jdbc:mysql:loadbalance:\/\/[^/]+\/([^/]+)\.([^/]+)/i); if (loadBalance){ - const database: string = loadBalance[2]; return { host: '', port: '', - databaseName: database, + catalog: loadBalance[1], + databaseName: loadBalance[2], urlInfo: loadBalance[0], } } diff --git a/src/modules/app.service.ts b/src/modules/app.service.ts index af79ad0..d33bb97 100644 --- a/src/modules/app.service.ts +++ b/src/modules/app.service.ts @@ -61,7 +61,7 @@ export function resolveUrlInfo(url: string, database?: string) { } // 拼接url -export function splitUrl(host: string, port: string, database: string, baseUrl: string) { +export function splitUrl(host: string, port: string, catalog: string, database: string, baseUrl: string) { if (baseUrl.startsWith('jdbc:sqlserver')) { return baseUrl.replace('hostname', host).replace(':port', port ? `:${port}` : '') .replace('=database', `=${database}`); @@ -75,6 +75,12 @@ export function splitUrl(host: string, port: string, database: string, baseUrl: .replace(':INFORMIXSERVER={server}', ''); } + if (catalog) { + return baseUrl.replace('hostname', host).replace(':port', port ? `:${port}` : '') + .replace('default_catalog', catalog) + .replace('database', database) + } + return baseUrl.replace('hostname', host).replace(':port', port ? `:${port}` : '') .replace('/database', `/${database}`) .replace(':database', `:${database}`) diff --git a/src/modules/constants/constant.ts b/src/modules/constants/constant.ts index 7b698a0..2e12817 100644 --- a/src/modules/constants/constant.ts +++ b/src/modules/constants/constant.ts @@ -722,7 +722,7 @@ export const DATA_BASE_TYPES = [ databaseType: 'starrocks', driver: 'com.mysql.jdbc.Driver', drivers: ['com.mysql.jdbc.Driver'], - url: 'jdbc:mysql://hostname:port/database', + url: 'jdbc:mysql://hostname:port/default_catalog.database', commonly: false, internal: true, type: 'jdbc', diff --git a/src/modules/pages/connection/connection_jdbc/connection_jdbc.ts b/src/modules/pages/connection/connection_jdbc/connection_jdbc.ts index 817b50d..5a7069d 100644 --- a/src/modules/pages/connection/connection_jdbc/connection_jdbc.ts +++ b/src/modules/pages/connection/connection_jdbc/connection_jdbc.ts @@ -57,7 +57,7 @@ export class ConnectionJdbc extends BI.Widget { hdfs, } = connectionData; const databaseType = getJdbcDatabaseType(database, driver); - const { host, port, databaseName, version } = resolveUrlInfo(url, database); + const { host, port, catalog, databaseName, version } = resolveUrlInfo(url, database); this.version = !BI.isUndefined(databaseType.versions) ? (version ?? databaseType.versions[0]) : version; const { hgap, vgap } = CONNECTION_LAYOUT; @@ -78,6 +78,12 @@ export class ConnectionJdbc extends BI.Widget { name: BI.i18nText('Dec-Dcm_Connection_Form_Driver'), value: BI.isKey(driverSource) ? `${driver} (${driverSource})` : driver, }, + { + type: FormItem.xtype, + name: 'catalog', + invisible: database !== 'starrocks', + value: catalog, + }, { type: FormItem.xtype, name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Name'), diff --git a/src/modules/pages/maintain/forms/components/form.jdbc.ts b/src/modules/pages/maintain/forms/components/form.jdbc.ts index a3a2dee..cb41e3a 100644 --- a/src/modules/pages/maintain/forms/components/form.jdbc.ts +++ b/src/modules/pages/maintain/forms/components/form.jdbc.ts @@ -51,6 +51,7 @@ export class FormJdbc extends BI.Widget { connectionName: null, version: null, driver: null, + catalog: null, database: null, host: null, port: null, @@ -160,7 +161,7 @@ export class FormJdbc extends BI.Widget { } = connectionPoolAttr as ConnectionPoolJDBC; const databaseType = getJdbcDatabaseType(database, driver); this.databaseType = databaseType; - const { host, port, databaseName, version } = resolveUrlInfo(url, database); + const { host, port, catalog, databaseName, version } = resolveUrlInfo(url, database); this.version = !BI.isUndefined(databaseType.versions) ? (version ?? databaseType.versions[0]) : version; const { hgap, vgap } = CONNECTION_LAYOUT; @@ -262,6 +263,33 @@ export class FormJdbc extends BI.Widget { }, ], }, + // catalog + { + type: FormItem.xtype, + name: 'catalog', + invisible: database !== 'starrocks', + forms: [ + { + type: BI.TextEditor.xtype, + $value: 'database-catalog', + width: EDITOR_WIDTH, + allowBlank: true, + watermark: 'catalog', + value: catalog, + ref: (_ref: any) => { + this.form.catalog = _ref; + }, + listeners: [ + { + eventName: BI.Editor.EVENT_CHANGE, + action: () => { + this.onHostPortChange(databaseType); + }, + }, + ], + }, + ], + }, // 数据库名称 { type: FormItem.xtype, @@ -843,6 +871,7 @@ export class FormJdbc extends BI.Widget { action: () => { const urlInfo = resolveUrlInfo(this.form.url.getValue(), database); this.form.host.setValue(urlInfo.host); + this.form.catalog.setValue(urlInfo.catalog); this.form.database.setValue(urlInfo.databaseName); this.form.port.setValue(urlInfo.port); }, @@ -1578,8 +1607,9 @@ export class FormJdbc extends BI.Widget { const selectUrl = BI.get(urls, driver.driver) || url; const host = this.form.host.getValue(); const port = this.form.port.getValue(); + const catalog = this.form.catalog.getValue(); const database = this.form.database.getValue(); - this.form.url.setValue(splitUrl(host, port, database, selectUrl)); + this.form.url.setValue(splitUrl(host, port, catalog, database, selectUrl)); } private onSshTypeChange(sshType) {