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