Change code in appc dispatcher for new LCMs in R6
[appc.git] / appc-dispatcher / appc-dispatcher-common / appc-data-access-lib / src / main / java / org / onap / appc / dao / util / api / DBConnectionPoolService.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
14  *
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  *
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=========================================================
23  */
24
25 package org.onap.appc.dao.util.api;
26
27 import org.onap.appc.dao.util.exception.DBConnectionPoolException;
28
29 import java.sql.Connection;
30 import java.util.Map;
31
32 /**
33  * This class is the interface of DBConnectionPool.
34  * <p>
35  * Below is an example of how to query an entry from database.
36  * Inject AppcDatabaseConnectionPool bean by the blueprint first
37  * for example,
38  * {@code
39  * <reference id="AppcMysqlDBConnectionPoolService" availability="mandatory"
40  * activation="eager" interface="org.onap.appc.dao.util.api.DBConnectionPoolService" />
41  * }
42  * <p>
43  * Then, query the data and close ResultSet, Statement, Connection.
44  * <blockquote><pre>
45  * {@code
46  * private AppcDatabaseConnectionPool pool;
47  * public void setAppcDatabaseConnectionPool(AppcDatabaseConnectionPool pool) {
48  *     this.pool = pool;
49  * }
50  * public queryAppcDatabase(AppcDatabaseConnectionPool pool) {
51  *      Connection connection = null;
52  *      try {
53  *          connection = pool.getConnection();
54  *      } catch (DBConnectionPoolException e) {
55  *          e.printStackTrace();
56  *      }
57  *      Connection conn = null;
58  *      Statement stmt = null;
59  *      ResultSet rs = null;
60  *      try {
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();
68  *      } finally {
69  *          try {
70  *              pool.close(rs, stmt, conn);
71  *              } catch (DataAccessException e) {
72  *                  e.printStackTrace();
73  *              }
74  *     }
75  * }
76  * }
77  * <p>
78  * </pre></blockquote>
79  */
80 public interface DBConnectionPoolService {
81     /**
82      * Get a jdbc connection
83      *
84      * @return connection {@link Connection}
85      * @throws DBConnectionPoolException - if a {@link Connection} cannot be return.
86      */
87     Connection getConnection() throws DBConnectionPoolException;
88
89     /**
90      * Get Data source status
91      *
92      * @return map
93      */
94     Map<String, Integer> getDataSourceStatus();
95
96 }