2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.dao.util.api;
26 import org.onap.appc.dao.util.exception.DBConnectionPoolException;
27 import org.onap.appc.dao.util.exception.DataAccessException;
29 import java.sql.Connection;
30 import java.sql.ResultSet;
31 import java.sql.SQLException;
32 import java.sql.Statement;
36 * This class is the interface of DBConnectionPool.
38 * Below is an example of how to query an entry from database.
39 * Inject AppcDatabaseConnectionPool bean by the blueprint first
42 * <reference id="AppcMysqlDBConnectionPoolService" availability="mandatory"
43 * activation="eager" interface="org.onap.appc.dao.util.api.DBConnectionPoolService" />
46 * Then, query the data and close ResultSet, Statement, Connection.
49 * private AppcDatabaseConnectionPool pool;
50 * public void setAppcDatabaseConnectionPool(AppcDatabaseConnectionPool pool){
53 * public queryAppcDatabase(AppcDatabaseConnectionPool pool){
54 * Connection connection = null;
56 * connection = pool.getConnection();
57 * } catch (DBConnectionPoolException e) {
58 * e.printStackTrace();
60 * Connection conn = null;
61 * Statement stmt = null;
62 * ResultSet rs = null;
64 * stmt = connection.createStatement();
65 * rs = stmt.executeQuery("select * from appcctl.transactions");
66 * System.out.println("# of entries in db:");
67 * int numcols = rs.getMetaData().getColumnCount();
68 * System.out.println(pool.getDataSourceStatus());
69 * }catch (SQLException e) {
70 * e.printStackTrace();
73 * pool.close(rs, stmt, conn);
74 * } catch (DataAccessException e) {
75 * e.printStackTrace();
83 public interface DBConnectionPoolService {
85 * Get a jdbc connection
87 * @return connection {@link Connection}
88 * @throws DBConnectionPoolException - if a {@link Connection} cannot be return.
90 Connection getConnection() throws DBConnectionPoolException;
93 * Get Data source status
97 Map<String, Integer> getDataSourceStatus();