2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.vid.dao;
23 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
28 public class FnAppDoaImpl {
31 static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FnAppDoaImpl.class);
33 public int getProfileCount(String driver, String URL, String username, String password) {
34 Connection dbc = null;
35 PreparedStatement pst = null;
40 dbc = getConnection(URL,username,password);
41 logger.debug(EELFLoggerDelegate.debugLogger, "getConnection:::"+ dbc);
42 q = "select count(*) from fn_app";
43 pst = dbc.prepareStatement(q);
44 rs = pst.executeQuery();
48 } catch(Exception ex) {
49 logger.error(EELFLoggerDelegate.errorLogger, "Failed to perform health check", ex);
53 logger.debug(EELFLoggerDelegate.debugLogger, "count:::"+ count);
57 public static Connection getConnection(String url, String username, String password) throws SQLException {
58 java.sql.Connection con=null;
60 if( url!=null && username!=null && password!=null ){
61 con = DriverManager.getConnection(url, username, password);
64 logger.info("Connection Successful");
70 public static void cleanup(ResultSet rs, PreparedStatement st, Connection c) {
75 closePreparedStatement(st);
78 rollbackAndCloseConnection(c);
82 private static void rollbackAndCloseConnection(Connection c) {
85 } catch (Exception e) {
87 logger.error("Error when trying to rollback connection", e);
91 } catch (Exception e) {
93 logger.error("Error when trying to close connection", e);
97 private static void closePreparedStatement(PreparedStatement st) {
100 } catch (Exception e) {
102 logger.error("Error when trying to close statement", e);
106 private static void closeResultSet(ResultSet rs) {
109 } catch (Exception e) {
111 logger.error("Error when trying to close result set", e);