Hazelcast C++ Client
Hazelcast C++ Client Library
Loading...
Searching...
No Matches
hazelcast::client::transaction_context Class Reference

Provides a context to do transactional operations; so beginning/committing transactions, but also retrieving transactional data-structures like the TransactionalMap. More...

#include <transaction_context.h>

Public Member Functions

 transaction_context (spi::impl::ClientTransactionManagerServiceImpl &transaction_manager, const transaction_options &)
 Constructor to be used internally.
boost::uuids::uuid get_txn_id () const
boost::future< void > begin_transaction ()
 Begins a transaction.
boost::future< void > commit_transaction ()
 Commits a transaction.
boost::future< void > rollback_transaction ()
 Begins a transaction.
std::shared_ptr< transactional_mapget_map (const std::string &name)
 Returns the transactional distributed map instance with the specified name.
std::shared_ptr< transactional_queueget_queue (const std::string &name)
 Returns the transactional queue instance with the specified name.
std::shared_ptr< transactional_multi_mapget_multi_map (const std::string &name)
 Returns the transactional multimap instance with the specified name.
std::shared_ptr< transactional_listget_list (const std::string &name)
 Returns the transactional list instance with the specified name.
std::shared_ptr< transactional_setget_set (const std::string &name)
 Returns the transactional set instance with the specified name.
template<typename T>
std::shared_ptr< T > get_transactional_object (const std::string &service_name, const std::string &name)
 get any transactional object with template T.

Detailed Description

Provides a context to do transactional operations; so beginning/committing transactions, but also retrieving transactional data-structures like the TransactionalMap.

See also
hazelcast_client::newTransactionContext

Definition at line 68 of file transaction_context.h.

Constructor & Destructor Documentation

◆ transaction_context()

hazelcast::client::transaction_context::transaction_context ( spi::impl::ClientTransactionManagerServiceImpl & transaction_manager,
const transaction_options & txn_options )

Constructor to be used internally.

Not public API.

Definition at line 715 of file transactions.cpp.

718 : options_(txn_options)
719 , txn_connection_(transaction_manager.connect())
720 , transaction_(options_, transaction_manager.get_client(), txn_connection_)
721{}

Member Function Documentation

◆ begin_transaction()

boost::future< void > hazelcast::client::transaction_context::begin_transaction ( )

Begins a transaction.

Exceptions
illegal_stateif a transaction already is active.

Definition at line 730 of file transactions.cpp.

731{
732 return transaction_.begin();
733}

◆ commit_transaction()

boost::future< void > hazelcast::client::transaction_context::commit_transaction ( )

Commits a transaction.

Exceptions
transactionif no transaction is active or the transaction could not be committed.

Definition at line 736 of file transactions.cpp.

737{
738 return transaction_.commit();
739}

◆ get_list()

std::shared_ptr< transactional_list > hazelcast::client::transaction_context::get_list ( const std::string & name)
inline

Returns the transactional list instance with the specified name.

Parameters
namename of the list
Returns
transactional list instance with the specified name

Definition at line 154 of file transaction_context.h.

155 {
156 return get_transactional_object<transactional_list>(ilist::SERVICE_NAME,
157 name);
158 }
std::shared_ptr< T > get_transactional_object(const std::string &service_name, const std::string &name)
get any transactional object with template T.

◆ get_map()

std::shared_ptr< transactional_map > hazelcast::client::transaction_context::get_map ( const std::string & name)
inline

Returns the transactional distributed map instance with the specified name.

Parameters
namename of the distributed map
Returns
transactional distributed map instance with the specified name

Definition at line 114 of file transaction_context.h.

115 {
116 return get_transactional_object<transactional_map>(imap::SERVICE_NAME,
117 name);
118 }

◆ get_multi_map()

std::shared_ptr< transactional_multi_map > hazelcast::client::transaction_context::get_multi_map ( const std::string & name)
inline

Returns the transactional multimap instance with the specified name.

Parameters
namename of the multimap
Returns
transactional multimap instance with the specified name

Definition at line 140 of file transaction_context.h.

142 {
144 multi_map::SERVICE_NAME, name);
145 }

◆ get_queue()

std::shared_ptr< transactional_queue > hazelcast::client::transaction_context::get_queue ( const std::string & name)
inline

Returns the transactional queue instance with the specified name.

Parameters
namename of the queue
Returns
transactional queue instance with the specified name

Definition at line 127 of file transaction_context.h.

128 {
130 iqueue::SERVICE_NAME, name);
131 }

◆ get_set()

std::shared_ptr< transactional_set > hazelcast::client::transaction_context::get_set ( const std::string & name)
inline

Returns the transactional set instance with the specified name.

Parameters
namename of the set
Returns
transactional set instance with the specified name

Definition at line 167 of file transaction_context.h.

168 {
169 return get_transactional_object<transactional_set>(iset::SERVICE_NAME,
170 name);
171 }

◆ get_transactional_object()

template<typename T>
std::shared_ptr< T > hazelcast::client::transaction_context::get_transactional_object ( const std::string & service_name,
const std::string & name )
inline

get any transactional object with template T.

Mostly to be used by spi implementers of Hazelcast.

Returns
transactionalObject.

Definition at line 181 of file transaction_context.h.

183 {
184 if (transaction_.get_state() != txn::TxnState::ACTIVE) {
185 std::string message = "No transaction is found while accessing ";
186 message += "transactional object -> [" + name + "]!";
187 BOOST_THROW_EXCEPTION(exception::illegal_state(
188 "TransactionContext::getMap(const std::string& name)", message));
189 }
190 auto key = std::make_pair(service_name, name);
191 std::shared_ptr<T> obj =
192 std::static_pointer_cast<T>(txn_object_map_.get(key));
193 if (!obj) {
194 obj = std::shared_ptr<T>(new T(name, transaction_));
195 txn_object_map_.put(key, obj);
196 }
197
198 return obj;
199 }

◆ get_txn_id()

boost::uuids::uuid hazelcast::client::transaction_context::get_txn_id ( ) const
Returns
txn id.

Definition at line 724 of file transactions.cpp.

725{
726 return transaction_.get_txn_id();
727}

◆ rollback_transaction()

boost::future< void > hazelcast::client::transaction_context::rollback_transaction ( )

Begins a transaction.

Exceptions
illegal_stateif a transaction already is active.

Definition at line 742 of file transactions.cpp.

743{
744 return transaction_.rollback();
745}

The documentation for this class was generated from the following files: