MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
client_session.hpp
Go to the documentation of this file.
1// Copyright 2009-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
15#pragma once
16
17#include <mongocxx/options/client_session-fwd.hpp> // IWYU pragma: export
18
19//
20
21#include <mongocxx/v1/client_session.hpp> // IWYU pragma: export
22
23#include <utility>
24
25#include <mongocxx/client_session-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
26
28
30
32
33namespace mongocxx {
34namespace v_noabi {
35namespace options {
36
41 public:
45 client_session() = default;
46
50 /* explicit(false) */ client_session(v1::client_session::options const& opts)
51 : _causal_consistency{opts.causal_consistency()},
52 _snapshot{opts.snapshot()},
53 _default_transaction_opts{opts.default_transaction_opts()} {}
54
58 explicit operator v1::client_session::options() const {
60
62
63 if (_causal_consistency) {
64 ret.causal_consistency(*_causal_consistency);
65 }
66
67 if (_snapshot) {
68 ret.snapshot(*_snapshot);
69 }
70
71 if (_default_transaction_opts) {
72 ret.default_transaction_opts(to_v1(*_default_transaction_opts));
73 }
74
75 return ret;
76 }
77
97 _causal_consistency = causal_consistency;
98 return *this;
99 }
100
105 bool causal_consistency() const noexcept {
106 return _causal_consistency.value_or(true);
107 }
108
123 client_session& snapshot(bool enable_snapshot_reads) noexcept {
124 _snapshot = enable_snapshot_reads;
125 return *this;
126 }
127
131 bool snapshot() const noexcept {
132 return _snapshot.value_or(false);
133 }
134
146 _default_transaction_opts = std::move(default_transaction_opts);
147 return *this;
148 }
149
156 return _default_transaction_opts;
157 }
158
159 private:
160 bsoncxx::v_noabi::stdx::optional<bool> _causal_consistency;
162 bsoncxx::v_noabi::stdx::optional<transaction> _default_transaction_opts;
163};
164
165} // namespace options
166} // namespace v_noabi
167} // namespace mongocxx
168
169namespace mongocxx {
170namespace v_noabi {
171
178
185
186} // namespace v_noabi
187} // namespace mongocxx
188
190
A polyfill for std::optional<T>.
Definition optional.hpp:799
client_session()=default
Default initialization.
Options for mongocxx::v1::client_session.
Definition client_session.hpp:285
options & default_transaction_opts(v1::transaction_options const &v)
Set the "defaultTransactionOptions" field.
options & snapshot(bool v)
Set the "snapshot" field.
options & causal_consistency(bool v)
Set the "causalConsistency" field.
Used by client sessions.
Definition client_session.hpp:40
client_session & snapshot(bool enable_snapshot_reads) noexcept
Sets the read concern "snapshot" (not enabled by default).
Definition client_session.hpp:123
client_session(v1::client_session::options const &opts)
Construct with the mongocxx::v1 equivalent.
Definition client_session.hpp:50
client_session & default_transaction_opts(transaction default_transaction_opts)
Sets the default transaction options.
Definition client_session.hpp:145
client_session & causal_consistency(bool causal_consistency) noexcept
Sets the causal_consistency option.
Definition client_session.hpp:96
client_session()=default
Default initialization.
bool causal_consistency() const noexcept
Gets the value of the causal_consistency option.
Definition client_session.hpp:105
bool snapshot() const noexcept
Gets the value of the snapshot_reads option.
Definition client_session.hpp:131
bsoncxx::v_noabi::stdx::optional< transaction > const & default_transaction_opts() const
Gets the current default transaction options.
Definition client_session.hpp:155
Used by MongoDB transaction operations.
Definition transaction.hpp:43
The mongocxx v_noabi macro guard postlude header.
The mongocxx v_noabi macro guard prelude header.
Declares entities representing options to use with various commands.
Declares entities whose ABI stability is NOT guaranteed.
v1::bulk_write to_v1(v_noabi::bulk_write v)
Convert to the mongocxx::v1 equivalent of v.
Definition bulk_write.hpp:162
v_noabi::bulk_write from_v1(v1::bulk_write v)
Convert to the mongocxx::v_noabi equivalent of v.
Definition bulk_write.hpp:155
The top-level namespace within which all mongocxx library entities are declared.
Provides mongocxx::v_noabi::options::transaction.
Provides mongocxx::v1::client_session.
Provides std::optional-related polyfills for library API usage.
Declares mongocxx::v_noabi::client_session.
Declares mongocxx::v_noabi::options::client.