1//
2// PooledSessionImpl.cpp
3//
4// Library: Data
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/Data/PooledSessionImpl.h"
16#include "Poco/Data/DataException.h"
17#include "Poco/Data/SessionPool.h"
18
19
20namespace Poco {
21namespace Data {
22
23
24PooledSessionImpl::PooledSessionImpl(PooledSessionHolder* pHolder):
25 SessionImpl(pHolder->session()->connectionString(),
26 pHolder->session()->getLoginTimeout()),
27 _pHolder(pHolder, true)
28{
29}
30
31
32PooledSessionImpl::~PooledSessionImpl()
33{
34 try
35 {
36 close();
37 }
38 catch (...)
39 {
40 poco_unexpected();
41 }
42}
43
44
45StatementImpl* 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()
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()
76{
77 return access()->getConnectionTimeout();
78}
79
80
81bool PooledSessionImpl::canTransact()
82{
83 return access()->canTransact();
84}
85
86
87bool PooledSessionImpl::isTransaction()
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()
100{
101 return access()->getTransactionIsolation();
102}
103
104
105bool PooledSessionImpl::hasTransactionIsolation(Poco::UInt32 ti)
106{
107 return access()->hasTransactionIsolation(ti);
108}
109
110
111bool PooledSessionImpl::isTransactionIsolation(Poco::UInt32 ti)
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::close()
130{
131 if (_pHolder)
132 {
133 if (isTransaction())
134 {
135 try
136 {
137 rollback();
138 }
139 catch (...)
140 {
141 // Something's wrong with the session. Get rid of it.
142 access()->close();
143 }
144 }
145 _pHolder->owner().putBack(_pHolder);
146 _pHolder = 0;
147 }
148}
149
150
151const std::string& PooledSessionImpl::connectorName() const
152{
153 return access()->connectorName();
154}
155
156
157void PooledSessionImpl::setFeature(const std::string& name, bool state)
158{
159 access()->setFeature(name, state);
160}
161
162
163bool PooledSessionImpl::getFeature(const std::string& name)
164{
165 return access()->getFeature(name);
166}
167
168
169void PooledSessionImpl::setProperty(const std::string& name, const Poco::Any& value)
170{
171 access()->setProperty(name, value);
172}
173
174
175Poco::Any PooledSessionImpl::getProperty(const std::string& name)
176{
177 return access()->getProperty(name);
178}
179
180
181SessionImpl* PooledSessionImpl::access() const
182{
183 if (_pHolder)
184 {
185 _pHolder->access();
186 return impl();
187 }
188 else throw SessionUnavailableException();
189}
190
191
192} } // namespace Poco::Data
193