Flip Reference

 

TxSessionGuard Class Reference

Namespace

ohm::flip

Declared in

ohm/flip/TxSessionGuard.h

See Also

ohm::flip::Scribe

Overview

The TxSessionGuard class implements a convenient class to manage transaction as well as a guard to detect common errors when manipulating transactions.

Usually, every custom Flip classes implemented by the client should have a TxSessionGuard member.

The following sections will only document the public API.

Partial Class Diagram

Methods Overview

Constructor

Manipulating

State

Methods

TxSessionGuard constructor

Constructs a TxSessionGuard and bind it to a document.

               TxSessionGuard (DocumentBase & document);

prepare_record

Prepares the undo system to start to record the transaction if needed.

Important:If used, it must be called before the transaction is started with start .

void           prepare_record (Scribe & scribe);

If the transaction does not need to be recorded by the undo system, this function must not be called.

start

Starts the transaction if possible. Returns true if the transaction was successfully started, false otherwise.

bool           start ();

A transaction cannot be started if the document has already an ongoing transaction. However a transaction maybe joined : see can_join below.

commit

Commits the transaction. The transaction must have been started with start before. If the transaction was not started, then this will trigger an assert .

void           commit ();

When a transaction is commited, it is sent to the server for validation and broadcast to the other clients.

revert

Reverts the transaction. The transaction must have been started with start before. If the transaction was not started, then this will trigger an assert .

void           revert ();

When a transaction is reverted, the model is automatically rollbacked, and a call to the observer is issued if needed.

In particular, reverting a transaction does not send anything to the server.

can_start

Returns true if a transaction was not already started, false otherwise.

bool           can_start ();

is_started

Returns true if a transaction was already started on this, false otherwise.

bool           can_start ();

This function only applies to this session guard. The function might return false while a transaction might be opened at the document level.

can_join

Returns true if a transaction was already started on this, or at the document level, false otherwise.

bool           can_join ();

Joining a transaction allows objects to fill the current transaction without the need to start a transaction themselves. This is rarely used, but is handy for concurrent manipulation such as, for example, scrolling in a document while the user drags an object, where the drag is part of the transaction.