More license header updates to appc-config files
[appc.git] / appc-config / appc-encryption-tool / provider / src / main / java / org / onap / appc / encryptiontool / wrapper / DbServiceUtil.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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  *
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.appc.encryptiontool.wrapper;
23
24 import com.google.common.collect.Lists;
25 import java.io.File;
26 import java.io.IOException;
27 import java.net.URL;
28 import java.sql.SQLException;
29 import java.util.List;
30 import java.util.Properties;
31 import javax.sql.rowset.CachedRowSet;
32 import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 public class DbServiceUtil {
37
38     private static final Logger log = LoggerFactory.getLogger(DbServiceUtil.class);
39     private static DBResourceManager jdbcDataSource = null;
40
41     private DbServiceUtil() {}
42
43     public static boolean updateDB(String tableName, List<String> argList, String whereClause, String setCluase)
44         throws SQLException {
45
46         String updatePasswordString = "update " + tableName + " set " + setCluase + " where " + whereClause;
47         return jdbcDataSource.writeData(updatePasswordString, Lists.newArrayList(argList), Constants.SCHEMA_SDNCTL);
48     }
49
50     public static CachedRowSet getData(String tableName, List<String> argList, String schema,
51         String getselectData, String getDataClasue) throws SQLException {
52
53         String selectQuery = "select " + getselectData + "from " + tableName + " where " + getDataClasue;
54         return jdbcDataSource.getData(selectQuery, Lists.newArrayList(argList), schema);
55     }
56
57
58     public static DBResourceManager initDbLibService() throws IOException {
59         Properties props = new Properties();
60         File file = new File("/opt/onap/appc/data/properties/dblib.properties");
61         URL propURL = file.toURI().toURL();
62         props.load(propURL.openStream());
63         jdbcDataSource = new DBResourceManager(props);
64         return jdbcDataSource;
65     }
66 }