Browse Source

feat: DEC-9068 url拼接与解析

qufenxi
alan 5 years ago
parent
commit
b7aa4d5b45
  1. 34
      src/modules/app.service.ts
  2. 1
      src/modules/components/test_status/test_status.ts
  3. 56
      src/modules/constants/constant.ts
  4. 9
      src/modules/pages/connection/connection_jdbc/connection_jdbc.ts
  5. 23
      src/modules/pages/maintain/forms/components/form.jdbc.ts

34
src/modules/app.service.ts

@ -42,3 +42,37 @@ export function getJdbcDatabaseType(database: string, driver: string): DatabaseT
return databaseType;
}
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]+))?(:|\/|;DatabaseName=)([0-9a-zA-Z_\\.]+)(.*)/i);
if (result) {
return {
host: result[5],
port: result[7],
databaseName: result[9],
urlInfo: result[10],
};
}
// 处理oracle的RAC方式
if (/^jdbc:oracle:thin:([0-9a-zA-Z/]*)?@\(DESCRIPTION/i.test(url)) {
const host = url.match(/\(HOST\s*=\s*([0-9a-zA-Z_\\.-]+)\)/i);
const port = url.match(/\(PORT\s*=\s*([0-9]+)\)/i);
const databaseName = url.match(/\(SERVICE_NAME\s*=\s*([\s0-9a-zA-Z_\\.]+)\)/i);
return {
host: host ? host[1] : '',
port: port ? port[1] : '',
databaseName: databaseName ? databaseName[1] : '',
urlInfo: '',
};
}
return {
host: '',
port: '',
databaseName: '',
urlInfo: '',
};
}

1
src/modules/components/test_status/test_status.ts

