MongoDB C++ Driver 4.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
51 public:
52 enum class transaction_state {
53 k_transaction_none,
54 k_transaction_starting,
55 k_transaction_in_progress,
56 k_transaction_committed,
57 k_transaction_aborted,
58 };
59
64
69
70 client_session(client_session const&) = delete;
71 MONGOCXX_ABI_EXPORT_CDECL(client_session&) operator=(client_session const&) = delete;
72
77
82
87
92 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::document::view) id() const noexcept;
93
100 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::document::view) cluster_time() const noexcept;
101
107 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::types::b_timestamp) operation_time() const noexcept;
108
113 MONGOCXX_ABI_EXPORT_CDECL(std::uint32_t) server_id() const noexcept;
114
118 MONGOCXX_ABI_EXPORT_CDECL(transaction_state) get_transaction_state() const noexcept;
119
123 MONGOCXX_ABI_EXPORT_CDECL(bool) get_dirty() const noexcept;
124
135
146
158 start_transaction(bsoncxx::v_noabi::stdx::optional<options::transaction> const& transaction_opts = {});
159
168
176
181
212 with_transaction(with_transaction_cb cb, options::transaction opts = {});
213
214 private:
215 friend ::mongocxx::v_noabi::bulk_write;
216 friend ::mongocxx::v_noabi::client;
217 friend ::mongocxx::v_noabi::collection;
218 friend ::mongocxx::v_noabi::database;
219 friend ::mongocxx::v_noabi::index_view;
220 friend ::mongocxx::v_noabi::search_index_view;
221
222 class impl;
223
225
226 impl& _get_impl();
227 impl const& _get_impl() const;
228
229 std::unique_ptr<impl> _impl;
230};
231
232} // namespace v_noabi
233} // namespace mongocxx
234
236
Declares mongocxx::v_noabi::bulk_write.
client_session(client_session &&) noexcept
Move constructs a session.
std::function< void(client_session *)> with_transaction_cb
Represents a callback invoked within a transaction.
Definition client_session.hpp:180
void start_transaction(bsoncxx::v_noabi::stdx::optional< options::transaction > const &transaction_opts={})
Starts a transaction on the current client session.
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...
mongocxx::v_noabi::client const & client() const noexcept
Gets the client that started this session.
transaction_state get_transaction_state() const noexcept
Returns the current transaction state for this session.
void with_transaction(with_transaction_cb cb, options::transaction opts={})
Helper to run a user-provided callback within a transaction.
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...
bool get_dirty() const noexcept
Returns whether or not this session is dirty.
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 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...
options::client_session const & options() const noexcept
Gets the options this session was created with.
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...
void commit_transaction()
Commits a transaction on the current client session.
A client connection to a MongoDB server.
Definition client.hpp:61
Used by client sessions.
Definition client_session.hpp:33
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.
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.
The top-level namespace within which all bsoncxx library entities are declared.
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.
Provides mongocxx::v_noabi::options::client_session.
Declares mongocxx::v_noabi::search_index_view.
Provides std::optional-related polyfills for library API usage.