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/client_session-fwd.hpp> // IWYU pragma: export
//
#include <mongocxx/v1/client_session.hpp> // IWYU pragma: export
#include <cstdint>
#include <functional>
#include <memory> // IWYU pragma: keep: backward compatibility, to be removed.
#include <mongocxx/bulk_write-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <mongocxx/client-fwd.hpp>
#include <mongocxx/collection-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <mongocxx/database-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <mongocxx/index_view-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <mongocxx/search_index_view-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <bsoncxx/document/view.hpp>
#include <bsoncxx/stdx/optional.hpp>
#include <bsoncxx/types.hpp>
#include <mongocxx/options/client_session.hpp>
#include <mongocxx/options/transaction.hpp>
#include <mongocxx/config/prelude.hpp>
namespace mongocxx {
namespace v_noabi {
class client_session {
private:
v1::client_session _session;
v_noabi::client* _client;
v_noabi::options::client_session _options;
public:
using transaction_state = v1::client_session::transaction_state;
v_noabi::client const& client() const noexcept {
return *_client;
}
options::client_session const& options() const noexcept {
return _options;
}
bsoncxx::v_noabi::document::view id() const noexcept {
return _session.id();
}
bsoncxx::v_noabi::document::view cluster_time() const noexcept {
return _session.cluster_time();
}
bsoncxx::v_noabi::types::b_timestamp operation_time() const noexcept {
return bsoncxx::v_noabi::from_v1(_session.operation_time());
}
std::uint32_t server_id() const noexcept {
return _session.server_id();
}
transaction_state get_transaction_state() const noexcept {
return _session.get_transaction_state();
}
bool get_dirty() const noexcept {
return _session.get_dirty();
}
void advance_cluster_time(bsoncxx::v_noabi::document::view const& cluster_time) {
_session.advance_cluster_time(bsoncxx::v_noabi::to_v1(cluster_time));
}
void advance_operation_time(bsoncxx::v_noabi::types::b_timestamp const& operation_time) {
_session.advance_operation_time(bsoncxx::v_noabi::to_v1(operation_time));
}
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(void) start_transaction(
bsoncxx::v_noabi::stdx::optional<v_noabi::options::transaction> const& transaction_opts = {});
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(void) commit_transaction();
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(void) abort_transaction();
using with_transaction_cb = std::function<void MONGOCXX_ABI_CDECL(client_session*)>;
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(void) with_transaction(
with_transaction_cb cb,
v_noabi::options::transaction opts = {});
class internal;
private:
client_session(v1::client_session session, v_noabi::client& client, v_noabi::options::client_session options);
};
} // namespace v_noabi
} // namespace mongocxx
#include <mongocxx/config/postlude.hpp>
bsoncxx::v1::stdx::optional
A polyfill for std::optional<T>.
Definition optional.hpp:799
bsoncxx::v_noabi::document::view
A read-only, non-owning view of a BSON document.
Definition view.hpp:40
mongocxx::v1::client_session
A MongoDB client session.
Definition client_session.hpp:46
mongocxx::v1::client_session::transaction_state
transaction_state
The state of an associated transaction.
Definition client_session.hpp:57
mongocxx::v_noabi::client_session
Supports MongoDB client session operations.
Definition client_session.hpp:58
mongocxx::v_noabi::client_session::with_transaction_cb
std::function< void(client_session *)> with_transaction_cb
Represents a callback invoked within a transaction.
Definition client_session.hpp:187
mongocxx::v_noabi::client_session::cluster_time
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
mongocxx::v_noabi::client_session::get_transaction_state
transaction_state get_transaction_state() const noexcept
Returns the current transaction state for this session.
Definition client_session.hpp:119
mongocxx::v_noabi::client_session::id
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
mongocxx::v_noabi::client_session::operation_time
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
mongocxx::v_noabi::client_session::get_dirty
bool get_dirty() const noexcept
Returns whether or not this session is dirty.
Definition client_session.hpp:126
mongocxx::v_noabi::client_session::with_transaction
void with_transaction(with_transaction_cb cb, v_noabi::options::transaction opts={})
Helper to run a user-provided callback within a transaction.
mongocxx::v_noabi::client_session::abort_transaction
void abort_transaction()
Aborts a transaction on the current client session.
mongocxx::v_noabi::client_session::server_id
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
mongocxx::v_noabi::client_session::advance_cluster_time
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
mongocxx::v_noabi::client_session::options
options::client_session const & options() const noexcept
Gets the options this session was created with.
Definition client_session.hpp:77
mongocxx::v_noabi::client_session::advance_operation_time
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
mongocxx::v_noabi::client_session::commit_transaction
void commit_transaction()
Commits a transaction on the current client session.
mongocxx::v_noabi::client_session::start_transaction
void start_transaction(bsoncxx::v_noabi::stdx::optional< v_noabi::options::transaction > const &transaction_opts={})
Starts a transaction on the current client session.
mongocxx::v_noabi::client_session::client
v_noabi::client const & client() const noexcept
Gets the client that started this session.
Definition client_session.hpp:70
mongocxx::v_noabi::client
A client connection to a MongoDB server.
Definition client.hpp:77
mongocxx::v_noabi::options::client_session
Used by client sessions.
Definition client_session.hpp:40
mongocxx::v_noabi::options::transaction
Used by MongoDB transaction operations.
Definition transaction.hpp:43
index_view-fwd.hpp
Declares mongocxx::v_noabi::index_view.
MONGOCXX_ABI_CDECL
#define MONGOCXX_ABI_CDECL
Expands to __cdecl when built with MSVC on Windows.
Definition export.hpp:49
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE
#define MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(...)
Equivalent to MONGOCXX_ABI_EXPORT_UNSTABLE with MONGOCXX_ABI_CDECL.
Definition config.hpp:28
postlude.hpp
The mongocxx v_noabi macro guard postlude header.
prelude.hpp
The mongocxx v_noabi macro guard prelude header.
bsoncxx::v_noabi::to_v1
v1::element::view to_v1(v_noabi::array::element const &v)
Convert to the bsoncxx::v1 equivalent of v.
Definition element.hpp:132
bsoncxx::v_noabi::from_v1
v_noabi::array::value from_v1(v1::array::value const &v)
Convert from the bsoncxx::v1 equivalent of v.
Definition value.hpp:263
mongocxx::v_noabi::options
Declares entities representing options to use with various commands.
mongocxx::v_noabi
Declares entities whose ABI stability is NOT guaranteed.
mongocxx
The top-level namespace within which all mongocxx library entities are declared.
search_index_view-fwd.hpp
Declares mongocxx::v_noabi::search_index_view.
bsoncxx::v_noabi::types::b_timestamp
A BSON replication timestamp value.
Definition types.hpp:601
transaction.hpp
Provides mongocxx::v_noabi::options::transaction.
types.hpp
Provides entities used to represent BSON types.
client_session.hpp
Provides mongocxx::v1::client_session.
view.hpp
Provides bsoncxx::v_noabi::document::view.
optional.hpp
Provides std::optional-related polyfills for library API usage.
bulk_write-fwd.hpp
Declares mongocxx::v_noabi::bulk_write.
client-fwd.hpp
Declares mongocxx::v_noabi::client.
client_session-fwd.hpp
Declares mongocxx::v_noabi::client_session.
collection-fwd.hpp
Declares mongocxx::v_noabi::collection.
database-fwd.hpp
Declares mongocxx::v_noabi::database.
client_session.hpp
Provides mongocxx::v_noabi::options::client_session.