2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2016 - 2017 ONAP
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.ccsdk.sli.core.dblib.factory;
24 import java.util.ArrayList;
25 import java.util.Iterator;
26 import java.util.Properties;
28 import org.onap.ccsdk.sli.core.dblib.config.BaseDBConfiguration;
29 import org.onap.ccsdk.sli.core.dblib.config.DbConfigPool;
30 import org.onap.ccsdk.sli.core.dblib.config.JDBCConfiguration;
31 import org.slf4j.LoggerFactory;
34 * @version $Revision: 1.1 $
36 * Author Date Comments
37 * ============== ======== ====================================================
38 * Rich Tabedzki 01/17/08 Initial version
40 public class DBConfigFactory {
42 public static DbConfigPool createConfig(Properties resource) {
43 return getConfigparams(resource);
46 static DbConfigPool getConfigparams(Properties properties){
47 DbConfigPool xmlConfig = new DbConfigPool(properties);
48 ArrayList<Properties> propertySets = new ArrayList<Properties>();
50 if("JDBC".equalsIgnoreCase(xmlConfig.getType())) {
51 String hosts = properties.getProperty(BaseDBConfiguration.DATABASE_HOSTS);
52 if(hosts == null || hosts.isEmpty()) {
53 propertySets.add(properties);
55 String[] newhost = hosts.split(",");
56 for(int i=0; i< newhost.length; i++) {
57 Properties localset = new Properties();
58 localset.putAll(properties);
59 String url = localset.getProperty(BaseDBConfiguration.DATABASE_URL);
60 if(url.contains("DBHOST"))
61 url = url.replace("DBHOST", newhost[i]);
62 if(url.contains("dbhost"))
63 url = url.replace("dbhost", newhost[i]);
64 localset.setProperty(BaseDBConfiguration.DATABASE_URL, url);
65 localset.setProperty(BaseDBConfiguration.CONNECTION_NAME, newhost[i]);
66 propertySets.add(localset);
70 propertySets.add(properties);
73 Iterator<Properties> it = propertySets.iterator();
75 BaseDBConfiguration config = parse(it.next());
76 xmlConfig.addConfiguration(config);
79 } catch (Exception e) {
80 LoggerFactory.getLogger(DBConfigFactory.class).warn("",e);
86 public static BaseDBConfiguration parse(Properties props) throws Exception {
88 String type = props.getProperty(BaseDBConfiguration.DATABASE_TYPE);
90 BaseDBConfiguration config = null;
92 if("JDBC".equalsIgnoreCase(type)) {
93 config = new JDBCConfiguration(props);