2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 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.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.dao.util.api;
27 import org.onap.appc.dao.util.exception.DBConnectionPoolException;
29 import java.sql.Connection;
33 * This class is the interface of DBConnectionPool.
35 * Below is an example of how to query an entry from database.
36 * Inject AppcDatabaseConnectionPool bean by the blueprint first
39 * <reference id="AppcMysqlDBConnectionPoolService" availability="mandatory"
40 * activation="eager" interface="org.onap.appc.dao.util.api.DBConnectionPoolService" />
43 * Then, query the data and close ResultSet, Statement, Connection.
46 * private AppcDatabaseConnectionPool pool;
47 * public void setAppcDatabaseConnectionPool(AppcDatabaseConnectionPool pool) {
50 * public queryAppcDatabase(AppcDatabaseConnectionPool pool) {
51 * Connection connection = null;
53 * connection = pool.getConnection();
54 * } catch (DBConnectionPoolException e) {
55 * e.printStackTrace();
57 * Connection conn = null;
58 * Statement stmt = null;
59 * ResultSet rs = null;
61 * stmt = connection.createStatement();
62 * rs = stmt.executeQuery("select * from appcctl.transactions");
63 * System.out.println("# of entries in db:");
64 * int numcols = rs.getMetaData().getColumnCount();
65 * System.out.println(pool.getDataSourceStatus());
66 * } catch (SQLException e) {
67 * e.printStackTrace();
70 * pool.close(rs, stmt, conn);
71 * } catch (DataAccessException e) {
72 * e.printStackTrace();
80 public interface DBConnectionPoolService {
82 * Get a jdbc connection
84 * @return connection {@link Connection}
85 * @throws DBConnectionPoolException - if a {@link Connection} cannot be return.
87 Connection getConnection() throws DBConnectionPoolException;
90 * Get Data source status
94 Map<String, Integer> getDataSourceStatus();