PooledSessionImpl.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. //
  2. // PooledSessionImpl.cpp
  3. //
  4. // $Id: //poco/Main/Data/src/PooledSessionImpl.cpp#3 $
  5. //
  6. // Library: Data
  7. // Package: SessionPooling
  8. // Module: PooledSessionImpl
  9. //
  10. // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // Permission is hereby granted, free of charge, to any person or organization
  14. // obtaining a copy of the software and accompanying documentation covered by
  15. // this license (the "Software") to use, reproduce, display, distribute,
  16. // execute, and transmit the Software, and to prepare derivative works of the
  17. // Software, and to permit third-parties to whom the Software is furnished to
  18. // do so, all subject to the following:
  19. //
  20. // The copyright notices in the Software and this entire statement, including
  21. // the above license grant, this restriction and the following disclaimer,
  22. // must be included in all copies of the Software, in whole or in part, and
  23. // all derivative works of the Software, unless such copies or derivative
  24. // works are solely in the form of machine-executable object code generated by
  25. // a source language processor.
  26. //
  27. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  28. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  29. // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
  30. // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
  31. // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
  32. // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  33. // DEALINGS IN THE SOFTWARE.
  34. //
  35. #include "Poco/Data/PooledSessionImpl.h"
  36. #include "Poco/Data/DataException.h"
  37. #include "Poco/Data/SessionPool.h"
  38. namespace Poco {
  39. namespace Data {
  40. PooledSessionImpl::PooledSessionImpl(PooledSessionHolder* pHolder):
  41. SessionImpl(pHolder->session()->connectionString()),
  42. _pHolder(pHolder, true)
  43. {
  44. }
  45. PooledSessionImpl::~PooledSessionImpl()
  46. {
  47. close();
  48. }
  49. StatementImpl* PooledSessionImpl::createStatementImpl()
  50. {
  51. return access()->createStatementImpl();
  52. }
  53. void PooledSessionImpl::begin()
  54. {
  55. return access()->begin();
  56. }
  57. void PooledSessionImpl::commit()
  58. {
  59. return access()->commit();
  60. }
  61. bool PooledSessionImpl::isConnected()
  62. {
  63. return access()->isConnected();
  64. }
  65. bool PooledSessionImpl::canTransact()
  66. {
  67. return access()->canTransact();
  68. }
  69. bool PooledSessionImpl::isTransaction()
  70. {
  71. return access()->isTransaction();
  72. }
  73. void PooledSessionImpl::setTransactionIsolation(Poco::UInt32 ti)
  74. {
  75. access()->setTransactionIsolation(ti);
  76. }
  77. Poco::UInt32 PooledSessionImpl::getTransactionIsolation()
  78. {
  79. return access()->getTransactionIsolation();
  80. }
  81. bool PooledSessionImpl::hasTransactionIsolation(Poco::UInt32 ti)
  82. {
  83. return access()->hasTransactionIsolation(ti);
  84. }
  85. bool PooledSessionImpl::isTransactionIsolation(Poco::UInt32 ti)
  86. {
  87. return access()->isTransactionIsolation(ti);
  88. }
  89. void PooledSessionImpl::rollback()
  90. {
  91. return access()->rollback();
  92. }
  93. void PooledSessionImpl::close()
  94. {
  95. if (_pHolder)
  96. {
  97. if (isTransaction())
  98. {
  99. try
  100. {
  101. rollback();
  102. }
  103. catch (...)
  104. {
  105. // Something's wrong with the session. Get rid of it.
  106. access()->close();
  107. }
  108. }
  109. _pHolder->owner().putBack(_pHolder);
  110. _pHolder = 0;
  111. }
  112. }
  113. const std::string& PooledSessionImpl::connectorName()
  114. {
  115. return access()->connectorName();
  116. }
  117. void PooledSessionImpl::setFeature(const std::string& name, bool state)
  118. {
  119. access()->setFeature(name, state);
  120. }
  121. bool PooledSessionImpl::getFeature(const std::string& name)
  122. {
  123. return access()->getFeature(name);
  124. }
  125. void PooledSessionImpl::setProperty(const std::string& name, const Poco::Any& value)
  126. {
  127. access()->setProperty(name, value);
  128. }
  129. Poco::Any PooledSessionImpl::getProperty(const std::string& name)
  130. {
  131. return access()->getProperty(name);
  132. }
  133. SessionImpl* PooledSessionImpl::access()
  134. {
  135. if (_pHolder)
  136. {
  137. _pHolder->access();
  138. return impl();
  139. }
  140. else throw SessionUnavailableException();
  141. }
  142. } } // namespace Poco::Data