@ -86,6 +86,7 @@ export class TestStatus extends BI.Widget {
{
eventName: EVENT_DETAIL,
action: (isCollapse: boolean) => {
this.tab.setHeight(isCollapse ? 250 : 200);
this.detail.setVisible(!isCollapse);
},
},

56
src/modules/constants/constant.ts

@ -33,7 +33,7 @@ export const DATA_BASE_TYPES = [
text: 'ADS',
databaseType: 'ads',
driver: 'com.mysql.jdbc.Driver',
url: 'jdbc:mysql://hostname:port/my_ads_db',
url: 'jdbc:mysql://hostname:port/database',
commonly: false,
internal: true,
type: 'jdbc',
@ -56,7 +56,7 @@ export const DATA_BASE_TYPES = [
text: 'APACHE IMPALA',
databaseType: 'apache-impala',
driver: 'com.cloudera.impala.jdbc41.Driver',
url: 'jdbc:impala://hostname:port/_impala_builtins',
url: 'jdbc:impala://hostname:port/database',
commonly: false,
internal: true,
type: 'jdbc',
@ -67,7 +67,7 @@ export const DATA_BASE_TYPES = [
text: 'APACHE KYLIN',
databaseType: 'apache-kylin',
driver: 'org.apache.kylin.jdbc.Driver',
url: 'jdbc:kylin://hostname:port/<kylin_project_name>',
url: 'jdbc:kylin://hostname:port/database',
commonly: false,
internal: true,
type: 'jdbc',
@ -78,7 +78,7 @@ export const DATA_BASE_TYPES = [
text: 'APACHE Phoenix',
databaseType: 'apache-phoenix',
driver: 'org.apache.phoenix.jdbc.PhoenixDriver',
url: 'jdbc:phoenix:hostname:port/dbname',
url: 'jdbc:phoenix:hostname:port/database',
commonly: false,
internal: true,
type: 'jdbc',
@ -89,7 +89,7 @@ export const DATA_BASE_TYPES = [
text: 'DERBY',
databaseType: 'derby',
driver: 'org.apache.derby.jdbc.ClientDriver',
url: 'jdbc:derby://hostname:port/',
url: 'jdbc:derby://hostname:port/database',
commonly: false,
internal: true,
type: 'jdbc',
@ -100,7 +100,7 @@ export const DATA_BASE_TYPES = [
text: 'Gbase 8A',
databaseType: 'gbase-8a',
driver: 'com.gbase.jdbc.Driver',
url: 'jdbc:gbase://hostname:port/dbname',
url: 'jdbc:gbase://hostname:port/database',
commonly: false,
internal: true,
type: 'jdbc',
@ -111,7 +111,7 @@ export const DATA_BASE_TYPES = [
text: 'Gbase 8S',
databaseType: 'gbase-8s',
driver: 'com.gbasedbt.jdbc.IfxDriver',
url: 'jdbc:gbasedbt-sqli://hostname:port/{database}',
url: 'jdbc:gbasedbt-sqli://hostname:port/database',
commonly: false,
internal: true,
type: 'jdbc',
@ -122,7 +122,7 @@ export const DATA_BASE_TYPES = [
text: 'Gbase 8T',
databaseType: 'gbase-8t',
driver: 'com.informix.jdbc.IfxDriver',
url: 'jdbc:informix-sqli://hostname:port/{database}:INFORMIXSERVER={server}',
url: 'jdbc:informix-sqli://hostname:port/database:INFORMIXSERVER={server}',
commonly: false,
internal: true,
type: 'jdbc',
@ -133,7 +133,7 @@ export const DATA_BASE_TYPES = [
text: 'H2',
databaseType: 'h2',
driver: 'org.h2.Driver',
url: 'jdbc:h2://${ENV_HOME}/../databaseName',
url: 'jdbc:h2://hostname:port/../database',
commonly: false,
internal: true,
type: 'jdbc',
@ -144,7 +144,7 @@ export const DATA_BASE_TYPES = [
text: '华为云DWS',
databaseType: 'hw-dws',
driver: 'org.postgresql.Driver',
url: 'jdbc:postgresql://hostname:port/dbname',
url: 'jdbc:postgresql://hostname:port/database',
commonly: false,
internal: true,
type: 'jdbc',
@ -155,7 +155,7 @@ export const DATA_BASE_TYPES = [
text: 'FusionInsight elk',
databaseType: 'hw-elk',
driver: 'org.postgresql.Driver',
url: 'jdbc:postgresql://hostname:port/dbname',
url: 'jdbc:postgresql://hostname:port/database',
commonly: false,
internal: true,
type: 'jdbc',
@ -177,7 +177,7 @@ export const DATA_BASE_TYPES = [
text: 'GaussDB 200',
databaseType: 'hw-libr-a',
driver: 'org.postgresql.Driver',
url: 'jdbc:postgresql://hostname:port/dbname',
url: 'jdbc:postgresql://hostname:port/database',
commonly: false,
internal: true,
type: 'jdbc',
@ -187,7 +187,7 @@ export const DATA_BASE_TYPES = [
text: 'Hadoop Hive',
databaseType: 'hadoop-hive',
driver: 'org.apache.hive.jdbc.HiveDriver',
url: 'jdbc:hive2://hostname:port/databasename',
url: 'jdbc:hive2://hostname:port/database',
commonly: false,
internal: true,
type: 'jdbc',
@ -197,7 +197,7 @@ export const DATA_BASE_TYPES = [
text: 'Hbase',
databaseType: 'hbase',
driver: 'org.apache.phoenix.jdbc.PhoenixDriver',
url: 'jdbc:phoenix:hostname:port/dbname',
url: 'jdbc:phoenix:hostname:port/database',
commonly: false,
internal: true,
type: 'jdbc',
@ -207,7 +207,7 @@ export const DATA_BASE_TYPES = [
text: 'HP Vertica',
databaseType: 'hp-vertica',
driver: 'com.vertica.jdbc.Driver',
url: 'jdbc:vertica://hostname:port/databaseName',
url: 'jdbc:vertica://hostname:port/database',
commonly: false,
internal: true,
type: 'jdbc',
@ -227,7 +227,7 @@ export const DATA_BASE_TYPES = [
text: 'IBM DB2',
databaseType: 'ibm-db2',
driver: 'com.ibm.db2.jcc.DB2Driver',
url: 'jdbc:db2://hostname:port/dbname',
url: 'jdbc:db2://hostname:port/database',
commonly: true,
internal: true,
type: 'jdbc',
@ -237,7 +237,7 @@ export const DATA_BASE_TYPES = [
text: 'INFORMIX',
databaseType: 'informix',
driver: 'com.informix.jdbc.IfxDriver',
url: 'jdbc:informix-sqli://hostname:port/{database}:INFORMIXSERVER={server}',
url: 'jdbc:informix-sqli://hostname:port/database:INFORMIXSERVER={server}',
commonly: false,
internal: true,
type: 'jdbc',
@ -247,7 +247,7 @@ export const DATA_BASE_TYPES = [
text: 'KINGBASE',
databaseType: 'kingbase',
driver: 'com.kingbase.Driver',
url: 'jdbc:kingbase://hostname:port',
url: 'jdbc:kingbase://hostname:port/database',
commonly: false,
internal: true,
type: 'jdbc',
@ -257,7 +257,7 @@ export const DATA_BASE_TYPES = [
text: 'Microsoft SQL Server',
databaseType: 'sql-server',
driver: 'com.microsoft.sqlserver.jdbc.SQLServerDriver',
url: 'jdbc:sqlserver://hostname:port;databaseName=',
url: 'jdbc:sqlserver://hostname:port;databaseName=database',
commonly: true,
internal: true,
type: 'jdbc',
@ -268,7 +268,7 @@ export const DATA_BASE_TYPES = [
databaseType: 'mysql',
driver: 'com.mysql.jdbc.Driver',
drivers: ['com.mysql.jdbc.Driver', 'org.gjt.mm.mysql.Driver'],
url: 'jdbc:mysql://hostname:port/dbname',
url: 'jdbc:mysql://hostname:port/database',
commonly: true,
internal: true,
type: 'jdbc',
@ -279,7 +279,7 @@ export const DATA_BASE_TYPES = [
text: 'Oracle',
databaseType: 'oracle',
driver: 'oracle.jdbc.driver.OracleDriver',
url: 'jdbc:oracle:thin:@hostname:port:databaseName',
url: 'jdbc:oracle:thin:@hostname:port:database',
commonly: true,
internal: true,
type: 'jdbc',
@ -290,7 +290,7 @@ export const DATA_BASE_TYPES = [
text: 'Pivotal Greenplum Database',
databaseType: 'pivotal-greenplum-database',
driver: 'org.postgresql.Driver',
url: 'jdbc:postgresql://hostname:port/dbname',
url: 'jdbc:postgresql://hostname:port/database',
commonly: false,
internal: true,
type: 'jdbc',
@ -300,7 +300,7 @@ export const DATA_BASE_TYPES = [
text: 'Postgresql',
databaseType: 'postgresql',
driver: 'org.postgresql.Driver',
url: 'jdbc:postgresql://hostname:port/dbname',
url: 'jdbc:postgresql://hostname:port/database',
commonly: false,
internal: true,
type: 'jdbc',
@ -310,7 +310,7 @@ export const DATA_BASE_TYPES = [
text: 'Presto',
databaseType: 'presto',
driver: 'com.facebook.presto.jdbc.PrestoDriver',
url: 'jdbc:presto://hostname:port/catalog',
url: 'jdbc:presto://hostname:port/database',
commonly: false,
internal: true,
type: 'jdbc',
@ -330,7 +330,7 @@ export const DATA_BASE_TYPES = [
text: 'SAP Sybase',
databaseType: 'sap-sybase',
driver: 'com.sybase.jdbc4.jdbc.SybDriver',
url: 'jdbc:sybase:Tds:hostname:port/databasename',
url: 'jdbc:sybase:Tds:hostname:port/database',
commonly: false,
internal: true,
type: 'jdbc',
@ -340,7 +340,7 @@ export const DATA_BASE_TYPES = [
text: 'SPARK',
databaseType: 'spark',
driver: 'org.apache.hive.jdbc.HiveDriver',
url: 'jdbc:hive2://hostname:port/databasename',
url: 'jdbc:hive2://hostname:port/database',
commonly: false,
internal: true,
type: 'jdbc',
@ -370,7 +370,7 @@ export const DATA_BASE_TYPES = [
text: 'TRANSWARP INCEPTOR',
databaseType: 'transwarp-inceptor',
driver: 'org.apache.hive.jdbc.HiveDriver',
url: 'jdbc:hive2://hostname:port/databasename',
url: 'jdbc:hive2://hostname:port/database',
commonly: false,
internal: true,
type: 'jdbc',
@ -392,7 +392,7 @@ export const DATA_BASE_TYPES = [
databaseType: 'other',
driver: 'org.ha.Driver',
drivers: ['org.ha.Driver', 'com.fr.third.org.hsqldb.jdbcDriver', 'org.sqlite.JDBC'],
url: 'jdbc:h2://hostname:port/../databaseName',
url: 'jdbc:h2://hostname:port/../database',
commonly: false,
internal: false,
type: 'jdbc',

9
src/modules/pages/connection/connection_jdbc/connection_jdbc.ts

@ -4,7 +4,7 @@ import { FormItemXtype } from '../components/form_item/form_item';
import { CollapseXtype, EVENT_CHANGE } from 'src/modules/components/collapse/collapse';
import { ConnectionJdbcModelXtype, ConnectionJdecModel } from './connection_jdbc.model';
import { ConnectionJDBC } from 'src/modules/crud/crud.typings';
import { getAllDatabaseTypes, getJdbcDatabaseType } from '../../../app.service';
import { getAllDatabaseTypes, getJdbcDatabaseType, resolveUrlInfo } from '../../../app.service';
export const ConnectionJdbcXtype = 'dec.dcm.connection_jdbc';
@shortcut(ConnectionJdbcXtype)
@store(ConnectionJdbcModelXtype)
@ -16,8 +16,9 @@ export class ConnectionJdbc extends BI.Widget {
render () {
const connectionData = this.model.connectionSelectedOne.connectionData as ConnectionJDBC;
const { driver, database, host, user, newCharsetName, schema, connectionPoolAttr, port, authType, principal, keyPath, url } = connectionData;
const { driver, database, user, newCharsetName, schema, connectionPoolAttr, authType, principal, keyPath, url } = connectionData;
const databaseType = getJdbcDatabaseType(database, driver);
const { host, port, databaseName } = resolveUrlInfo(url);
return {
type: Vertical,
@ -32,7 +33,7 @@ export class ConnectionJdbc extends BI.Widget {
{
type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Name'),
value: '', // TODO: 数据库名称待适配,
value: databaseName,
},
{
type: FormItemXtype,
@ -42,7 +43,7 @@ export class ConnectionJdbc extends BI.Widget {
{
type: FormItemXtype,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Port'),
value: port === 0 ? '' : port,
value: port,
},
{
type: FormItemXtype,

23
src/modules/pages/maintain/forms/components/form.jdbc.ts

@ -5,7 +5,7 @@ import { FormItemXtype } from '../../components/form_item/form_item';
import { Connection, ConnectionJDBC, ConnectionPoolJDBC } from 'src/modules/crud/crud.typings';
import { connectionType } from '@constants/env';
import { CONNECT_CHARSET } from '@constants/constant';
import { getAllDatabaseTypes, getJdbcDatabaseType } from '../../../../app.service';
import { getAllDatabaseTypes, getJdbcDatabaseType, resolveUrlInfo } from '../../../../app.service';
export const FormJdbcXtype = 'dec.dcm.maintain.form.jdbc';
@shortcut(FormJdbcXtype)
@ -56,11 +56,13 @@ export class FormJdbc extends BI.Widget {
render() {
const { connectionName, connectionData } = this.options.formData;
const { driver, host, port, user, password, newCharsetName, schema, url, connectionPoolAttr, database, authType, principal, keyPath } = connectionData as ConnectionJDBC;
const { driver, user, password, newCharsetName, schema, url, connectionPoolAttr, database, authType, principal, keyPath } = connectionData as ConnectionJDBC;
// minIdle 暂未使用
const { initialSize, maxActive, maxIdle, maxWait, validationQuery, testOnBorrow, testOnReturn, testWhileIdle, timeBetweenEvictionRunsMillis, numTestsPerEvictionRun, minEvictableIdleTimeMillis } = connectionPoolAttr as ConnectionPoolJDBC;
const databaseType = getJdbcDatabaseType(database, driver);
this.oldPassword = password;
const { host, port, databaseName } = resolveUrlInfo(url);
return {
type: Vertical,
@ -115,11 +117,16 @@ export class FormJdbc extends BI.Widget {
width: 300,
allowBlank: true,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Name'),
value: '', // TODO: 数据库名称待适配
disabled: true,
value: databaseName,
ref: (_ref: any) => {
this.form.database = _ref;
},
listeners: [{
eventName: BI.Editor.EVENT_CHANGE,
action: () => {
this.onHostPortChange(databaseType);
},
}],
}],
},
{
@ -131,7 +138,6 @@ export class FormJdbc extends BI.Widget {
allowBlank: true,
value: host,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Host'),
disabled: true,
ref: (_ref: any) => {
this.form.host = _ref;
},
@ -150,9 +156,8 @@ export class FormJdbc extends BI.Widget {
type: TextEditor,
width: 300,
allowBlank: true,
value: port === 0 ? '' : port,
value: port,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Port'),
disabled: true,
ref: (_ref: any) => {
this.form.port = _ref;
},
@ -619,7 +624,9 @@ export class FormJdbc extends BI.Widget {
const { url = '' } = databaseType;
const host = this.form.host.getValue();
const port = this.form.port.getValue();
this.form.url.setValue(url.replace('hostname', host).replace(':port', port ? `:${port}` : ''));
const database = this.form.database.getValue();
this.form.url.setValue(url.replace('hostname', host).replace(':port', port ? `:${port}` : '')
.replace('database', database));
}
public setSchemas(schemas: string[]) {

Loading…
Cancel
Save