a4151ab48bb1be0f1def47ec2944bdb32d8e4efe
[appc.git] / appc-config / appc-config-generator / provider / src / main / java / org / onap / sdnc / config / generator / tool / DbServiceUtil.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.sdnc.config.generator.tool;
25
26 import com.google.common.collect.Lists;
27 import java.io.File;
28 import java.net.URL;
29 import java.sql.SQLException;
30 import java.util.ArrayList;
31 import java.util.List;
32 import java.util.Properties;
33 import javax.sql.rowset.CachedRowSet;
34 import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37
38 public class DbServiceUtil {
39
40     private static final Logger log = LoggerFactory.getLogger(DbServiceUtil.class);
41
42     private static Properties properties;
43     private static DBResourceManager jdbcDataSource = null;
44
45
46     public static boolean updateDB(String tableName, List<String> inputArgs, String whereClause, String setClause)
47         throws SQLException {
48         String updatePasswordString =
49             "update " + tableName + " set " + setClause + " where " + whereClause;
50
51         return jdbcDataSource.writeData(updatePasswordString, Lists.newArrayList(inputArgs), Constants.SCHEMA_SDNCTL);
52     }
53
54
55     public static CachedRowSet getData(String tableName, List<String> argList, String schema,
56         String getselectData, String getDataClasue) throws SQLException {
57         String selectQuery =
58             "select " + getselectData + "from " + tableName + " where " + getDataClasue;
59         return jdbcDataSource.getData(selectQuery, Lists.newArrayList(argList), schema);
60     }
61
62
63     public static DBResourceManager initDbLibService() throws Exception {
64         properties = new Properties();
65         File file = new File("/opt/onap/appc/data/properties/dblib.properties");
66         URL propURL = file.toURI().toURL();
67         properties.load(propURL.openStream());
68
69         // this is an expected difference in CCSDK
70         jdbcDataSource = new DBResourceManager(properties);
71
72         return jdbcDataSource;
73     }
74 }