Hazelcast C++ Client
Hazelcast C++ Client Library
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. More...
 
boost::uuids::uuid get_txn_id () const
 
boost::future< void > begin_transaction ()
 Begins a transaction. More...
 
boost::future< void > commit_transaction ()
 Commits a transaction. More...
 
boost::future< void > rollback_transaction ()
 Begins a transaction. More...
 
std::shared_ptr< transactional_mapget_map (const std::string &name)
 Returns the transactional distributed map instance with the specified name. More...
 
std::shared_ptr< transactional_queueget_queue (const std::string &name)
 Returns the transactional queue instance with the specified name. More...
 
std::shared_ptr< transactional_multi_mapget_multi_map (const std::string &name)
 Returns the transactional multimap instance with the specified name. More...
 
std::shared_ptr< transactional_listget_list (const std::string &name)
 Returns the transactional list instance with the specified name. More...
 
std::shared_ptr< transactional_setget_set (const std::string &name)
 Returns the transactional set instance with the specified name. More...
 
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. More...
 

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 60 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 561 of file transactions.cpp.

562  : options_(txn_options),
563  txn_connection_(
564  transaction_manager.connect()),
565  transaction_(options_,
566  transaction_manager.get_client(),
567  txn_connection_) {
568  }

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 574 of file transactions.cpp.

574  {
575  return transaction_.begin();
576  }

◆ 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 578 of file transactions.cpp.

578  {
579  return transaction_.commit();
580  }

◆ 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 135 of file transaction_context.h.

135  {
136  return get_transactional_object<transactional_list>(ilist::SERVICE_NAME, name);
137  }

◆ 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 102 of file transaction_context.h.

102  {
103  return get_transactional_object<transactional_map>(imap::SERVICE_NAME, name);
104  }

◆ 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 124 of file transaction_context.h.

124  {
125  return get_transactional_object<transactional_multi_map>(multi_map::SERVICE_NAME, name);
126  }

◆ 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 113 of file transaction_context.h.

113  {
114  return get_transactional_object<transactional_queue>(iqueue::SERVICE_NAME, name);
115  }

◆ 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 146 of file transaction_context.h.

146  {
147  return get_transactional_object<transactional_set>(iset::SERVICE_NAME, name);
148  }

◆ 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 158 of file transaction_context.h.

158  {
159  if (transaction_.get_state() != txn::TxnState::ACTIVE) {
160  std::string message = "No transaction is found while accessing ";
161  message += "transactional object -> [" + name + "]!";
162  BOOST_THROW_EXCEPTION(
163  exception::illegal_state("TransactionContext::getMap(const std::string& name)",
164  message));
165  }
166  auto key = std::make_pair(service_name, name);
167  std::shared_ptr<T> obj = std::static_pointer_cast<T>(txn_object_map_.get(key));
168  if (!obj) {
169  obj = std::shared_ptr<T>(new T(name, transaction_));
170  txn_object_map_.put(key, obj);
171  }
172 
173  return obj;
174  }

◆ get_txn_id()

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

Definition at line 570 of file transactions.cpp.

570  {
571  return transaction_.get_txn_id();
572  }

◆ 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 582 of file transactions.cpp.

582  {
583  return transaction_.rollback();
584  }

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