2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2016 - 2017 AT&T
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.openecomp.sdnc.sli.resource.dblib.factory;
24 import java.util.ArrayList;
25 import java.util.Iterator;
26 import java.util.Properties;
28 import org.slf4j.LoggerFactory;
30 import org.openecomp.sdnc.sli.resource.dblib.config.BaseDBConfiguration;
31 import org.openecomp.sdnc.sli.resource.dblib.config.DbConfigPool;
32 import org.openecomp.sdnc.sli.resource.dblib.config.JDBCConfiguration;
35 * @version $Revision: 1.1 $
37 * Author Date Comments
38 * ============== ======== ====================================================
39 * Rich Tabedzki 01/17/08 Initial version
41 public class DBConfigFactory {
43 public static DbConfigPool createConfig(Properties resource) {
44 return getConfigparams(resource);
47 static DbConfigPool getConfigparams(Properties properties){
48 LoggerFactory.getLogger(DBConfigFactory.class).info(properties.toString());
49 DbConfigPool xmlConfig = new DbConfigPool(properties);
50 ArrayList<Properties> propertySets = new ArrayList<Properties>();
52 if("JDBC".equalsIgnoreCase(xmlConfig.getType())) {
53 String hosts = properties.getProperty(BaseDBConfiguration.DATABASE_HOSTS);
54 if(hosts == null || hosts.isEmpty()) {
55 propertySets.add(properties);
57 String[] newhost = hosts.split(",");
58 for(int i=0; i< newhost.length; i++) {
59 Properties localset = new Properties();
60 localset.putAll(properties);
61 String url = localset.getProperty(BaseDBConfiguration.DATABASE_URL);
62 if(url.contains("DBHOST"))
63 url = url.replace("DBHOST", newhost[i]);
64 if(url.contains("dbhost"))
65 url = url.replace("dbhost", newhost[i]);
66 localset.setProperty(BaseDBConfiguration.DATABASE_URL, url);
67 localset.setProperty(BaseDBConfiguration.CONNECTION_NAME, newhost[i]);
68 propertySets.add(localset);
72 propertySets.add(properties);
75 Iterator<Properties> it = propertySets.iterator();
77 BaseDBConfiguration config = parse(it.next());
78 xmlConfig.addConfiguration(config);
81 } catch (Exception e) {
82 LoggerFactory.getLogger(DBConfigFactory.class).warn("",e);
88 public static BaseDBConfiguration parse(Properties props) throws Exception {
90 String type = props.getProperty(BaseDBConfiguration.DATABASE_TYPE);
92 BaseDBConfiguration config = null;
94 if("JDBC".equalsIgnoreCase(type)) {
95 config = new JDBCConfiguration(props);