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/v1/client_session-fwd.hpp> // IWYU pragma: export
//
#include <mongocxx/v1/detail/prelude.hpp>
#include <bsoncxx/v1/document/view-fwd.hpp>
#include <bsoncxx/v1/types/view-fwd.hpp>
#include <mongocxx/v1/client-fwd.hpp>
#include <mongocxx/v1/transaction_options-fwd.hpp>
#include <bsoncxx/v1/stdx/optional.hpp>
#include <mongocxx/v1/config/export.hpp>
#include <cstdint>
#include <functional>
namespace mongocxx {
namespace v1 {
class client_session {
private:
class impl;
void* _impl;
public:
class options;
enum class transaction_state {
k_transaction_none,
k_transaction_starting,
k_transaction_in_progress,
k_transaction_committed,
k_transaction_aborted,
};
MONGOCXX_ABI_EXPORT_CDECL() ~client_session();
MONGOCXX_ABI_EXPORT_CDECL() client_session(client_session&& other) noexcept;
MONGOCXX_ABI_EXPORT_CDECL(client_session&) operator=(client_session&& other) noexcept;
client_session(client_session const&) = delete;
client_session& operator=(client_session const&) = delete;
MONGOCXX_ABI_EXPORT_CDECL(v1::client const&) client() const;
MONGOCXX_ABI_EXPORT_CDECL(options) opts() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) id() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) cluster_time() const;
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::types::b_timestamp) operation_time() const;
MONGOCXX_ABI_EXPORT_CDECL(std::uint32_t) server_id() const;
MONGOCXX_ABI_EXPORT_CDECL(transaction_state) get_transaction_state() const;
MONGOCXX_ABI_EXPORT_CDECL(bool) get_dirty() const;
MONGOCXX_ABI_EXPORT_CDECL(void) advance_cluster_time(bsoncxx::v1::document::view v);
MONGOCXX_ABI_EXPORT_CDECL(void) advance_operation_time(bsoncxx::v1::types::b_timestamp v);
MONGOCXX_ABI_EXPORT_CDECL(void) start_transaction(v1::transaction_options const& opts);
MONGOCXX_ABI_EXPORT_CDECL(void) start_transaction();
MONGOCXX_ABI_EXPORT_CDECL(void) commit_transaction();
MONGOCXX_ABI_EXPORT_CDECL(void) abort_transaction();
using with_transaction_cb = std::function<void MONGOCXX_ABI_CDECL(client_session&)>;
MONGOCXX_ABI_EXPORT_CDECL(void) with_transaction(
with_transaction_cb const& fn,
v1::transaction_options const& opts);
MONGOCXX_ABI_EXPORT_CDECL(void) with_transaction(with_transaction_cb const& fn);
class internal;
private:
/* explicit(false) */ client_session(void* impl);
};
class client_session::options {
private:
void* _impl; // mongoc_session_opt_t
public:
MONGOCXX_ABI_EXPORT_CDECL() ~options();
MONGOCXX_ABI_EXPORT_CDECL() options(options&& other) noexcept;
MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options&& other) noexcept;
MONGOCXX_ABI_EXPORT_CDECL() options(options const& other);
MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options const& other);
MONGOCXX_ABI_EXPORT_CDECL() options();
MONGOCXX_ABI_EXPORT_CDECL(options&) causal_consistency(bool v);
MONGOCXX_ABI_EXPORT_CDECL(bool) causal_consistency() const;
MONGOCXX_ABI_EXPORT_CDECL(options&) snapshot(bool v);
MONGOCXX_ABI_EXPORT_CDECL(bool) snapshot() const;
MONGOCXX_ABI_EXPORT_CDECL(options&) default_transaction_opts(v1::transaction_options const& v);
MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<v1::transaction_options>) default_transaction_opts() const;
class internal;
private:
/* explicit(false) */ options(void* impl);
};
} // namespace v1
} // namespace mongocxx
#include <mongocxx/v1/detail/postlude.hpp>
mongocxx::v1::client_session::options
Options for mongocxx::v1::client_session.
Definition client_session.hpp:279
mongocxx::v1::client_session::options::~options
~options()
Destroy this object.
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::options
options(options &&other) noexcept
Move constructor.
mongocxx::v1::client_session::options::causal_consistency
options & causal_consistency(bool v)
Set the "causalConsistency" field.
mongocxx::v1::client_session::cluster_time
bsoncxx::v1::document::view cluster_time() const
Return this session's current "clusterTime" value.
mongocxx::v1::client_session::client_session
client_session(client_session &&other) noexcept
Move constructor.
mongocxx::v1::client_session::advance_operation_time
void advance_operation_time(bsoncxx::v1::types::b_timestamp v)
Advance the "operationTime" value for this session.
mongocxx::v1::client_session::client
v1::client const & client() const
Return the associated client object.
mongocxx::v1::client_session::operation_time
bsoncxx::v1::types::b_timestamp operation_time() const
Return this session's current "operationTime" value.
mongocxx::v1::client_session::start_transaction
void start_transaction(v1::transaction_options const &opts)
Start a new transaction using opts instead of default transaction options.
mongocxx::v1::client_session::server_id
std::uint32_t server_id() const
Return the ID of the current pinned server.
mongocxx::v1::client_session::~client_session
~client_session()
Destroy this object.
mongocxx::v1::client_session::get_transaction_state
transaction_state get_transaction_state() const
Return the current transaction state.
mongocxx::v1::client_session::get_dirty
bool get_dirty() const
Return true when the current session is dirty.
mongocxx::v1::client_session::with_transaction_cb
std::function< void(client_session &)> with_transaction_cb
The callback function to invoke within a standalone transaction.
Definition client_session.hpp:219
mongocxx::v1::client_session::transaction_state
transaction_state
The state of an associated transaction.
Definition client_session.hpp:57
mongocxx::v1::client_session::transaction_state::k_transaction_none
@ k_transaction_none
No associated transaction.
Definition client_session.hpp:61
mongocxx::v1::client_session::transaction_state::k_transaction_in_progress
@ k_transaction_in_progress
The associated transaction is in progress.
Definition client_session.hpp:71
mongocxx::v1::client_session::transaction_state::k_transaction_committed
@ k_transaction_committed
The associated transaction was committed.
Definition client_session.hpp:76
mongocxx::v1::client_session::transaction_state::k_transaction_aborted
@ k_transaction_aborted
The associated transaction was aborted.
Definition client_session.hpp:81
mongocxx::v1::client_session::transaction_state::k_transaction_starting
@ k_transaction_starting
An associated transaction has started.
Definition client_session.hpp:66
mongocxx::v1::client_session::abort_transaction
void abort_transaction()
Abort the current transaction.
mongocxx::v1::client_session::commit_transaction
void commit_transaction()
Commit the current transaction.
mongocxx::v1::client_session::opts
options opts() const
Return the options used to create this client session.
mongocxx::v1::client_session::advance_cluster_time
void advance_cluster_time(bsoncxx::v1::document::view v)
Advance the "clusterTime" value for this session.
mongocxx::v1::client_session::with_transaction
void with_transaction(with_transaction_cb const &fn, v1::transaction_options const &opts)
Start and commit a new standalone transaction using fn.
mongocxx::v1::transaction_options
Options related to a distributed transaction.
Definition transaction_options.hpp:48
export.hpp
Provides macros to control the set of symbols exported in the ABI.
MONGOCXX_ABI_CDECL
#define MONGOCXX_ABI_CDECL
Expands to __cdecl when built with MSVC on Windows.
Definition export.hpp:49
MONGOCXX_ABI_EXPORT_CDECL
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition export.hpp:52
prelude.hpp
The mongocxx v1 macro guard prelude header.
bsoncxx
The top-level namespace within which all bsoncxx library entities are declared.
mongocxx::v1
Declares entities whose ABI stability is guaranteed for documented symbols.
mongocxx
The top-level namespace within which all mongocxx library entities are declared.
transaction_options-fwd.hpp
Declares mongocxx::v1::transaction_options.
client-fwd.hpp
Declares mongocxx::v1::client.
client_session-fwd.hpp
Declares mongocxx::v1::client_session.
view-fwd.hpp
Declares bsoncxx::v1::document::view.
optional.hpp
Provides std::optional-related polyfills for library API usage.
view-fwd.hpp
Declares non-owning, read-only entities representing a BSON type value.