Browse Source

Merge pull request #844 in DEC/decision-webui-dcm from release/10.0 to bugfix/10.0

* commit '99ba02276b282322c5b08a36136e4f8d2de6c953':
  DEC-15719 feat: 数据连接直接支持jdbc插件
bugfix/10.0
superman 4 years ago
parent
commit
28c964c0f8
  1. 2
      src/modules/__test__/app.test.ts
  2. 64
      src/modules/app.provider.ts
  3. 58
      src/modules/app.service.ts
  4. 2
      src/modules/pages/connection/connection_jdbc/connection_jdbc.ts
  5. 6
      src/modules/pages/maintain/forms/components/form.jdbc.ts

2
src/modules/__test__/app.test.ts

@ -1,4 +1,6 @@
import { connectionCanEdit, resolveUrlInfo, splitUrl, getJdbcDatabaseType } from '../app.service';
import '../app.provider';
const connection = {
connectionId: '',
connectionType: '',

64
src/modules/app.provider.ts

@ -1,9 +1,73 @@
import { CONSTANT_PLUGIN_TYPES } from './app.constant';
BI.provider('dec.connection.provider.datebase', function() {
this.resolves = {};
// 原service中resolveUrlInfo方法
function jdbcResolve (url: string) {
if (BI.isNull(url)) return {};
const oracleUlr = url.match(/^jdbc:(oracle):(thin:([0-9a-zA-Z/]*)?@|thin:([0-9a-zA-Z/]*)?@\/\/|\/\/|)([0-9a-zA-Z_\\.-]+)(:([0-9|port]+))?(:|\/)([^]+)(.*)/i);
if (oracleUlr) {
return {
host: oracleUlr[5],
port: oracleUlr[7] === 'port' ? '' : oracleUlr[7],
databaseName: oracleUlr[9],
urlInfo: oracleUlr[10],
};
}
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:(mysql|sqlserver|db2|impala|kylin|phoenix|derby|gbase|gbasedbt-sqli|informix-sqli|h2|postgresql|hive2|vertica|kingbase|presto|redshift|postgresql|clickhouse):(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],
port: result[7] === '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] !== 'port' ? port[1] : '',
databaseName: databaseName ? databaseName[1] : '',
urlInfo: '',
};
}
return {
host: '',
port: '',
databaseName: '',
urlInfo: '',
};
}
this.registerDatabaseType = (config: any) => {
BI.config(CONSTANT_PLUGIN_TYPES, connections => BI.concat(connections, config));
};
this.registerJdbcDatabase = (config: any, resolve?: Function) => {
BI.config(CONSTANT_PLUGIN_TYPES, connections => BI.concat(connections, { ...config, type: 'jdbc' }));
BI.isFunction(resolve) && (this.resolves[config.databaseType] = resolve);
};
this.$get = () => BI.inherit(BI.OB, {
getJdbcResolveByType: (type: string) => this.resolves[type] || jdbcResolve,
});
});

58
src/modules/app.service.ts

