LMDBAL 0.6.0
LMDB (Lightning Memory-Mapped Database Manager) Abstraction Layer
Loading...
Searching...
No Matches
LMDBAL::CursorCommon Class Reference

An object to manage cursor internals and state. More...

Inheritance diagram for LMDBAL::CursorCommon:
LMDBAL::Cursor< K, V >

Public Member Functions

void open ()
 Opens the cursor for operations.
 
void open (const Transaction &transaction)
 Opens the cursor for operations.
 
void renew ()
 Renews a cursor.
 
void renew (const Transaction &transaction)
 Renews a cursor.
 
bool opened () const
 Tells if the cursor is open.
 
bool empty () const
 Returns true if the cursor is empty.
 
void close ()
 Termiates a sequence of operations with the cursor.
 

Protected Types

enum  State { closed , openedPublic , openedPrivate }
 

Protected Member Functions

 CursorCommon ()
 Creates a empty class.
 
 CursorCommon (StorageCommon *storage)
 Creates a cursor.
 
 CursorCommon (const CursorCommon &other)=delete
 
 CursorCommon (CursorCommon &&other)
 Moves other cursor into this class.
 
virtual ~CursorCommon () noexcept
 Destroys this cursor.
 
CursorCommonoperator= (const CursorCommon &other)=delete
 
CursorCommonoperator= (CursorCommon &&other)
 Move assignment operator.
 
void terminated ()
 A private function called to inform the cursor he has been terminated.
 
void dropped ()
 A private method that turns cursor into an empty one.
 
void reset ()
 A private method that turns cursor into an empty one.
 

Protected Attributes

uint32_t id
 
State state
 
MDB_cursor * handle
 
StorageCommonstorage
 

Static Protected Attributes

static const std::string firstMethodName = "first"
 member function name, just for exceptions in heir
 
static const std::string lastMethodName = "last"
 member function name, just for exceptions in heir
 
static const std::string nextMethodName = "next"
 member function name, just for exceptions in heir
 
static const std::string prevMethodName = "prev"
 member function name, just for exceptions in heir
 
static const std::string currentMethodName = "current"
 member function name, just for exceptions in heir
 
static const std::string setMethodName = "set"
 member function name, just for exceptions in heir
 
static const std::string firstOperationName = "Cursor::first"
 member function name, just for exceptions in heir
 
static const std::string lastOperationName = "Cursor::last"
 member function name, just for exceptions in heir
 
static const std::string nextOperationName = "Cursor::next"
 member function name, just for exceptions in heir
 
static const std::string prevOperationName = "Cursor::prev"
 member function name, just for exceptions in heir
 
static const std::string currentOperationName = "Cursor::current"
 member function name, just for exceptions in heir
 

Friends

class Transaction
 

Detailed Description

An object to manage cursor internals and state.

Cursors are owned by the storage, they die with the storage. They also get closed if the storage is closed (if you close by the database for example)

You can obtain an instance of this class calling LMDBAL::Storage::createCursor() and destory it calling LMDBAL::Storage::destoryCursor() at any time, LMDBAL::Base doesn't necessarily need to be opened.

You are not supposed to instantiate or destory instances of this class yourself!

Member Enumeration Documentation

◆ State

Enumerator
closed 

Cursor state:

  • closed
openedPublic 
  • opened with public transaction, all storages will be notified about it after it's done
openedPrivate 
  • opened with private transaction, only current storage will be notified when cursor is closed

Constructor & Destructor Documentation

◆ CursorCommon() [1/2]

LMDBAL::CursorCommon::CursorCommon ( StorageCommon * _storage)
protected

Creates a cursor.

Parameters
[in]_storagea storage that created this cursor

◆ CursorCommon() [2/2]

LMDBAL::CursorCommon::CursorCommon ( CursorCommon && other)
protected

Moves other cursor into this class.

Parameters
[in]otherother instance that is being moved

◆ ~CursorCommon()

LMDBAL::CursorCommon::~CursorCommon ( )
protectedvirtualnoexcept

Destroys this cursor.

If the cursor wasn't properly closed - it's going to be upon destruction

Member Function Documentation

◆ close()

void LMDBAL::CursorCommon::close ( )

Termiates a sequence of operations with the cursor.

