@ -211,12 +211,20 @@ public class DataSourceService extends BaseService{
String parameter = dataSource . getConnectionParams ( ) ;
String parameter = dataSource . getConnectionParams ( ) ;
BaseDataSource datasourceForm = DataSourceFactory . getDatasource ( dataSource . getType ( ) , parameter ) ;
BaseDataSource datasourceForm = DataSourceFactory . getDatasource ( dataSource . getType ( ) , parameter ) ;
DbConnectType connectType = null ;
String hostSeperator = Constants . DOUBLE_SLASH ;
if ( DbType . ORACLE . equals ( dataSource . getType ( ) ) ) {
connectType = ( ( OracleDataSource ) datasourceForm ) . getConnectType ( ) ;
if ( DbConnectType . ORACLE_SID . equals ( connectType ) ) {
hostSeperator = Constants . AT_SIGN ;
}
}
String database = datasourceForm . getDatabase ( ) ;
String database = datasourceForm . getDatabase ( ) ;
// jdbc connection params
// jdbc connection params
String other = datasourceForm . getOther ( ) ;
String other = datasourceForm . getOther ( ) ;
String address = datasourceForm . getAddress ( ) ;
String address = datasourceForm . getAddress ( ) ;
String [ ] hostsPorts = getHostsAndPort ( address ) ;
String [ ] hostsPorts = getHostsAndPort ( address , hostSeperator ) ;
// ip host
// ip host
String host = hostsPorts [ 0 ] ;
String host = hostsPorts [ 0 ] ;
// prot
// prot
@ -252,6 +260,10 @@ public class DataSourceService extends BaseService{
map . put ( NAME , dataSourceName ) ;
map . put ( NAME , dataSourceName ) ;
map . put ( NOTE , desc ) ;
map . put ( NOTE , desc ) ;
map . put ( TYPE , dataSourceType ) ;
map . put ( TYPE , dataSourceType ) ;
if ( connectType ! = null ) {
map . put ( Constants . ORACLE_DB_CONNECT_TYPE , connectType ) ;
}
map . put ( HOST , host ) ;
map . put ( HOST , host ) ;
map . put ( PORT , port ) ;
map . put ( PORT , port ) ;
map . put ( PRINCIPAL , datasourceForm . getPrincipal ( ) ) ;
map . put ( PRINCIPAL , datasourceForm . getPrincipal ( ) ) ;
@ -478,13 +490,10 @@ public class DataSourceService extends BaseService{
String password , DbConnectType connectType , String other ) {
String password , DbConnectType connectType , String other ) {
String address = buildAddress ( type , host , port , connectType ) ;
String address = buildAddress ( type , host , port , connectType ) ;
Map < String , Object > parameterMap = new LinkedHashMap < String , Object > ( 6 ) ;
String jdbcUrl ;
String jdbcUrl = address + "/" + database ;
if ( Constants . ORACLE . equals ( type . name ( ) )
if ( Constants . ORACLE . equals ( type . name ( ) ) ) {
& & connectType = = DbConnectType . ORACLE_SID ) {
parameterMap . put ( Constants . ORACLE_DB_CONNECT_TYPE , connectType ) ;
jdbcUrl = address + ":" + database ;
} else {
jdbcUrl = address + "/" + database ;
}
}
if ( CommonUtils . getKerberosStartupState ( ) & &
if ( CommonUtils . getKerberosStartupState ( ) & &
@ -505,7 +514,6 @@ public class DataSourceService extends BaseService{
separator = ";" ;
separator = ";" ;
}
}
Map < String , Object > parameterMap = new LinkedHashMap < String , Object > ( 6 ) ;
parameterMap . put ( Constants . ADDRESS , address ) ;
parameterMap . put ( Constants . ADDRESS , address ) ;
parameterMap . put ( Constants . DATABASE , database ) ;
parameterMap . put ( Constants . DATABASE , database ) ;
parameterMap . put ( Constants . JDBC_URL , jdbcUrl ) ;
parameterMap . put ( Constants . JDBC_URL , jdbcUrl ) ;
@ -675,12 +683,23 @@ public class DataSourceService extends BaseService{
/ * *
/ * *
* get host and port by address
* get host and port by address
*
*
* @param address
* @param address address
* @return sting array : [ host , port ]
* @return sting array : [ host , port ]
* /
* /
private String [ ] getHostsAndPort ( String address ) {
private String [ ] getHostsAndPort ( String address ) {
return getHostsAndPort ( address , Constants . DOUBLE_SLASH ) ;
}
/ * *
* get host and port by address
*
* @param address address
* @param separator separator
* @return sting array : [ host , port ]
* /
private String [ ] getHostsAndPort ( String address , String separator ) {
String [ ] result = new String [ 2 ] ;
String [ ] result = new String [ 2 ] ;
String [ ] tmpArray = address . split ( Constants . DOUBLE_SLASH ) ;
String [ ] tmpArray = address . split ( separator ) ;
String hostsAndPorts = tmpArray [ tmpArray . length - 1 ] ;
String hostsAndPorts = tmpArray [ tmpArray . length - 1 ] ;
StringBuilder hosts = new StringBuilder ( ) ;
StringBuilder hosts = new StringBuilder ( ) ;
String [ ] hostPortArray = hostsAndPorts . split ( Constants . COMMA ) ;
String [ ] hostPortArray = hostsAndPorts . split ( Constants . COMMA ) ;