@ -31,14 +31,16 @@ export function getJdbcDatabaseType(database: string, driver: string): DatabaseT
return DATA_BASE_TYPES_OTHER;
}
let databaseType = null;
// KERNEL-1655 兼容旧版 由于旧版设计器创建的数据连接database都为other,所以要根据driber来判断数据类型
if (database && database !== 'other' && DATA_BASE_TYPES.some(item => item.databaseType === database)) {
databaseType = DATA_BASE_TYPES.find(item => item.databaseType === database);
// 从全部数据库类型中获取jdbc类型的
const jdbcDatabases = getAllDatabaseTypes().filter(v => v.type === 'jdbc');
// KERNEL-1655 兼容旧版 由于旧版设计器创建的数据连接database都为other,所以要根据driver来判断数据类型
if (database && database !== 'other' && jdbcDatabases.some(item => item.databaseType === database)) {
databaseType = jdbcDatabases.find(item => item.databaseType === database);
} else {
const designDatabase = DESIGN_DRIVER_TYPE.find(item => item.driver === driver);
const decisionDatabase = DATA_BASE_TYPES.find(item => item.driver === driver);
const decisionDatabase = jdbcDatabases.find(item => item.driver === driver);
const type = designDatabase ? BI.get(designDatabase, 'type') : BI.get(decisionDatabase, 'databaseType');
databaseType = DATA_BASE_TYPES.find(item => item.databaseType === type);
databaseType = jdbcDatabases.find(item => item.databaseType === type);
}
if (!databaseType) {
return DATA_BASE_TYPES_OTHER;
@ -47,52 +49,10 @@ export function getJdbcDatabaseType(database: string, driver: string): DatabaseT
return databaseType;
}
export function resolveUrlInfo (url: string) {
export function resolveUrlInfo (url: string, database?: string) {
if (BI.isNull(url)) return {};
const oracleUlr = url.match(/^jdbc:(oracle):(thin:([0-9a-zA-Z/]*)?@|thin:([0-9a-zA-Z/]*)?@\/\/|\/\/|)([0-9a-zA-Z_\\.-]+)(:([0-9|port]+))?(:|\/)([^]+)(.*)/i);
if (oracleUlr) {
return {
host: oracleUlr[5],
port: oracleUlr[7] === 'port' ? '' : oracleUlr[7],
databaseName: oracleUlr[9],
urlInfo: oracleUlr[10],
};
}
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:(mysql|sqlserver|db2|impala|kylin|phoenix|derby|gbase|gbasedbt-sqli|informix-sqli|h2|postgresql|hive2|vertica|kingbase|presto|redshift|postgresql|clickhouse):(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],
port: result[7] === '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] !== 'port' ? port[1] : '',
databaseName: databaseName ? databaseName[1] : '',
urlInfo: '',
};
}
return {
return BI.Providers.getProvider('dec.connection.provider.datebase').getJdbcResolveByType(database)(url) || {
host: '',
port: '',
databaseName: '',

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

@ -19,7 +19,7 @@ export class ConnectionJdbc extends BI.Widget {
const connectionData = this.model.connectionSelectedOne.connectionData as ConnectionJDBC;
const { driver, database, user, originalCharsetName, schema, connectionPoolAttr, authType, principal, url } = connectionData;
const databaseType = getJdbcDatabaseType(database, driver);
const { host, port, databaseName } = resolveUrlInfo(url);
const { host, port, databaseName } = resolveUrlInfo(url, database);
const { hgap, vgap } = CONNECTION_LAYOUT;
return {

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

@ -62,7 +62,7 @@ export class FormJdbc extends BI.Widget {
const { initialSize, maxActive, maxIdle, maxWait, validationQuery, testOnBorrow, testOnReturn, testWhileIdle, timeBetweenEvictionRunsMillis, numTestsPerEvictionRun, minIdle, minEvictableIdleTimeMillis } = connectionPoolAttr as ConnectionPoolJDBC;
const databaseType = getJdbcDatabaseType(database, driver);
this.oldPassword = password;
const { host, port, databaseName } = resolveUrlInfo(url);
const { host, port, databaseName } = resolveUrlInfo(url, database);
const { hgap, vgap } = CONNECTION_LAYOUT;
const valueRangeConfig = {
@ -112,7 +112,7 @@ export class FormJdbc extends BI.Widget {
const connectionType = getJdbcDatabaseType(connectionData.database, connectionData.driver);
const url = connectionType.urls ? connectionType.urls[value] : connectionType.url;
this.form.url.setValue(url);
const urlInfo = resolveUrlInfo(url);
const urlInfo = resolveUrlInfo(url, connectionData.database);
this.form.host.setValue(urlInfo.host);
this.form.database.setValue(urlInfo.databaseName);
this.form.port.setValue(urlInfo.port);
@ -387,7 +387,7 @@ export class FormJdbc extends BI.Widget {
listeners: [{
eventName: 'EVENT_CHANGE',
action: () => {
const urlInfo = resolveUrlInfo(this.form.url.getValue());
const urlInfo = resolveUrlInfo(this.form.url.getValue(), database);
this.form.host.setValue(urlInfo.host);
this.form.database.setValue(urlInfo.databaseName);
this.form.port.setValue(urlInfo.port);

Loading…
Cancel
Save