PooledSessionImpl.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. #include "Poco/Data/PooledSessionImpl.h"
  14. #include "Poco/Data/DataException.h"
  15. #include "Poco/Data/SessionPool.h"
  16. namespace Poco {
  17. namespace Data {
  18. PooledSessionImpl::PooledSessionImpl(PooledSessionHolder* pHolder):
  19. SessionImpl(pHolder->session()->connectionString(),
  20. pHolder->session()->getLoginTimeout()),
  21. _pHolder(pHolder, true)
  22. {
  23. }
  24. PooledSessionImpl::~PooledSessionImpl()
  25. {
  26. try
  27. {
  28. close();
  29. }
  30. catch (...)
  31. {
  32. poco_unexpected();
  33. }
  34. }
  35. StatementImpl::Ptr PooledSessionImpl::createStatementImpl()
  36. {
  37. return access()->createStatementImpl();
  38. }
  39. void PooledSessionImpl::begin()
  40. {
  41. return access()->begin();
  42. }
  43. void PooledSessionImpl::commit()
  44. {
  45. return access()->commit();
  46. }
  47. bool PooledSessionImpl::isConnected() const
  48. {
  49. return access()->isConnected();
  50. }
  51. bool PooledSessionImpl::isGood() const
  52. {
  53. return access()->isGood();
  54. }
  55. void PooledSessionImpl::setConnectionTimeout(std::size_t timeout)
  56. {
  57. return access()->setConnectionTimeout(timeout);
  58. }
  59. std::size_t PooledSessionImpl::getConnectionTimeout() const
  60. {
  61. return access()->getConnectionTimeout();
  62. }
  63. bool PooledSessionImpl::canTransact() const
  64. {
  65. return access()->canTransact();
  66. }
  67. bool PooledSessionImpl::isTransaction() const
  68. {
  69. return access()->isTransaction();
  70. }
  71. void PooledSessionImpl::setTransactionIsolation(Poco::UInt32 ti)
  72. {
  73. access()->setTransactionIsolation(ti);
  74. }
  75. Poco::UInt32 PooledSessionImpl::getTransactionIsolation() const
  76. {
  77. return access()->getTransactionIsolation();
  78. }
  79. bool PooledSessionImpl::hasTransactionIsolation(Poco::UInt32 ti) const
  80. {
  81. return access()->hasTransactionIsolation(ti);
  82. }
  83. bool PooledSessionImpl::isTransactionIsolation(Poco::UInt32 ti) const
  84. {
  85. return access()->isTransactionIsolation(ti);
  86. }
  87. void PooledSessionImpl::rollback()
  88. {
  89. return access()->rollback();
  90. }
  91. void PooledSessionImpl::open(const std::string& connect)
  92. {
  93. access()->open(connect);
  94. }
  95. void PooledSessionImpl::close()
  96. {
  97. if (_pHolder)
  98. {
  99. if (isTransaction())
  100. {
  101. try
  102. {
  103. rollback();
  104. }
  105. catch (...)
  106. {
  107. // Something's wrong with the session. Get rid of it.
  108. access()->close();
  109. }
  110. }
  111. _pHolder->owner().putBack(_pHolder);
  112. _pHolder = 0;
  113. }
  114. }
  115. void PooledSessionImpl::reset()
  116. {
  117. access()->reset();
  118. }
  119. const std::string& PooledSessionImpl::connectorName() const
  120. {
  121. return access()->connectorName();
  122. }
  123. bool PooledSessionImpl::hasFeature(const std::string& name)
  124. {
  125. return access()->hasFeature(name);
  126. }
  127. void PooledSessionImpl::setFeature(const std::string& name, bool state)
  128. {
  129. access()->setFeature(name, state);
  130. }
  131. bool PooledSessionImpl::getFeature(const std::string& name)
  132. {
  133. return access()->getFeature(name);
  134. }
  135. bool PooledSessionImpl::hasProperty(const std::string& name)
  136. {
  137. return access()->hasProperty(name);
  138. }
  139. void PooledSessionImpl::setProperty(const std::string& name, const Poco::Any& value)
  140. {
  141. access()->setProperty(name, value);
  142. }
  143. Poco::Any PooledSessionImpl::getProperty(const std::string& name)
  144. {
  145. return access()->getProperty(name);
  146. }
  147. SessionImpl* PooledSessionImpl::access() const
  148. {
  149. if (_pHolder)
  150. {
  151. _pHolder->access();
  152. return impl();
  153. }
  154. else throw SessionUnavailableException();
  155. }
  156. } } // namespace Poco::Data