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