2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 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.sli;
24 import java.io.FileInputStream;
25 import java.io.InputStream;
26 import java.util.Properties;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 public class SvcLogicStoreFactory {
33 private static final Logger LOG = LoggerFactory.getLogger(SvcLogicStoreFactory.class);
35 public static SvcLogicStore getSvcLogicStore(String propfile)
36 throws SvcLogicException {
37 File propFile = new File(propfile);
38 if (!propFile.canRead()) {
39 throw new ConfigurationException("Cannot read property file "
45 return (getSvcLogicStore(new FileInputStream(propFile)));
46 } catch (Exception e) {
47 throw new ConfigurationException(
48 "Could load service store from properties file " + propfile,
54 public static SvcLogicStore getSvcLogicStore(InputStream inStr) throws SvcLogicException
56 Properties props = new Properties();
60 } catch (Exception e) {
61 throw new ConfigurationException("Could not get load properties from input stream", e);
64 return(getSvcLogicStore(props));
67 public static SvcLogicStore getSvcLogicStore(Properties props)
68 throws SvcLogicException {
69 String storeType = props.getProperty("org.openecomp.sdnc.sli.dbtype");
70 if ((storeType == null) || (storeType.length() == 0)) {
71 throw new ConfigurationException(
72 "property org.openecomp.sdnc.sli.dbtype unset");
76 SvcLogicStore retval = null;
77 LOG.debug(String.format("Using org.openecomp.sdnc.sli.dbtype=%s", storeType));
79 if ("jdbc".equalsIgnoreCase(storeType)) {
80 retval = new SvcLogicJdbcStore();
82 } else if ("dblib".equalsIgnoreCase(storeType)) {
83 retval = new SvcLogicDblibStore();
85 throw new ConfigurationException("unsupported dbtype (" + storeType