Browse Source

Merge pull request #2 in ~ABBY/decision-webui-dcm from release/10.0 to final/10.0

* commit '5b4a3493a87593d945dad91107950435d653c99c':
  fix: 更新注释
  fix: 移除不必要的修改
  fix: BI-56355 如果数据库类型和驱动都为空,则认为是其他jdbc
  fix: DEC-11219 调整布局
  fix: DEC-11216 jdbc默认最小空闲值为0
  fix: 更新单元测试名称
  fix: DEC-11030 修复切换驱动时解析url的问题并补充单元测试
  fix: DEC-10992 修复数据库名包含特殊符号的问题
final/10.0
Abby 5 years ago
parent
commit
79e4ee0c3e
  1. 53
      src/modules/__test__/app.test.ts
  2. 18
      src/modules/app.service.ts
  3. 5
      src/modules/constants/constant.ts
  4. 21
      src/modules/pages/maintain/forms/components/form.jdbc.ts

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

@ -1,4 +1,4 @@
import { connectionCanEdit } from '../app.service'; import { connectionCanEdit, resolveUrlInfo, splitUrl, getJdbcDatabaseType } from '../app.service';
const connection = { const connection = {
connectionId: '', connectionId: '',
connectionType: '', connectionType: '',
@ -6,6 +6,57 @@ const connection = {
connectionData: '', connectionData: '',
}; };
/**
* test_author_alan
*/
test('DEC-11030 拼接url', () => {
expect(splitUrl('localhost', '22', 'dbname', 'jdbc:pivotal:greenplum://hostname:port;dbname')).toEqual('jdbc:pivotal:greenplum://localhost:22;dbname');
});
/**
* test_author_alan
*/
test('BI-56355 如果数据库类型和驱动都为空,则为其他jdbc', () => {
expect(getJdbcDatabaseType('', '').databaseType).toEqual('otherJDBC');
expect(getJdbcDatabaseType('mysql', '').databaseType).toEqual('mysql');
expect(getJdbcDatabaseType('', 'com.mysql.jdbc.Driver').databaseType).toEqual('mysql');
});
/**
* test_author_alan
*/
test('DEC-10992 数据连接名称带-', () => {
expect(resolveUrlInfo('jdbc:sqlserver://192.168.17.111:1433;databaseName=L-Pick-DAS-MengYan')).toEqual({
host: '192.168.17.111',
port: '1433',
databaseName: 'L-Pick-DAS-MengYan',
urlInfo: '',
});
});
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
*/
test('BI-51537 判断数据连接是否有权限', () => { test('BI-51537 判断数据连接是否有权限', () => {
expect(connectionCanEdit({ expect(connectionCanEdit({
...connection, ...connection,

18
src/modules/app.service.ts

@ -27,9 +27,11 @@ export function getPluginWidgetEdit(plugin: string) {
// 由于database可能为空,所以为了兼容平台和设计器,需要根据driver来判断数据库类型 // 由于database可能为空,所以为了兼容平台和设计器,需要根据driver来判断数据库类型
export function getJdbcDatabaseType(database: string, driver: string): DatabaseType { export function getJdbcDatabaseType(database: string, driver: string): DatabaseType {
if (!database && !driver) {
return DATA_BASE_TYPES_OTHER;
}
let databaseType = null; let databaseType = null;
// KERNEL-1655 兼容旧版 由于旧版设计器创建的数据连接database都为other,所以要根据driber来判断数据类型 // KERNEL-1655 兼容旧版 由于旧版设计器创建的数据连接database都为other,所以要根据driber来判断数据类型
// DEC-10872 不能过滤other,因为新版数据连接创建的其他jdbc也是other类型,会混淆,需要和后端讨论一个最佳的解决方案。
if (database && database !== 'other' && DATA_BASE_TYPES.some(item => item.databaseType === database)) { if (database && database !== 'other' && DATA_BASE_TYPES.some(item => item.databaseType === database)) {
databaseType = DATA_BASE_TYPES.find(item => item.databaseType === database); databaseType = DATA_BASE_TYPES.find(item => item.databaseType === database);
} else { } else {
@ -47,7 +49,16 @@ export function getJdbcDatabaseType(database: string, driver: string): DatabaseT
export function resolveUrlInfo (url: string) { export function resolveUrlInfo (url: string) {
if (BI.isNull(url)) return {}; 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=)([0-9a-zA-Z_\\.]+)(.*)/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) { if (result) {
return { return {
host: result[5], host: result[5],
@ -87,7 +98,8 @@ export function splitUrl(host: string, port: string, database: string, baseUrl:
} }
return baseUrl.replace('hostname', host).replace(':port', port ? `:${port}` : '') return baseUrl.replace('hostname', host).replace(':port', port ? `:${port}` : '')
.replace('database', database); .replace('database', database)
.replace('dbname', database);
} }
export function connectionCanEdit(connection: Connection) { export function connectionCanEdit(connection: Connection) {

5
src/modules/constants/constant.ts

@ -446,8 +446,8 @@ export const DATA_BASE_TYPES = [
hasSchema: false, hasSchema: false,
kerberos: false, kerberos: false,
urls: { urls: {
'com.mysql.jdbc.Driver': 'jdbc:mysql://localhost/dbname', 'com.mysql.jdbc.Driver': 'jdbc:mysql://hostname:port/database',
'org.gjt.mm.mysql.Driver': 'jdbc:mysql://localhost/dbname', 'org.gjt.mm.mysql.Driver': 'jdbc:mysql://hostname:port/database',
}, },
}, },
{ {
@ -667,6 +667,7 @@ export const DEFAULT_JDBC_POOL = {
initialSize: 0, initialSize: 0,
maxActive: 50, maxActive: 50,
maxIdle: 10, maxIdle: 10,
minIdle: 0,
maxWait: 10000, maxWait: 10000,
testOnBorrow: true, testOnBorrow: true,
testOnReturn: false, testOnReturn: false,

21
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 value = this.form.driver.getValue();
const connectionData = this.options.formData.connectionData as ConnectionJDBC; const connectionData = this.options.formData.connectionData as ConnectionJDBC;
const connectionType = getJdbcDatabaseType(connectionData.database, connectionData.driver); const connectionType = getJdbcDatabaseType(connectionData.database, connectionData.driver);
if (connectionType.urls) { const url = connectionType.urls ? connectionType.urls[value] : connectionType.url;
this.form.url.setValue(connectionType.urls[value]); this.form.url.setValue(url);
const urlInfo = resolveUrlInfo(connectionType.urls[value]); const urlInfo = resolveUrlInfo(url);
this.form.host.setValue(urlInfo.host); this.form.host.setValue(urlInfo.host);
this.form.database.setValue(urlInfo.databaseName); this.form.database.setValue(urlInfo.databaseName);
this.form.port.setValue(urlInfo.port); this.form.port.setValue(urlInfo.port);
}
}, },
}], }],
}], }],
@ -375,6 +374,7 @@ export class FormJdbc extends BI.Widget {
}, },
{ {
type: CollapseXtype, type: CollapseXtype,
bgap: -15,
width: 70, width: 70,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Advanced_Setting'), name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Advanced_Setting'),
listeners: [ listeners: [
@ -397,6 +397,7 @@ export class FormJdbc extends BI.Widget {
items: [ items: [
{ {
type: FormItemXtype, type: FormItemXtype,
tgap: 15,
name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Initial_Size'), name: BI.i18nText('Dec-Dcm_Connection_Form_Database_Initial_Size'),
forms: [{ forms: [{
type: TextCheckerXtype, type: TextCheckerXtype,
@ -692,11 +693,13 @@ export class FormJdbc extends BI.Widget {
} }
private onHostPortChange(databaseType) { 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 host = this.form.host.getValue();
const port = this.form.port.getValue(); const port = this.form.port.getValue();
const database = this.form.database.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[]) { public setSchemas(schemas: string[]) {

Loading…
Cancel
Save