client_session.hpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2017-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 <bsoncxx/stdx/optional.hpp>
  16. #include <mongocxx/options/transaction.hpp>
  17. #include <mongocxx/stdx.hpp>
  18. #include <mongocxx/config/prelude.hpp>
  19. namespace mongocxx {
  20. MONGOCXX_INLINE_NAMESPACE_BEGIN
  21. namespace options {
  22. ///
  23. /// Class representing the optional arguments to mongocxx::client::start_session.
  24. ///
  25. class MONGOCXX_API client_session {
  26. public:
  27. ///
  28. /// Sets the causal_consistency option.
  29. ///
  30. /// If true (the default), each operation in the session will be causally ordered after the
  31. /// previous read or write operation. Set to false to disable causal consistency.
  32. ///
  33. /// Unacknowledged writes are not causally consistent. If you execute a write operation with an
  34. /// unacknowledged write concern (a mongocxx::write_concern with
  35. /// mongocxx::write_concern::acknowledge_level of @c k_unacknowledged), the write does not
  36. /// participate in causal consistency.
  37. ///
  38. /// @return
  39. /// A reference to the object on which this member function is being called. This facilitates
  40. /// method chaining.
  41. ///
  42. /// @see
  43. /// https://docs.mongodb.com/manual/core/read-isolation-consistency-recency/#causal-consistency
  44. ///
  45. client_session& causal_consistency(bool causal_consistency) noexcept;
  46. ///
  47. /// Gets the current value of the causal_consistency option.
  48. ///
  49. bool causal_consistency() const noexcept;
  50. ///
  51. /// Sets the default transaction options.
  52. ///
  53. /// @param default_transaction_opts
  54. /// The default transaction options.
  55. ///
  56. /// @return
  57. /// A reference to the object on which this member function is being called. This facilitates
  58. /// method chaining.
  59. ///
  60. client_session& default_transaction_opts(transaction default_transaction_opts);
  61. ///
  62. /// Gets the current default transaction options.
  63. ///
  64. /// @return The default transaction options.
  65. ///
  66. const stdx::optional<transaction>& default_transaction_opts() const;
  67. private:
  68. bool _causal_consistency = true;
  69. stdx::optional<transaction> _default_transaction_opts;
  70. };
  71. } // namespace options
  72. MONGOCXX_INLINE_NAMESPACE_END
  73. } // namespace mongocxx
  74. #include <mongocxx/config/postlude.hpp>