c8340816e926fc25c2d9063d4974e651e1bbf285
[appc.git] / appc-config / appc-config-generator / provider / src / main / java / org / openecomp / sdnc / config / generator / tool / DbServiceUtil.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APP-C
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  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdnc.config.generator.tool;
22
23 import java.io.File;
24 import java.net.URL;
25 import java.sql.SQLException;
26 import java.util.ArrayList;
27 import java.util.Properties;
28
29 import javax.sql.rowset.CachedRowSet;
30
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
35 import org.onap.ccsdk.sli.core.dblib.DbLibService;
36
37 public class DbServiceUtil
38 {    
39     private static final Logger log = LoggerFactory
40             .getLogger(DbServiceUtil.class);
41     
42     private static Properties props;
43     private static DBResourceManager jdbcDataSource = null;
44     
45
46     public static boolean updateDB(String tableName, ArrayList inputArgs, String scema, String whereClause, String setCluase) throws SQLException  
47     {
48             String updatePasswordString = "update " + tableName + " set " +  setCluase +  " where " + whereClause ;
49             boolean result = jdbcDataSource.writeData(updatePasswordString, inputArgs,Constants.SCHEMA_SDNCTL);
50             return result;
51     }
52     
53     
54      public static CachedRowSet getData(String tableName, ArrayList argList, String schema, String getselectData, String getDataClasue ) throws SQLException
55      {         
56          String selectQuery = "select " + getselectData + "from " + tableName + " where " + getDataClasue ;         
57          CachedRowSet data = jdbcDataSource.getData(selectQuery, argList, schema);         
58          return data;         
59      }
60
61
62     public static DBResourceManager initDbLibService() throws Exception 
63     {
64         props = new Properties();
65         File file = new File("/opt/app/bvc/properties/dblib.properties");        
66         URL propURL = file.toURI().toURL();    
67         props.load(propURL.openStream());        
68         jdbcDataSource = new DBResourceManager(props);
69         return jdbcDataSource;
70         
71     }
72
73
74
75 }