CONZEPT 16 C++ API
C16::Transaction Class Reference

Transaction of a database. More...

#include "C16/Transaction.hpp"

Detailed Description

Transaction of a database.

Examples

Usage

#include "C16/Library.hpp"
using namespace C16;
void transaction_usage(Database& database)
{
// Starts a transaction.
Transaction transaction(database);
...
if (...)
// Aborts the transaction implicitly due to deconstruction.
return;
if (...)
// Commits the transaction.
transaction.commit();
else
// Aborts the transaction.
transaction.abort();
}

Public Types

enum  State { State::ACTIVE = 1, State::COMMITTED, State::ABORTED }
 State of a transaction. More...
 

Public Member Functions

 Transaction (Database &database)
 Constructs and starts a transaction. More...
 
 ~Transaction ()
 Aborts and destructs the transaction. More...
 
State state () const
 Gets the state of the transaction. More...
 
bool active () const
 Gets if the transaction is active. More...
 
bool comitted () const
 Gets if the transaction was comitted. More...
 
bool aborted () const
 Gets if the transaction was aborted. More...
 
int level () const
 Gets the level of the transaction. More...
 
void commit ()
 Commits the transaction if it is active. More...
 
void abort ()
 Aborts the transaction if it is active. More...
 

Member Enumeration Documentation

◆ State

State of a transaction.

Enumerator
ACTIVE 

Transaction is active.

COMMITTED 

Transaction was commited.

ABORTED 

Transaction was aborted.

Constructor & Destructor Documentation

◆ Transaction()

C16::Transaction::Transaction ( Database database)
explicit

Constructs and starts a transaction.

Parameters
databaseDatabase the transaction relates to

The state of the transaction will be "active".

◆ ~Transaction()

C16::Transaction::~Transaction ( )

Aborts and destructs the transaction.

Member Function Documentation

◆ state()

State C16::Transaction::state ( ) const

Gets the state of the transaction.

◆ active()

bool C16::Transaction::active ( ) const

Gets if the transaction is active.

Note
Equal to state() == State::ACTIVE.

◆ comitted()

bool C16::Transaction::comitted ( ) const

Gets if the transaction was comitted.

Note
Equal to state() == State::COMMITTED.

◆ aborted()

bool C16::Transaction::aborted ( ) const

Gets if the transaction was aborted.

Note
Equal to state() == State::ABORTED.

◆ level()

int C16::Transaction::level ( ) const

Gets the level of the transaction.

The level is the number of active transactions when the transaction was started (including this transaction).

See also
Transactions::depth

◆ commit()

void C16::Transaction::commit ( )

Commits the transaction if it is active.

If the transaction is the only active one (i.e. the level of the transaction is one), all manipulations to database entities that are covered by transactions will be applied.

The state of the transaction and all active transactions that were started after this transaction (i.e. the level of the transactions is greater than the level of this transaction) will be "committed".

Note
Has no effect if the transaction is not active.
See also
Examples

◆ abort()

void C16::Transaction::abort ( )

Aborts the transaction if it is active.

If the transaction is the only active one (i.e. the level of the transaction is one), all manipulations to database entities that are covered by transactions will be rejected.

The state of the transaction and all active transactions that were started after this transaction (i.e. the level of the transactions is greater than the level of this transaction) will be "aborted".

Note
Has no effect if the transaction is not active.
See also
Examples
Transactions::abort_all
C16::Transaction
Transaction of a database.
Definition: Transaction.hpp:49
Library.hpp
CONZEPT 16 C++ API.
C16::Database
Database hosted by a server.
Definition: Database.hpp:38
C16
Namespace.
Definition: Array.hpp:6