2849641b5b6fb24d81ee5ba45dc2ab1329c4bee7
[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 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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.appc.encryptiontool.wrapper;
24
25 import com.google.common.collect.Lists;
26 import java.io.File;
27 import java.io.IOException;
28 import java.net.URL;
29 import java.sql.SQLException;
30 import java.util.List;
31 import java.util.Properties;
32 import javax.sql.rowset.CachedRowSet;
33 import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36
37 public class DbServiceUtil {
38
39     private static final Logger log = LoggerFactory.getLogger(DbServiceUtil.class);
40     private static DBResourceManager jdbcDataSource = null;
41
42     private DbServiceUtil() {}
43
44     public static boolean updateDB(String tableName, List<String> argList, String whereClause, String setCluase)
45         throws SQLException {
46
47         String updatePasswordString = "update " + tableName + " set " + setCluase + " where " + whereClause;
48         return jdbcDataSource.writeData(updatePasswordString, Lists.newArrayList(argList), Constants.SCHEMA_SDNCTL);
49     }
50
51     public static CachedRowSet getData(String tableName, List<String> argList, String schema,
52         String getselectData, String getDataClasue) throws SQLException {
53
54         String selectQuery = "select " + getselectData + "from " + tableName + " where " + getDataClasue;
55         return jdbcDataSource.getData(selectQuery, Lists.newArrayList(argList), schema);
56     }
57
58
59     public static DBResourceManager initDbLibService() throws IOException {
60         Properties props = new Properties();
61         File file = new File("/opt/onap/appc/data/properties/dblib.properties");
62         URL propURL = file.toURI().toURL();
63         props.load(propURL.openStream());
64         jdbcDataSource = new DBResourceManager(props);
65         return jdbcDataSource;
66     }
67 }