Loading...
Searching...
No Matches
client_session.hpp
Go to the documentation of this file.
// Copyright 2009-present MongoDB, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <mongocxx/options/client_session-fwd.hpp> // IWYU pragma: export
//
#include <mongocxx/v1/client_session.hpp> // IWYU pragma: export
#include <utility>
#include <mongocxx/client_session-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <bsoncxx/stdx/optional.hpp>
#include <mongocxx/options/transaction.hpp>
#include <mongocxx/config/prelude.hpp>
namespace mongocxx {
namespace v_noabi {
namespace options {
class client_session {
public:
client_session() = default;
/* explicit(false) */ client_session(v1::client_session::options const& opts)
: _causal_consistency{opts.causal_consistency()},
_snapshot{opts.snapshot()},
_default_transaction_opts{opts.default_transaction_opts()} {}
explicit operator v1::client_session::options() const {
using mongocxx::v_noabi::to_v1;
v1::client_session::options ret;
if (_causal_consistency) {
ret.causal_consistency(*_causal_consistency);
}
if (_snapshot) {
ret.snapshot(*_snapshot);
}
if (_default_transaction_opts) {
ret.default_transaction_opts(to_v1(*_default_transaction_opts));
}
return ret;
}
client_session& causal_consistency(bool causal_consistency) noexcept {
_causal_consistency = causal_consistency;
return *this;
}
bool causal_consistency() const noexcept {
return _causal_consistency.value_or(true);
}
client_session& snapshot(bool enable_snapshot_reads) noexcept {
_snapshot = enable_snapshot_reads;
return *this;
}
bool snapshot() const noexcept {
return _snapshot.value_or(false);
}
client_session& default_transaction_opts(transaction default_transaction_opts) {
_default_transaction_opts = std::move(default_transaction_opts);
return *this;
}
bsoncxx::v_noabi::stdx::optional<transaction> const& default_transaction_opts() const {
return _default_transaction_opts;
}
private:
bsoncxx::v_noabi::stdx::optional<bool> _causal_consistency;
bsoncxx::v_noabi::stdx::optional<bool> _snapshot;
bsoncxx::v_noabi::stdx::optional<transaction> _default_transaction_opts;
};
} // namespace options
} // namespace v_noabi
} // namespace mongocxx
namespace mongocxx {
namespace v_noabi {
inline v_noabi::options::client_session from_v1(v1::client_session::options v) {
return {v};
}
inline v1::client_session::options to_v1(v_noabi::options::client_session v) {
return v1::client_session::options{v};
}
} // namespace v_noabi
} // namespace mongocxx
#include <mongocxx/config/postlude.hpp>
bsoncxx::v1::stdx::optional
A polyfill for std::optional<T>.
Definition optional.hpp:799
mongocxx::options::client_session::client_session
client_session()=default
Default initialization.
mongocxx::v1::client_session::options
Options for mongocxx::v1::client_session.
Definition client_session.hpp:279
mongocxx::v1::client_session::options::default_transaction_opts
options & default_transaction_opts(v1::transaction_options const &v)
Set the "defaultTransactionOptions" field.
mongocxx::v1::client_session::options::snapshot
options & snapshot(bool v)
Set the "snapshot" field.
mongocxx::v1::client_session::options::causal_consistency
options & causal_consistency(bool v)
Set the "causalConsistency" field.
mongocxx::v_noabi::options::client_session
Used by client sessions.
Definition client_session.hpp:40
mongocxx::v_noabi::options::client_session::snapshot
client_session & snapshot(bool enable_snapshot_reads) noexcept
Sets the read concern "snapshot" (not enabled by default).
Definition client_session.hpp:123
mongocxx::v_noabi::options::client_session::client_session
client_session(v1::client_session::options const &opts)
Construct with the mongocxx::v1 equivalent.
Definition client_session.hpp:50
mongocxx::v_noabi::options::client_session::default_transaction_opts
client_session & default_transaction_opts(transaction default_transaction_opts)
Sets the default transaction options.
Definition client_session.hpp:145
mongocxx::v_noabi::options::client_session::causal_consistency
client_session & causal_consistency(bool causal_consistency) noexcept
Sets the causal_consistency option.
Definition client_session.hpp:96
mongocxx::v_noabi::options::client_session::client_session
client_session()=default
Default initialization.
mongocxx::v_noabi::options::client_session::causal_consistency
bool causal_consistency() const noexcept
Gets the value of the causal_consistency option.
Definition client_session.hpp:105
mongocxx::v_noabi::options::client_session::snapshot
bool snapshot() const noexcept
Gets the value of the snapshot_reads option.
Definition client_session.hpp:131
mongocxx::v_noabi::options::client_session::default_transaction_opts
bsoncxx::v_noabi::stdx::optional< transaction > const & default_transaction_opts() const
Gets the current default transaction options.
Definition client_session.hpp:155
mongocxx::v_noabi::options::transaction
Used by MongoDB transaction operations.
Definition transaction.hpp:43
postlude.hpp
The mongocxx v_noabi macro guard postlude header.
prelude.hpp
The mongocxx v_noabi macro guard prelude header.
mongocxx::v_noabi::options
Declares entities representing options to use with various commands.
mongocxx::v_noabi
Declares entities whose ABI stability is NOT guaranteed.
mongocxx::v_noabi::to_v1
v1::bulk_write to_v1(v_noabi::bulk_write v)
Convert to the mongocxx::v1 equivalent of v.
Definition bulk_write.hpp:162
mongocxx::v_noabi::from_v1
v_noabi::bulk_write from_v1(v1::bulk_write v)
Convert to the mongocxx::v_noabi equivalent of v.
Definition bulk_write.hpp:155
mongocxx
The top-level namespace within which all mongocxx library entities are declared.
transaction.hpp
Provides mongocxx::v_noabi::options::transaction.
client_session.hpp
Provides mongocxx::v1::client_session.
optional.hpp
Provides std::optional-related polyfills for library API usage.
client_session-fwd.hpp
Declares mongocxx::v_noabi::client_session.
client_session-fwd.hpp
Declares mongocxx::v_noabi::options::client.