You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
4.0 KiB
107 lines
4.0 KiB
import { CONSTANT_PLUGIN_TYPES } from './app.constant'; |
|
import { DATA_BASE_TYPES } from '@constants/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]+))?(\/|;DatabaseName=)?([^]+)(.*)/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|dm|impala|kylin|phoenix|derby|gbase|gbasedbt-sqli|informix-sqli|h2|postgresql|hive2|vertica|kingbase|presto|redshift|postgresql|clickhouse|trino):(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], |
|
}; |
|
} |
|
|
|
// 处理SAP HANA数据连接url |
|
const sapHanaUrl = url.match(/^jdbc:(sap):(thin:([0-9a-zA-Z/]*)?@|thin:([0-9a-zA-Z/]*)?@\/\/|\/\/|)([0-9a-zA-Z_\\.-]+)(:([0-9|port]+))?([^]+)?(.*)/i); |
|
if (sapHanaUrl) { |
|
return { |
|
host: sapHanaUrl[5], |
|
port: sapHanaUrl[7] === 'port' ? '' : sapHanaUrl[7], |
|
databaseName: '', |
|
urlInfo: sapHanaUrl[9], |
|
}; |
|
} |
|
|
|
// 处理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: '', |
|
}; |
|
} |
|
|
|
function coverBaseDatabase(config) { |
|
const baseDataBase = DATA_BASE_TYPES.find(item => item.text === config.text); |
|
if (BI.isNotNull(baseDataBase)) { |
|
// 覆盖基础配置 |
|
Object.assign(baseDataBase, config); |
|
|
|
return true; |
|
} |
|
|
|
return false; |
|
} |
|
|
|
this.registerDatabaseType = (config: any) => { |
|
if (coverBaseDatabase(config)) return; |
|
|
|
BI.config(CONSTANT_PLUGIN_TYPES, connections => BI.concat(connections, config)); |
|
}; |
|
|
|
this.registerJdbcDatabase = (config: any, resolve?: Function) => { |
|
config = { |
|
...config, |
|
type: 'jdbc', |
|
}; |
|
|
|
BI.isFunction(resolve) && (this.resolves[config.databaseType] = resolve); |
|
|
|
if (coverBaseDatabase(config)) return; |
|
|
|
BI.config(CONSTANT_PLUGIN_TYPES, connections => BI.concat(connections, config)); |
|
}; |
|
|
|
this.$get = () => BI.inherit(BI.OB, { |
|
getJdbcResolveByType: (type: string) => this.resolves[type] || jdbcResolve, |
|
customDatabaseType: BI.Constants.getConstant(CONSTANT_PLUGIN_TYPES), |
|
}); |
|
});
|
|
|