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