|
|
|
import { DATA_BASE_TYPES, DATA_BASE_TYPES_OTHER, DESIGN_DRIVER_TYPE } from '@constants/constant';
|
|
|
|
import { CONSTANT_PLUGIN_TYPES } from './app.constant';
|
|
|
|
import { DatabaseType } from './app.typings';
|
|
|
|
import { Connection } from './crud/crud.typings';
|
|
|
|
export function getAllDatabaseTypes():DatabaseType[] {
|
|
|
|
return [
|
|
|
|
...DATA_BASE_TYPES,
|
|
|
|
...BI.Constants.getConstant(CONSTANT_PLUGIN_TYPES).map(item => {
|
|
|
|
return {
|
|
|
|
...item,
|
|
|
|
internal: false,
|
|
|
|
commonly: false,
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
function getPlugin(type: string) {
|
|
|
|
return BI.Constants.getConstant(CONSTANT_PLUGIN_TYPES).find(item => item.databaseType === type);
|
|
|
|
}
|
|
|
|
export function getPluginWidgetShow(plugin: string) {
|
|
|
|
return BI.get(getPlugin(plugin), 'show');
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getPluginWidgetEdit(plugin: string) {
|
|
|
|
return BI.get(getPlugin(plugin), 'edit');
|
|
|
|
}
|
|
|
|
|
|
|
|
// 由于database可能为空,所以为了兼容平台和设计器,需要根据driver来判断数据库类型
|
|
|
|
export function getJdbcDatabaseType(database: string, driver: string): DatabaseType {
|
|
|
|
if (!database && !driver) {
|
|
|
|
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);
|
|
|
|
} else {
|
|
|
|
const designDatabase = DESIGN_DRIVER_TYPE.find(item => item.driver === driver);
|
|
|
|
const decisionDatabase = DATA_BASE_TYPES.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);
|
|
|
|
}
|
|
|
|
if (!databaseType) {
|
|
|
|
return DATA_BASE_TYPES_OTHER;
|
|
|
|
}
|
|
|
|
|
|
|
|
return databaseType;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function resolveUrlInfo (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: '',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// 拼接url
|
|
|
|
export function splitUrl(host: string, port: string, database: string, baseUrl: string) {
|
|
|
|
if (baseUrl.startsWith('jdbc:sqlserver')) {
|
|
|
|
return baseUrl.replace('hostname', host).replace(':port', port ? `:${port}` : '')
|
|
|
|
.replace('=database', `=${database}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
return baseUrl.replace('hostname', host).replace(':port', port ? `:${port}` : '')
|
|
|
|
.replace('database', database)
|
|
|
|
.replace('dbname', database);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function connectionCanEdit(connection: Connection) {
|
|
|
|
if (connection && connection.privilegeDetailBeanList) {
|
|
|
|
// privilegeType === 4 代表编辑权限,privilegeValue === 2 代表有权限
|
|
|
|
return connection.privilegeDetailBeanList.some(item => item.privilegeType === 4 && item.privilegeValue === 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getTextByDatabaseType(databaseType: string) {
|
|
|
|
const database = getAllDatabaseTypes().find(item => item.databaseType === databaseType);
|
|
|
|
|
|
|
|
return database ? database.text : '';
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getChartLength(str: string) {
|
|
|
|
return str.replace(/[^\x00-\xff]/g, '01').length;
|
|
|
|
}
|