transaction.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // Copyright 2018-present MongoDB Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #include <chrono>
  16. #include <memory>
  17. #include <bsoncxx/stdx/optional.hpp>
  18. #include <mongocxx/stdx.hpp>
  19. #include <mongocxx/config/prelude.hpp>
  20. namespace mongocxx {
  21. MONGOCXX_INLINE_NAMESPACE_BEGIN
  22. class client_session;
  23. class read_concern;
  24. class write_concern;
  25. class read_preference;
  26. namespace options {
  27. ///
  28. /// Class representing the optional arguments for a transaction.
  29. ///
  30. class MONGOCXX_API transaction {
  31. public:
  32. transaction();
  33. ///
  34. /// Copy constructs transaction options.
  35. ///
  36. transaction(const transaction&);
  37. ///
  38. /// Copy assigns transaction options.
  39. ///
  40. transaction& operator=(const transaction&);
  41. ///
  42. /// Move constructs transaction options.
  43. ///
  44. transaction(transaction&&) noexcept;
  45. ///
  46. /// Move assigns transaction options.
  47. ///
  48. transaction& operator=(transaction&&) noexcept;
  49. ///
  50. /// Destroys the transaction options.
  51. ///
  52. ~transaction() noexcept;
  53. ///
  54. /// Sets the transaction read concern.
  55. ///
  56. /// @param rc
  57. /// The read concern.
  58. ///
  59. /// @return
  60. /// A reference to the object on which this member function is being called. This facilitates
  61. /// method chaining.
  62. ///
  63. transaction& read_concern(const class read_concern& rc);
  64. ///
  65. /// Gets the current transaction read concern.
  66. ///
  67. /// @return
  68. /// An optional containing the read concern. If the read concern has not been set, a
  69. /// disengaged optional is returned.
  70. stdx::optional<class read_concern> read_concern() const;
  71. ///
  72. /// Sets the transaction write concern.
  73. ///
  74. /// @param wc
  75. /// The write concern.
  76. ///
  77. /// @return
  78. /// A reference to the object on which this member function is being called. This facilitates
  79. /// method chaining.
  80. ///
  81. transaction& write_concern(const class write_concern& wc);
  82. ///
  83. /// Gets the current transaction write concern.
  84. ///
  85. /// @return The write concern.
  86. ///
  87. /// @return
  88. /// An optional containing the write concern. If the write concern has not been set, a
  89. /// disengaged optional is returned.
  90. stdx::optional<class write_concern> write_concern() const;
  91. ///
  92. /// Sets the transaction read preference.
  93. ///
  94. /// @param rp
  95. /// The read preference.
  96. ///
  97. /// @return
  98. /// A reference to the object on which this member function is being called. This facilitates
  99. /// method chaining.
  100. ///
  101. transaction& read_preference(const class read_preference& rp);
  102. ///
  103. /// Gets the current transaction read preference.
  104. ///
  105. /// @return
  106. /// An optional containing the read preference. If the read preference has not been set, a
  107. /// disengaged optional is returned.
  108. stdx::optional<class read_preference> read_preference() const;
  109. ///
  110. /// Sets the transaction's max commit time, in milliseconds.
  111. ///
  112. /// @param ms
  113. /// The max commit time in milliseconds.
  114. ///
  115. /// @return
  116. /// A reference to the object on which this function is being called.
  117. ///
  118. transaction& max_commit_time_ms(std::chrono::milliseconds ms);
  119. ///
  120. /// Gets the current transaction commit time, in milliseconds.
  121. ///
  122. /// @return
  123. /// An optional containing the timeout. If the max commit time has not been set,
  124. /// a disengaged optional is returned.
  125. ///
  126. stdx::optional<std::chrono::milliseconds> max_commit_time_ms() const;
  127. private:
  128. friend class ::mongocxx::client_session;
  129. class MONGOCXX_PRIVATE impl;
  130. MONGOCXX_PRIVATE impl& _get_impl();
  131. MONGOCXX_PRIVATE const impl& _get_impl() const;
  132. std::unique_ptr<impl> _impl;
  133. };
  134. } // namespace options
  135. MONGOCXX_INLINE_NAMESPACE_END
  136. } // namespace mongocxx
  137. #include <mongocxx/config/postlude.hpp>