MongoDB C++ Driver mongocxx-3.11.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 <functional>
18#include <memory>
19
27
30
32
34
35namespace mongocxx {
36namespace v_noabi {
37
49 public:
50 enum class transaction_state {
51 k_transaction_none,
52 k_transaction_starting,
53 k_transaction_in_progress,
54 k_transaction_committed,
55 k_transaction_aborted,
56 };
57
62
67
68 client_session(const client_session&) = delete;
69 MONGOCXX_ABI_EXPORT_CDECL(client_session&) operator=(const client_session&) = delete;
70
75
79 MONGOCXX_ABI_EXPORT_CDECL(const mongocxx::v_noabi::client&) client() const noexcept;
80
85
90 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::document::view) id() const noexcept;
91
98 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::document::view) cluster_time() const noexcept;
99
105 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::types::b_timestamp) operation_time() const noexcept;
106
111 MONGOCXX_ABI_EXPORT_CDECL(std::uint32_t) server_id() const noexcept;
112
116 MONGOCXX_ABI_EXPORT_CDECL(transaction_state) get_transaction_state() const noexcept;
117
121 MONGOCXX_ABI_EXPORT_CDECL(bool) get_dirty() const noexcept;
122
132 advance_cluster_time(const bsoncxx::v_noabi::document::view& cluster_time);
133
143 advance_operation_time(const bsoncxx::v_noabi::types::b_timestamp& operation_time);
144
156 start_transaction(const stdx::optional<options::transaction>& transaction_opts = {});
157
166
174
179
202 with_transaction(with_transaction_cb cb, options::transaction opts = {});
203
204 private:
205 friend ::mongocxx::v_noabi::bulk_write;
206 friend ::mongocxx::v_noabi::client;
207 friend ::mongocxx::v_noabi::collection;
208 friend ::mongocxx::v_noabi::database;
209 friend ::mongocxx::v_noabi::index_view;
210 friend ::mongocxx::v_noabi::search_index_view;
211
212 class impl;
213
215
216 impl& _get_impl();
217 const impl& _get_impl() const;
218
219 std::unique_ptr<impl> _impl;
220};
221
222} // namespace v_noabi
223} // namespace mongocxx
224
226
Declares mongocxx::v_noabi::bulk_write.
Use a session for a sequence of operations, optionally with either causal consistency or snapshots.
Definition client_session.hpp:48
void advance_operation_time(const bsoncxx::v_noabi::types::b_timestamp &operation_time)
Advance the session's operation time, expressed as a BSON timestamp. Has an effect only if the new op...
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...
transaction_state get_transaction_state() const noexcept
Returns the current transaction state for this session.
void advance_cluster_time(const bsoncxx::v_noabi::document::view &cluster_time)
Advance the cluster time for a session. Has an effect only if the new cluster time is greater than th...
void with_transaction(with_transaction_cb cb, options::transaction opts={})
Helper to run a user-provided callback within a transaction.
const options::client_session & options() const noexcept
Gets the options this session was created with.
client_session(client_session &&) noexcept
Move constructs a session.
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...
std::function< void MONGOCXX_ABI_CDECL(client_session *)> with_transaction_cb
Represents a callback invoked within a transaction.
Definition client_session.hpp:178
bool get_dirty() const noexcept
Returns whether or not this session is dirty.
void start_transaction(const stdx::optional< options::transaction > &transaction_opts={})
Starts a transaction on the current client session.
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...
void commit_transaction()
Commits a transaction on the current client session.
Class representing a client connection to MongoDB.
Definition client.hpp:62
Class representing the optional arguments to mongocxx::v_noabi::client::start_session.
Definition client_session.hpp:34
Declares mongocxx::v_noabi::client.
Declares mongocxx::v_noabi::client_session.
Declares mongocxx::v_noabi::collection.
Declares mongocxx::v_noabi::database.
Provides bsoncxx::v_noabi::document::view.
#define MONGOCXX_ABI_CDECL
Expands to __cdecl when built with MSVC on Windows.
Definition fwd.hpp:214
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition fwd.hpp:222
Declares mongocxx::v_noabi::index_view.
The mongocxx macro guard postlude header.
The mongocxx macro guard prelude header.
The top-level namespace within which all bsoncxx library entities are declared.
The top-level namespace within which all mongocxx library entities are declared.
The top-level namespace reserved for the C++ standard library.
Provides std::optional-related polyfills for library API usage.
Provides mongocxx::v_noabi::options::client_session.
Declares mongocxx::v_noabi::search_index_view.