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