OCILIB (C and C++ Driver for Oracle)  4.7.6
Open source and cross platform Oracle Driver delivering efficient access to Oracle databases.
Pool.hpp
1 /*
2  * OCILIB - C Driver for Oracle (C Wrapper for Oracle OCI)
3  *
4  * Website: http://www.ocilib.net
5  *
6  * Copyright (c) 2007-2023 Vincent ROGIER <vince.rogier@ocilib.net>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #pragma once
22 
23 #include "ocilibcpp/types.hpp"
24 
25 // ReSharper disable CppClangTidyHicppUseEqualsDefault
26 // ReSharper disable CppClangTidyModernizeUseEqualsDefault
27 // ReSharper disable CppClangTidyPerformanceUnnecessaryValueParam
28 
29 namespace ocilib
30 {
31 
32 inline Pool::Pool()
33 {
34 
35 }
36 
37 inline Pool::Pool(const ostring& db, const ostring& user, const ostring& pwd, Pool::PoolType poolType,
38  unsigned int minSize, unsigned int maxSize, unsigned int increment, Environment::SessionFlags sessionFlags)
39 {
40  Open(db, user, pwd, poolType, minSize, maxSize, increment, sessionFlags);
41 }
42 
43 inline void Pool::Open(const ostring& db, const ostring& user, const ostring& pwd, Pool::PoolType poolType,
44  unsigned int minSize, unsigned int maxSize, unsigned int increment, Environment::SessionFlags sessionFlags)
45 {
46  Release();
47 
48  AcquireAllocated
49  (
51  (
52  OCI_PoolCreate(db.c_str(), user.c_str(), pwd.c_str(), poolType, sessionFlags.GetValues(), minSize, maxSize, increment)
53  ),
54  Environment::GetEnvironmentHandle()
55  );
56 }
57 
58 inline void Pool::Close()
59 {
60  Release();
61 }
62 
63 inline Connection Pool::GetConnection(const ostring& sessionTag)
64 {
65  return Connection(core::Check(OCI_PoolGetConnection(*this, sessionTag.c_str())), GetHandle());
66 }
67 
68 inline unsigned int Pool::GetTimeout() const
69 {
70  return core::Check(OCI_PoolGetTimeout(*this));
71 }
72 
73 inline void Pool::SetTimeout(unsigned int value)
74 {
75  core::Check(OCI_PoolSetTimeout(*this, value));
76 }
77 
78 inline bool Pool::GetNoWait() const
79 {
80  return (core::Check(OCI_PoolGetNoWait(*this)) == TRUE);
81 }
82 
83 inline void Pool::SetNoWait(bool value)
84 {
85  core::Check(OCI_PoolSetNoWait(*this, value));
86 }
87 
88 inline unsigned int Pool::GetBusyConnectionsCount() const
89 {
90  return core::Check(OCI_PoolGetBusyCount(*this));
91 }
92 
93 inline unsigned int Pool::GetOpenedConnectionsCount() const
94 {
95  return core::Check(OCI_PoolGetOpenedCount(*this));
96 }
97 
98 inline unsigned int Pool::GetMinSize() const
99 {
100  return core::Check(OCI_PoolGetMin(*this));
101 }
102 
103 inline unsigned int Pool::GetMaxSize() const
104 {
105  return core::Check(OCI_PoolGetMax(*this));
106 }
107 
108 inline unsigned int Pool::GetIncrement() const
109 {
110  return core::Check(OCI_PoolGetIncrement(*this));
111 }
112 
113 inline unsigned int Pool::GetStatementCacheSize() const
114 {
116 }
117 
118 inline void Pool::SetStatementCacheSize(unsigned int value)
119 {
121 }
122 
123 }
A connection or session with a specific database.
Definition: types.hpp:1580
unsigned int GetMinSize() const
Return the minimum number of connections/sessions that can be opened to the database.
Definition: Pool.hpp:98
Connection GetConnection(const ostring &sessionTag=OTEXT(""))
Get a connection from the pool.
Definition: Pool.hpp:63
bool GetNoWait() const
Get the waiting mode used when no more connections/sessions are available from the pool.
Definition: Pool.hpp:78
unsigned int GetTimeout() const
Get the idle timeout for connections/sessions in the pool.
Definition: Pool.hpp:68
unsigned int GetIncrement() const
Return the increment for connections/sessions to be opened to the database when the pool is not full.
Definition: Pool.hpp:108
void SetNoWait(bool value)
Set the waiting mode used when no more connections/sessions are available from the pool.
Definition: Pool.hpp:83
unsigned int GetStatementCacheSize() const
Return the maximum number of statements to keep in the pool's statement cache.
Definition: Pool.hpp:113
unsigned int GetBusyConnectionsCount() const
Return the current number of busy connections/sessions.
Definition: Pool.hpp:88
void Open(const ostring &db, const ostring &user, const ostring &pwd, Pool::PoolType poolType, unsigned int minSize, unsigned int maxSize, unsigned int increment=1, Environment::SessionFlags sessionFlags=Environment::SessionDefault)
Create an Oracle pool of connections or sessions.
Definition: Pool.hpp:43
void Close()
Destroy the current Oracle pool of connections or sessions.
Definition: Pool.hpp:58
unsigned int GetOpenedConnectionsCount() const
Return the current number of opened connections/sessions.
Definition: Pool.hpp:93
unsigned int GetMaxSize() const
Return the maximum number of connections/sessions that can be opened to the database.
Definition: Pool.hpp:103
Pool()
Default constructor.
Definition: Pool.hpp:32
void SetTimeout(unsigned int value)
Set the connections/sessions idle timeout.
Definition: Pool.hpp:73
void SetStatementCacheSize(unsigned int value)
Set the maximum number of statements to keep in the pool's statement cache.
Definition: Pool.hpp:118
Template Enumeration template class providing some type safety to some extends for manipulating enume...
Definition: core.hpp:118
Template Flags template class providing some type safety to some extends for manipulating flags set v...
Definition: core.hpp:148
OCI_SYM_PUBLIC unsigned int OCI_API OCI_PoolGetBusyCount(OCI_Pool *pool)
Return the current number of busy connections/sessions.
OCI_SYM_PUBLIC OCI_Connection *OCI_API OCI_PoolGetConnection(OCI_Pool *pool, const otext *tag)
Get a connection from the pool.
OCI_SYM_PUBLIC unsigned int OCI_API OCI_PoolGetIncrement(OCI_Pool *pool)
Return the increment for connections/sessions to be opened to the database when the pool is not full.
OCI_SYM_PUBLIC unsigned int OCI_API OCI_PoolGetStatementCacheSize(OCI_Pool *pool)
Return the maximum number of statements to keep in the pool statement cache.
OCI_SYM_PUBLIC boolean OCI_API OCI_PoolSetStatementCacheSize(OCI_Pool *pool, unsigned int value)
Set the maximum number of statements to keep in the pool statement cache.
OCI_SYM_PUBLIC boolean OCI_API OCI_PoolSetNoWait(OCI_Pool *pool, boolean value)
Set the waiting mode used when no more connections/sessions are available from the pool.
OCI_SYM_PUBLIC boolean OCI_API OCI_PoolSetTimeout(OCI_Pool *pool, unsigned int value)
Set the connections/sessions idle timeout.
OCI_SYM_PUBLIC unsigned int OCI_API OCI_PoolGetOpenedCount(OCI_Pool *pool)
Return the current number of opened connections/sessions.
OCI_SYM_PUBLIC OCI_Pool *OCI_API OCI_PoolCreate(const otext *db, const otext *user, const otext *pwd, unsigned int type, unsigned int mode, unsigned int min_con, unsigned int max_con, unsigned int incr_con)
Create an Oracle pool of connections or sessions.
OCI_SYM_PUBLIC unsigned int OCI_API OCI_PoolGetMax(OCI_Pool *pool)
Return the maximum number of connections/sessions that can be opened to the database.
OCI_SYM_PUBLIC boolean OCI_API OCI_PoolGetNoWait(OCI_Pool *pool)
Get the waiting mode used when no more connections/sessions are available from the pool.
OCI_SYM_PUBLIC unsigned int OCI_API OCI_PoolGetTimeout(OCI_Pool *pool)
Get the idle timeout for connections/sessions in the pool.
OCI_SYM_PUBLIC unsigned int OCI_API OCI_PoolGetMin(OCI_Pool *pool)
Return the minimum number of connections/sessions that can be opened to the database.
static T Check(T result)
Internal usage. Checks if the last OCILIB function call has raised an error. If so,...
Definition: Utils.hpp:53
OCILIB ++ Namespace.
std::basic_string< otext, std::char_traits< otext >, std::allocator< otext > > ostring
string class wrapping the OCILIB otext * type and OTEXT() macros ( see Character sets )
Definition: config.hpp:120