全て クラス 名前空間 関数 変数 型定義 列挙型 列挙値 ページ
connectionPool.h
1 #ifndef BZS_DB_PROTOCOL_TDAP_CLIENT_CONNECTIONPOOL_H
2 #define BZS_DB_PROTOCOL_TDAP_CLIENT_CONNECTIONPOOL_H
3 /*=================================================================
4  Copyright (C) 2014 BizStation Corp All rights reserved.
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  as published by the Free Software Foundation; either version 2
9  of the License, or (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19  02111-1307, USA.
20 =================================================================*/
21 #if HAVE_RB_THREAD_CALL_WITHOUT_GVL || HAVE_RB_THREAD_BLOCKING_REGION
22 #include <build/swig/ruby/threadBlockRegionWrapper.h>
23 #endif
24 
25 #include <bzs/db/protocol/tdap/client/databaseManager.h>
26 #define BOOST_THREAD_USE_LIB
27 #include <boost/thread/thread.hpp>
28 #include <boost/thread/condition.hpp>
29 #include <vector>
30 
31 namespace bzs
32 {
33 namespace db
34 {
35 namespace protocol
36 {
37 namespace tdap
38 {
39 namespace client
40 {
41 
42 /** connection pool class
43  Hold database or databaseManager instance and delivery.
44 
45  If maxConnections = 0 then not create databases automaticaly at no free
46  a database.
47  This case need call reserve() function at start up the process.\n
48 
49  Otherwise, create new database automaticaly by get() function with
50  connectParams.
51  This case need call setMaxConnections() function at start up the
52  process.
53 */
54 
55 template <class Database_Ptr> class connectionPool
56 {
57  std::vector<Database_Ptr> m_dbs;
58  mutable boost::mutex m_mutex;
59  mutable boost::mutex m_mutex2;
60  mutable boost::condition m_busy;
61  int m_maxConnections;
62  Database_Ptr addOne(const connectParams& param);
63  WIN_TPOOL_SHUTDOWN_PTR m_shutdownFunc;
64 public:
67 
68  Database_Ptr get(const connectParams* param = NULL);
69  void reserve(size_t size, const connectParams& param);
70  void setMaxConnections(int n);
71  int maxConnections() const;
72  void releaseOne();
73  bool reset(int waitSec = 5);
74  int usingCount() const;
75 };
76 
79 
80 /** stdDbmCconnectionPool is default for connetion pool.
81  pooling database and reuse tables.
82 */
83 #ifdef USE_DBM_CONNECTION_POOL
84 typedef stdDbmCconnectionPool stdCconnectionPool;
85 #else
86 #ifdef USE_DB_CONNECTION_POOL
87 typedef stdDbCconnectionPool stdCconnectionPool;
88 #else
89 #error \
90  "Please define the USE_DBM_CONNECTION_POOL when you need a connection pool";
91 #endif
92 #endif
93 
94 short __STDCALL dllUnloadCallbackFunc();
96 
97 extern stdCconnectionPool cpool;
98 
99 } // namespace client
100 } // namespace tdap
101 } // namespace protocol
102 } // namespace db
103 } // namespace bzs
104 
105 #endif // BZS_DB_PROTOCOL_TDAP_CLIENT_CONNECTIONPOOL_H
connectionPool< database_ptr > stdDbCconnectionPool
Definition: connectionPool.h:77
void reserve(size_t size, const connectParams &param)
void releaseConnection(stdDbmCconnectionPool *pool)
connectionPool< dbmanager_ptr > stdDbmCconnectionPool
Definition: connectionPool.h:78
short __STDCALL dllUnloadCallbackFunc()
データベースへの接続文字列生成ヘルパークラス
Definition: trdboostapi.h:72

Transactd SDK 2018年07月31日(火) 19時40分20秒 doxygen