1 | // |
---|---|
2 | // PooledSessionImpl.cpp |
3 | // |
4 | // Library: SQL |
5 | // Package: SessionPooling |
6 | // Module: PooledSessionImpl |
7 | // |
8 | // Copyright (c) 2006, Applied Informatics Software Engineering GmbH. |
9 | // and Contributors. |
10 | // |
11 | // SPDX-License-Identifier: BSL-1.0 |
12 | // |
13 | |
14 | |
15 | #include "Poco/SQL/PooledSessionImpl.h" |
16 | #include "Poco/SQL/SQLException.h" |
17 | #include "Poco/SQL/SessionPool.h" |
18 | |
19 | |
20 | namespace Poco { |
21 | namespace SQL { |
22 | |
23 | |
24 | PooledSessionImpl::PooledSessionImpl(PooledSessionHolder::Ptr pHolder): |
25 | SessionImpl(pHolder->session()->connectionString(), |
26 | pHolder->session()->getLoginTimeout()), |
27 | _pHolder(pHolder) |
28 | { |
29 | } |
30 | |
31 | |
32 | PooledSessionImpl::~PooledSessionImpl() |
33 | { |
34 | try |
35 | { |
36 | close(); |
37 | } |
38 | catch (...) |
39 | { |
40 | poco_unexpected(); |
41 | } |
42 | } |
43 | |
44 | |
45 | StatementImpl::Ptr PooledSessionImpl::createStatementImpl() |
46 | { |
47 | return access()->createStatementImpl(); |
48 | } |
49 | |
50 | |
51 | void PooledSessionImpl::begin() |
52 | { |
53 | return access()->begin(); |
54 | } |
55 | |
56 | |
57 | void PooledSessionImpl::commit() |
58 | { |
59 | return access()->commit(); |
60 | } |
61 | |
62 | |
63 | bool PooledSessionImpl::isConnected() const |
64 | { |
65 | return access()->isConnected(); |
66 | } |
67 | |
68 | |
69 | void PooledSessionImpl::setConnectionTimeout(std::size_t timeout) |
70 | { |
71 | return access()->setConnectionTimeout(timeout); |
72 | } |
73 | |
74 | |
75 | std::size_t PooledSessionImpl::getConnectionTimeout() const |
76 | { |
77 | return access()->getConnectionTimeout(); |
78 | } |
79 | |
80 | |
81 | bool PooledSessionImpl::canTransact() const |
82 | { |
83 | return access()->canTransact(); |
84 | } |
85 | |
86 | |
87 | bool PooledSessionImpl::isTransaction() const |
88 | { |
89 | return access()->isTransaction(); |
90 | } |
91 | |
92 | |
93 | void PooledSessionImpl::setTransactionIsolation(Poco::UInt32 ti) |
94 | { |
95 | access()->setTransactionIsolation(ti); |
96 | } |
97 | |
98 | |
99 | Poco::UInt32 PooledSessionImpl::getTransactionIsolation() const |
100 | { |
101 | return access()->getTransactionIsolation(); |
102 | } |
103 | |
104 | |
105 | bool PooledSessionImpl::hasTransactionIsolation(Poco::UInt32 ti) const |
106 | { |
107 | return access()->hasTransactionIsolation(ti); |
108 | } |
109 | |
110 | |
111 | bool PooledSessionImpl::isTransactionIsolation(Poco::UInt32 ti) const |
112 | { |
113 | return access()->isTransactionIsolation(ti); |
114 | } |
115 | |
116 | |
117 | void PooledSessionImpl::rollback() |
118 | { |
119 | return access()->rollback(); |
120 | } |
121 | |
122 | |
123 | void PooledSessionImpl::open(const std::string& connect) |
124 | { |
125 | access()->open(connect); |
126 | } |
127 | |
128 | |
129 | void PooledSessionImpl::putBack() |
130 | { |
131 | if (_pHolder) |
132 | { |
133 | _pHolder->owner().putBack(_pHolder); |
134 | _pHolder = nullptr; |
135 | } |
136 | } |
137 | |
138 | |
139 | void PooledSessionImpl::close() |
140 | { |
141 | if (_pHolder) |
142 | { |
143 | if (isTransaction()) |
144 | { |
145 | try |
146 | { |
147 | rollback(); |
148 | } |
149 | catch (...) |
150 | { |
151 | // Something's wrong with the session. Get rid of it. |
152 | access()->close(); |
153 | } |
154 | } |
155 | putBack(); |
156 | } |
157 | } |
158 | |
159 | |
160 | void PooledSessionImpl::reset() |
161 | { |
162 | access()->reset(); |
163 | } |
164 | |
165 | |
166 | const std::string& PooledSessionImpl::connectorName() const |
167 | { |
168 | return access()->connectorName(); |
169 | } |
170 | |
171 | |
172 | void PooledSessionImpl::setFeature(const std::string& name, bool state) |
173 | { |
174 | access()->setFeature(name, state); |
175 | } |
176 | |
177 | |
178 | bool PooledSessionImpl::getFeature(const std::string& name) const |
179 | { |
180 | return access()->getFeature(name); |
181 | } |
182 | |
183 | |
184 | void PooledSessionImpl::setProperty(const std::string& name, const Poco::Any& value) |
185 | { |
186 | access()->setProperty(name, value); |
187 | } |
188 | |
189 | |
190 | Poco::Any PooledSessionImpl::getProperty(const std::string& name) const |
191 | { |
192 | return access()->getProperty(name); |
193 | } |
194 | |
195 | |
196 | SessionImpl::Ptr PooledSessionImpl::access() const |
197 | { |
198 | if (_pHolder) |
199 | { |
200 | _pHolder->access(); |
201 | return impl(); |
202 | } |
203 | else throw SessionUnavailableException(); |
204 | } |
205 | |
206 | |
207 | } } // namespace Poco::SQL |
208 |