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
20namespace Poco {
21namespace SQL {
22
23
24PooledSessionImpl::PooledSessionImpl(PooledSessionHolder::Ptr pHolder):
25 SessionImpl(pHolder->session()->connectionString(),
26 pHolder->session()->getLoginTimeout()),
27 _pHolder(pHolder)
28{
29}
30
31
32PooledSessionImpl::~PooledSessionImpl()
33{
34 try
35 {
36 close();
37 }
38 catch (...)
39 {
40 poco_unexpected();
41 }
42}
43
44
45StatementImpl::Ptr PooledSessionImpl::createStatementImpl()
46{
47 return access()->createStatementImpl();
48}
49
50
51void PooledSessionImpl::begin()
52{
53 return access()->begin();
54}
55
56
57void PooledSessionImpl::commit()
58{
59 return access()->commit();
60}
61
62
63bool PooledSessionImpl::isConnected() const
64{
65 return access()->isConnected();
66}
67
68
69void PooledSessionImpl::setConnectionTimeout(std::size_t timeout)
70{
71 return access()->setConnectionTimeout(timeout);
72}
73
74
75std::size_t PooledSessionImpl::getConnectionTimeout() const
76{
77 return access()->getConnectionTimeout();
78}
79
80
81bool PooledSessionImpl::canTransact() const
82{
83 return access()->canTransact();
84}
85
86
87bool PooledSessionImpl::isTransaction() const
88{
89 return access()->isTransaction();
90}
91
92
93void PooledSessionImpl::setTransactionIsolation(Poco::UInt32 ti)
94{
95 access()->setTransactionIsolation(ti);
96}
97
98
99Poco::UInt32 PooledSessionImpl::getTransactionIsolation() const
100{
101 return access()->getTransactionIsolation();
102}
103
104
105bool PooledSessionImpl::hasTransactionIsolation(Poco::UInt32 ti) const
106{
107 return access()->hasTransactionIsolation(ti);
108}
109
110
111bool PooledSessionImpl::isTransactionIsolation(Poco::UInt32 ti) const
112{
113 return access()->isTransactionIsolation(ti);
114}
115
116
117void PooledSessionImpl::rollback()
118{
119 return access()->rollback();
120}
121
122
123void PooledSessionImpl::open(const std::string& connect)
124{
125 access()->open(connect);
126}
127
128
129void PooledSessionImpl::putBack()
130{
131 if (_pHolder)
132 {
133 _pHolder->owner().putBack(_pHolder);
134 _pHolder = nullptr;
135 }
136}
137
138
139void 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
160void PooledSessionImpl::reset()
161{
162 access()->reset();
163}
164
165
166const std::string& PooledSessionImpl::connectorName() const
167{
168 return access()->connectorName();
169}
170
171
172void PooledSessionImpl::setFeature(const std::string& name, bool state)
173{
174 access()->setFeature(name, state);
175}
176
177
178bool PooledSessionImpl::getFeature(const std::string& name) const
179{
180 return access()->getFeature(name);
181}
182
183
184void PooledSessionImpl::setProperty(const std::string& name, const Poco::Any& value)
185{
186 access()->setProperty(name, value);
187}
188
189
190Poco::Any PooledSessionImpl::getProperty(const std::string& name) const
191{
192 return access()->getProperty(name);
193}
194
195
196SessionImpl::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