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/client_session-fwd.hpp> // IWYU pragma: export
18
19//
20
21#include <mongocxx/v1/client_session.hpp> // IWYU pragma: export
22
23#include <cstdint>
24#include <functional>
25#include <memory> // IWYU pragma: keep: backward compatibility, to be removed.
26
27#include <mongocxx/bulk_write-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
29#include <mongocxx/collection-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
30#include <mongocxx/database-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
31#include <mongocxx/index_view-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
32#include <mongocxx/search_index_view-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
33
36#include <bsoncxx/types.hpp>
37
40
42
43namespace mongocxx {
44namespace v_noabi {
45
58class client_session {
59 private:
60 v1::client_session _session;
61 v_noabi::client* _client;
63
64 public:
65 using transaction_state = v1::client_session::transaction_state;
66
70 v_noabi::client const& client() const noexcept {
71 return *_client;
72 }
73
77 options::client_session const& options() const noexcept {
78 return _options;
79 }
80
86 return _session.id();
87 }
88
96 return _session.cluster_time();
97 }
98
105 return bsoncxx::v_noabi::from_v1(_session.operation_time());
106 }
107
112 std::uint32_t server_id() const noexcept {
113 return _session.server_id();
114 }
115
119 transaction_state get_transaction_state() const noexcept {
120 return _session.get_transaction_state();
121 }
122
126 bool get_dirty() const noexcept {
127 return _session.get_dirty();
128 }
129
141
153
166
175
183
187 using with_transaction_cb = std::function<void MONGOCXX_ABI_CDECL(client_session*)>;
188
219
220 class internal;
221
222 private:
224};
225
226} // namespace v_noabi
227} // namespace mongocxx
228
230
A polyfill for std::optional<T>.
Definition optional.hpp:799
A read-only, non-owning view of a BSON document.
Definition view.hpp:40
A MongoDB client session.
Definition client_session.hpp:48
transaction_state
The state of an associated transaction.
Definition client_session.hpp:61
Supports MongoDB client session operations.
Definition client_session.hpp:58
std::function< void(client_session *)> with_transaction_cb
Represents a callback invoked within a transaction.
Definition client_session.hpp:187
bsoncxx::v_noabi::document::view cluster_time() const noexcept
Get the session's clusterTime, as a BSON document. This is an opaque value suitable for passing to ad...
Definition client_session.hpp:95
transaction_state get_transaction_state() const noexcept
Returns the current transaction state for this session.
Definition client_session.hpp:119
bsoncxx::v_noabi::document::view id() const noexcept
Get the server-side "logical session ID" associated with this session, as a BSON document....
Definition client_session.hpp:85
bsoncxx::v_noabi::types::b_timestamp operation_time() const noexcept
Get the session's operationTime, as a BSON timestamp. This is an opaque value suitable for passing to...
Definition client_session.hpp:104
bool get_dirty() const noexcept
Returns whether or not this session is dirty.
Definition client_session.hpp:126
void with_transaction(with_transaction_cb cb, v_noabi::options::transaction opts={})
Helper to run a user-provided callback within a transaction.
void abort_transaction()
Aborts a transaction on the current client session.
std::uint32_t server_id() const noexcept
Get the server_id the session is pinned to. The server_id is zero if the session is not pinned to a s...
Definition client_session.hpp:112
void advance_cluster_time(bsoncxx::v_noabi::document::view const &cluster_time)
Advance the cluster time for a session. Has an effect only if the new cluster time is greater than th...
Definition client_session.hpp:138
options::client_session const & options() const noexcept
Gets the options this session was created with.
Definition client_session.hpp:77
void advance_operation_time(bsoncxx::v_noabi::types::b_timestamp const &operation_time)
Advance the session's operation time, expressed as a BSON timestamp. Has an effect only if the new op...
Definition client_session.hpp:150
void commit_transaction()
Commits a transaction on the current client session.
void start_transaction(bsoncxx::v_noabi::stdx::optional< v_noabi::options::transaction > const &transaction_opts={})
Starts a transaction on the current client session.
v_noabi::client const & client() const noexcept
Gets the client that started this session.
Definition client_session.hpp:70
A client connection to a MongoDB server.
Definition client.hpp:76
Used by client sessions.
Definition client_session.hpp:40
Used by MongoDB transaction operations.
Definition transaction.hpp:43
Declares mongocxx::v_noabi::index_view.
#define MONGOCXX_ABI_CDECL
Expands to __cdecl when built with MSVC on Windows.
Definition export.hpp:49
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition export.hpp:52
The mongocxx v_noabi macro guard postlude header.
The mongocxx v_noabi macro guard prelude header.
v1::element::view to_v1(v_noabi::array::element const &v)
Convert to the bsoncxx::v1 equivalent of v.
Definition element.hpp:132
v_noabi::array::value from_v1(v1::array::value const &v)
Convert from the bsoncxx::v1 equivalent of v.
Definition value.hpp:267
Declares entities representing options to use with various commands.
Declares entities whose ABI stability is NOT guaranteed.
The top-level namespace within which all mongocxx library entities are declared.
Declares mongocxx::v_noabi::search_index_view.
A BSON replication timestamp value.
Definition types.hpp:601
Provides mongocxx::v_noabi::options::transaction.
Provides entities used to represent BSON types.
Provides mongocxx::v1::client_session.
Provides bsoncxx::v_noabi::document::view.
Provides std::optional-related polyfills for library API usage.
Declares mongocxx::v_noabi::bulk_write.
Declares mongocxx::v_noabi::client.
Declares mongocxx::v_noabi::client_session.
Declares mongocxx::v_noabi::collection.
Declares mongocxx::v_noabi::database.
Provides mongocxx::v_noabi::options::client_session.