This is a normal way to tell that you're done with the cursor and don't want to continue the sequence of queries. The state of the cursor is lost after calling this method, some inner resorce is freed.

If the cursor was opened with the private transaction - the owner storage will be notified of the aborted transaction.

This function does nothing on a closed cursor.

◆ dropped()

void LMDBAL::CursorCommon::dropped ( )
protected

A private method that turns cursor into an empty one.

This function is called from LMDBAL::Storage, when it gets destroyed, but still has some valid cursors. Those cursors will become empty, and can't be used anymore

◆ empty()

bool LMDBAL::CursorCommon::empty ( ) const

Returns true if the cursor is empty.

Empty cursors can't be used, they can be only targets of move operations

◆ open() [1/2]

void LMDBAL::CursorCommon::open ( )

Opens the cursor for operations.

This is a normal way to start the sequence of operations with the cursor. This variant of the function creates a read only transaction just for this cursor

This function should be called when the LMDBAL::Storage is already opened and before any query with this cursor! It will do nothing to a cursor that was already opened (no matter what way).

Exceptions
LMDBAL::Closedthrown if you try to open the cursor on a closed database
LMDBAL::Unknownthrown if there was a problem opening the cursor by the lmdb, or to begin a transaction
LMDBAL::CursorEmptythrown if the cursor was empty

◆ open() [2/2]

void LMDBAL::CursorCommon::open ( const Transaction & transaction)

Opens the cursor for operations.

This is a normal way to start the sequence of operations with the cursor. This variant of the function uses for queries a transaction you have obtained somewhere else.

This function should be called when the LMDBAL::Storage is already opened and before any query with this cursor! It will do nothing to a cursor that was already opened (no matter what way).

Parameters
[in]transaction- a transaction, can be read only
Exceptions
LMDBAL::Closedthrown if you try to open the cursor on a closed database
LMDBAL::Unknownthrown if there was a problem opening the cursor by the lmdb
LMDBAL::TransactionTerminatedthrown if the passed transaction not active, any action with it's inner ID is an error
LMDBAL::CursorEmptythrown if the cursor was empty

◆ operator=()

LMDBAL::CursorCommon & LMDBAL::CursorCommon::operator= ( CursorCommon && other)
protected

Move assignment operator.

Transfers other cursor into this one

◆ renew() [1/2]

void LMDBAL::CursorCommon::renew ( )

Renews a cursor.

This function aborts current transaction if the cursor was opened with it's own transaction (does not mess up if the transaction was public), creates new private transaction and rebinds this cursor to it.

Theoretically you could call this method if your public transaction was aborted (or commited) but you wish to continue to keep working with your cursor. Or if you just want to rebind your cursor to a new private transaction.

This function does nothing if the cursor is closed

Exceptions
LMDBAL::Closedthrown if you try to renew the cursor on a closed database
LMDBAL::Unknownthrown if there was a problem beginning new transaction or if there was a problem renewing the cursor by lmdb
LMDBAL::CursorEmptythrown if the cursor was empty

◆ renew() [2/2]

void LMDBAL::CursorCommon::renew ( const Transaction & transaction)

Renews a cursor.

This function aborts current transaction if the cursor was opened with it's own transaction (does not mess up if the transaction was public), and rebinds this cursor to a passed new transaction.

Theoretically you could call this method if your previous public transaction was aborted (or commited) but you wish to continue to keep working with your cursor. Or if you just want to rebind your cursor to another public transaction.

This function does nothing if the cursor is closed

Parameters
[in]transaction- a transaction you wish this cursor to be bound to
Exceptions
LMDBAL::Closedthrown if you try to renew the cursor on a closed database
LMDBAL::Unknownthrown if there was a problem renewing the cursor by lmdb
LMDBAL::TransactionTerminatedthrown if the passed transaction not active, any action with it's inner ID is an error
LMDBAL::CursorEmptythrown if the cursor was empty

◆ reset()

void LMDBAL::CursorCommon::reset ( )
protected

A private method that turns cursor into an empty one.

This method is called from LMDBAL::Storage, when the cursor is getting destoryed. After this method cursors will become empty, and can't be used anymore

◆ terminated()

void LMDBAL::CursorCommon::terminated ( )
protected

A private function called to inform the cursor he has been terminated.

Is expected to be called from transaction, database, storage or move constructor


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