MongoDB C++ Driver  mongocxx-3.6.2
All Classes Namespaces Functions Typedefs Enumerations Enumerator Friends Pages
client_session.hpp
1 // Copyright 2017-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 
20 #include <bsoncxx/document/view.hpp>
21 #include <bsoncxx/stdx/optional.hpp>
22 #include <mongocxx/options/client_session.hpp>
23 
24 #include <mongocxx/config/prelude.hpp>
25 
26 namespace mongocxx {
27 MONGOCXX_INLINE_NAMESPACE_BEGIN
28 
29 class client;
30 
39 class MONGOCXX_API client_session {
40  public:
45 
49  client_session& operator=(client_session&&) noexcept;
50 
51  client_session(const client_session&) = delete;
52  client_session& operator=(const client_session&) = delete;
53 
57  ~client_session() noexcept;
58 
62  const class client& client() const noexcept;
63 
67  const options::client_session& options() const noexcept;
68 
73  bsoncxx::document::view id() const noexcept;
74 
81  bsoncxx::document::view cluster_time() const noexcept;
82 
88  bsoncxx::types::b_timestamp operation_time() const noexcept;
89 
93  std::uint32_t server_id() const noexcept;
94 
103  void advance_cluster_time(const bsoncxx::document::view& cluster_time);
104 
113  void advance_operation_time(const bsoncxx::types::b_timestamp& operation_time);
114 
125  void start_transaction(const stdx::optional<options::transaction>& transaction_opts = {});
126 
135 
143 
165  using with_transaction_cb = std::function<void MONGOCXX_CALL(client_session*)>;
166  void with_transaction(with_transaction_cb cb, options::transaction opts = {});
167 
168  private:
169  friend class bulk_write;
170  friend class client;
171  friend class collection;
172  friend class database;
173  friend class index_view;
174 
175  class MONGOCXX_PRIVATE impl;
176 
177  // "class client" distinguishes from client() method above.
178  MONGOCXX_PRIVATE client_session(const class client* client,
179  const options::client_session& options);
180 
181  MONGOCXX_PRIVATE impl& _get_impl();
182  MONGOCXX_PRIVATE const impl& _get_impl() const;
183 
184  std::unique_ptr<impl> _impl;
185 };
186 
187 MONGOCXX_INLINE_NAMESPACE_END
188 } // namespace mongocxx
189 
190 #include <mongocxx/config/postlude.hpp>
191 
mongocxx
Top level namespace for the MongoDB C++ driver.
Definition: bulk_write.hpp:24
bsoncxx
Top level namespace for MongoDB C++ BSON functionality.
Definition: element.hpp:24
mongocxx::options::client_session
Class representing the optional arguments to mongocxx::client::start_session.
Definition: client_session.hpp:30
mongocxx::client_session::with_transaction_cb
std::function< void(client_session *)> with_transaction_cb
Helper to run a user-provided callback within a transaction.
Definition: client_session.hpp:165
mongocxx::client_session::abort_transaction
void abort_transaction()
Aborts a transaction on the current client session.
mongocxx::client
Class representing a client connection to MongoDB.
Definition: client.hpp:58
mongocxx::index_view
Definition: index_view.hpp:32
mongocxx::client_session::client_session
client_session(client_session &&) noexcept
Move constructs a session.
mongocxx::client_session
Use a session for a sequence of operations, optionally with causal consistency.
Definition: client_session.hpp:39
mongocxx::bulk_write
Class representing a batch of write operations that can be sent to the server as a group.
Definition: bulk_write.hpp:43
mongocxx::database
Class representing a MongoDB database.
Definition: database.hpp:43
mongocxx::options::transaction
Class representing the optional arguments for a transaction.
Definition: transaction.hpp:38
mongocxx::collection
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:81
mongocxx::client_session::commit_transaction
void commit_transaction()
Commits a transaction on the current client session.