OCILIB (C and C++ Driver for Oracle)  4.7.3
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-2021 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  Acquire(core::Check(OCI_PoolCreate(db.c_str(), user.c_str(), pwd.c_str(), poolType, sessionFlags.GetValues(),
49  minSize, maxSize, increment)), reinterpret_cast<HandleFreeFunc>(OCI_PoolFree), nullptr, Environment::GetEnvironmentHandle());
50 }
51 
52 inline void Pool::Close()
53 {
54  Release();
55 }
56 
57 inline Connection Pool::GetConnection(const ostring& sessionTag)
58 {
59  return Connection(core::Check(OCI_PoolGetConnection(*this, sessionTag.c_str())), GetHandle());
60 }
61 
62 inline unsigned int Pool::GetTimeout() const
63 {
64  return core::Check(OCI_PoolGetTimeout(*this));
65 }
66 
67 inline void Pool::SetTimeout(unsigned int value)
68 {
69  core::Check(OCI_PoolSetTimeout(*this, value));
70 }
71 
72 inline bool Pool::GetNoWait() const
73 {
74  return (core::Check(OCI_PoolGetNoWait(*this)) == TRUE);
75 }
76 
77 inline void Pool::SetNoWait(bool value)
78 {
79  core::Check(OCI_PoolSetNoWait(*this, value));
80 }
81 
82 inline unsigned int Pool::GetBusyConnectionsCount() const
83 {
84  return core::Check(OCI_PoolGetBusyCount(*this));
85 }
86 
87 inline unsigned int Pool::GetOpenedConnectionsCount() const
88 {
89  return core::Check(OCI_PoolGetOpenedCount(*this));
90 }
91 
92 inline unsigned int Pool::GetMinSize() const
93 {
94  return core::Check(OCI_PoolGetMin(*this));
95 }
96 
97 inline unsigned int Pool::GetMaxSize() const
98 {
99  return core::Check(OCI_PoolGetMax(*this));
100 }
101 
102 inline unsigned int Pool::GetIncrement() const
103 {
104  return core::Check(OCI_PoolGetIncrement(*this));
105 }
106 
107 inline unsigned int Pool::GetStatementCacheSize() const
108 {
110 }
111 
112 inline void Pool::SetStatementCacheSize(unsigned int value)
113 {
115 }
116 
117 }
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
OCILIB ++ Namespace.
OCI_SYM_PUBLIC OCI_Connection *OCI_API OCI_PoolGetConnection(OCI_Pool *pool, const otext *tag)
Get a connection from the pool.
A connection or session with a specific database.
Definition: types.hpp:1563
unsigned int GetOpenedConnectionsCount() const
Return the current number of opened connections/sessions.
Definition: Pool.hpp:87
static T Check(T result)
Internal usage. Checks if the last OCILIB function call has raised an error. If so, it raises a C++ exception using the retrieved error handle.
Definition: Utils.hpp:53
OCI_SYM_PUBLIC boolean OCI_API OCI_PoolFree(OCI_Pool *pool)
Destroy a pool object.
Template Flags template class providing some type safety to some extends for manipulating flags set v...
Definition: core.hpp:147
void SetStatementCacheSize(unsigned int value)
Set the maximum number of statements to keep in the pool&#39;s statement cache.
Definition: Pool.hpp:112
void Close()
Destroy the current Oracle pool of connections or sessions.
Definition: Pool.hpp:52
OCI_SYM_PUBLIC unsigned int OCI_API OCI_PoolGetBusyCount(OCI_Pool *pool)
Return the current number of busy connections/sessions.
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.
Template Enumeration template class providing some type safety to some extends for manipulating enume...
Definition: core.hpp:117
void SetNoWait(bool value)
Set the waiting mode used when no more connections/sessions are available from the pool...
Definition: Pool.hpp:77
unsigned int GetMaxSize() const
Return the maximum number of connections/sessions that can be opened to the database.
Definition: Pool.hpp:97
unsigned int GetStatementCacheSize() const
Return the maximum number of statements to keep in the pool&#39;s statement cache.
Definition: Pool.hpp:107
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.
void SetTimeout(unsigned int value)
Set the connections/sessions idle timeout.
Definition: Pool.hpp:67
OCI_SYM_PUBLIC boolean OCI_API OCI_PoolSetTimeout(OCI_Pool *pool, unsigned int value)
Set the connections/sessions idle timeout.
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:102
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.
Connection GetConnection(const ostring &sessionTag=OTEXT(""))
Get a connection from the pool.
Definition: Pool.hpp:57
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.
Pool()
Default constructor.
Definition: Pool.hpp:32
unsigned int GetMinSize() const
Return the minimum number of connections/sessions that can be opened to the database.
Definition: Pool.hpp:92
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_PoolSetStatementCacheSize(OCI_Pool *pool, unsigned int value)
Set the maximum number of statements to keep in the pool statement cache.
unsigned int GetBusyConnectionsCount() const
Return the current number of busy connections/sessions.
Definition: Pool.hpp:82
bool GetNoWait() const
Get the waiting mode used when no more connections/sessions are available from the pool...
Definition: Pool.hpp:72
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.
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
unsigned int GetTimeout() const
Get the idle timeout for connections/sessions in the pool.
Definition: Pool.hpp:62
OCI_SYM_PUBLIC unsigned int OCI_API OCI_PoolGetOpenedCount(OCI_Pool *pool)
Return the current number of opened connections/sessions.