2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.openecomp.sdnc.sli;
25 import java.io.FileInputStream;
26 import java.io.InputStream;
27 import java.util.Properties;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class SvcLogicStoreFactory {
34 private static final Logger LOG = LoggerFactory.getLogger(SvcLogicStoreFactory.class);
36 public static SvcLogicStore getSvcLogicStore(String propfile)
37 throws SvcLogicException {
38 File propFile = new File(propfile);
39 if (!propFile.canRead()) {
40 throw new ConfigurationException("Cannot read property file "
46 return (getSvcLogicStore(new FileInputStream(propFile)));
47 } catch (Exception e) {
48 throw new ConfigurationException(
49 "Could load service store from properties file " + propfile,
55 public static SvcLogicStore getSvcLogicStore(InputStream inStr) throws SvcLogicException
57 Properties props = new Properties();
61 } catch (Exception e) {
62 throw new ConfigurationException("Could not get load properties from input stream", e);
65 return(getSvcLogicStore(props));
68 public static SvcLogicStore getSvcLogicStore(Properties props)
69 throws SvcLogicException {
70 String storeType = props.getProperty("org.openecomp.sdnc.sli.dbtype");
71 if ((storeType == null) || (storeType.length() == 0)) {
72 throw new ConfigurationException(
73 "property org.openecomp.sdnc.sli.dbtype unset");
77 SvcLogicStore retval = null;
78 LOG.debug(String.format("Using org.openecomp.sdnc.sli.dbtype=%s", storeType));
80 if ("jdbc".equalsIgnoreCase(storeType)) {
81 retval = new SvcLogicJdbcStore();
83 } else if ("dblib".equalsIgnoreCase(storeType)) {
84 retval = new SvcLogicDblibStore();
86 throw new ConfigurationException("unsupported dbtype (" + storeType