2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * ================================================================================
9 * Modifications (C) 2019 Ericsson
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.dao.util.api;
28 import org.onap.appc.dao.util.exception.DBConnectionPoolException;
30 import java.sql.Connection;
34 * This class is the interface of DBConnectionPool.
36 * Below is an example of how to query an entry from database.
37 * Inject AppcDatabaseConnectionPool bean by the blueprint first
40 * <reference id="AppcMysqlDBConnectionPoolService" availability="mandatory"
41 * activation="eager" interface="org.onap.appc.dao.util.api.DBConnectionPoolService" />
44 * Then, query the data and close ResultSet, Statement, Connection.
47 * private AppcDatabaseConnectionPool pool;
48 * public void setAppcDatabaseConnectionPool(AppcDatabaseConnectionPool pool){
51 * public queryAppcDatabase(AppcDatabaseConnectionPool pool){
52 * Connection connection = null;
54 * connection = pool.getConnection();
55 * } catch (DBConnectionPoolException e) {
56 * e.printStackTrace();
58 * Connection conn = null;
59 * Statement stmt = null;
60 * ResultSet rs = null;
62 * stmt = connection.createStatement();
63 * rs = stmt.executeQuery("select * from appcctl.transactions");
64 * System.out.println("# of entries in db:");
65 * int numcols = rs.getMetaData().getColumnCount();
66 * System.out.println(pool.getDataSourceStatus());
67 * }catch (SQLException e) {
68 * e.printStackTrace();
71 * pool.close(rs, stmt, conn);
72 * } catch (DataAccessException e) {
73 * e.printStackTrace();
81 public interface DBConnectionPoolService {
83 * Get a jdbc connection
85 * @return connection {@link Connection}
86 * @throws DBConnectionPoolException - if a {@link Connection} cannot be return.
88 Connection getConnection() throws DBConnectionPoolException;
91 * Get Data source status
95 Map<String, Integer> getDataSourceStatus();