LMDBAL 0.5.4
LMDB (Lightning Memory-Mapped Database Manager) Abstraction Layer
Loading...
Searching...
No Matches
LMDBAL::iStorage Class Referenceabstract

Storage interface. More...

Inheritance diagram for LMDBAL::iStorage:
LMDBAL::Storage< K, V > LMDBAL::Cache< K, V >

Public Member Functions

virtual void drop ()
 Drops content of a storage interface.
 
virtual int drop (const WriteTransaction &txn)
 Drops content of a storage interface (public transaction variant)
 
virtual SizeType count () const
 Storage size.
 
virtual SizeType count (const Transaction &txn) const
 Storage size (public transaction variant)
 
template<>
std::string toString (const QString &value)
 A method to cast a value (which can be a value or a key) to string.
 
template<>
std::string toString (const std::string &value)
 A method to cast a value (which can be a value or a key) to string.
 

Protected Member Functions

 iStorage (Base *parent, const std::string &name, bool duplicates=false)
 Constructs a storage interface.
 
virtual ~iStorage ()
 Destroys a storage interface.
 
virtual int open (MDB_txn *transaction)=0
 A private virtual function I need to open each storage in the database.
 
virtual void close ()
 A private virtual function I need to close each storage in the database.
 
virtual void handleDrop ()
 A method where database additionally handles drop.
 
bool isDBOpened () const
 Is database opened.
 
const std::string & dbName () const
 Database name.
 
void ensureOpened (const std::string &methodName) const
 Helper function, thows exception if the database is not opened.
 
void throwDuplicateOrUnknown (int rc, const std::string &key) const
 Throws LMDBAL::Exist or LMDBAL::Unknown.
 
void throwDuplicateOrUnknown (int rc, TransactionID txn, const std::string &key) const
 Throws LMDBAL::Exist or LMDBAL::Unknown (transaction vairiant)
 
void throwNotFoundOrUnknown (int rc, const std::string &key) const
 Throws LMDBAL::NotFound or LMDBAL::Unknown (transaction variant)
 
void throwNotFoundOrUnknown (int rc, TransactionID txn, const std::string &key) const
 Throws LMDBAL::NotFound or LMDBAL::Unknown (transaction vairiant)
 
void throwUnknown (int rc, TransactionID txn) const
 Throws LMDBAL::Unknown (transaction vairiant)
 
void throwUnknown (int rc) const
 Throws LMDBAL::Unknown.
 
void throwUnknown (const std::string &message) const
 Throws LMDBAL::Unknown.
 
void throwDuplicate (const std::string &key) const
 Throws LMDBAL::Exist.
 
void throwNotFound (const std::string &key) const
 Throws LMDBAL::NotFound.
 
void throwCursorNotReady (const std::string &method) const
 Throws LMDBAL::CursorNotReady.
 
TransactionID extractTransactionId (const Transaction &txn, const std::string &action="") const
 Checks if the transaction is still active, returns inner TransactionID.
 
TransactionID beginReadOnlyTransaction () const
 Begins read-only transaction.
 
TransactionID beginTransaction () const
 Begins writable transaction.
 
void commitTransaction (TransactionID id)
 Commits transaction.
 
void abortTransaction (TransactionID id) const
 Aborts transaction.
 
virtual void transactionStarted (TransactionID txn, bool readOnly) const
 called on beginning of public transaction
 
virtual void transactionCommited (TransactionID txn)
 called on commitment of public transaction
 
virtual void transactionAborted (TransactionID txn) const
 called on abortion of public transaction
 
virtual int drop (TransactionID transaction)
 Drops content of a storage interface (transaction variant)
 
virtual SizeType count (TransactionID txn) const
 Storage size (private transaction variant)
 
int _mdbOpen (MDB_txn *txn, unsigned int flags=0)
 
int _mdbPut (MDB_txn *txn, MDB_val &key, MDB_val &data, unsigned int flags=0)
 
int _mdbGet (MDB_txn *txn, MDB_val &key, MDB_val &data) const
 
int _mdbDel (MDB_txn *txn, MDB_val &key)
 
int _mdbDel (MDB_txn *txn, MDB_val &key, MDB_val &data)
 
int _mdbStat (MDB_txn *txn, MDB_stat &stat) const
 
int _mdbFlags (MDB_txn *txn, uint32_t &flags) const
 
int _mdbCursorOpen (MDB_txn *txn, MDB_cursor **cursor) const
 
void _mdbCursorClose (MDB_cursor *cursor) const
 
int _mdbCursorGet (MDB_cursor *cursor, MDB_val &key, MDB_val &data, MDB_cursor_op operation) const
 
int _mdbCursorSet (MDB_cursor *cursor, MDB_val &key) const
 
int _mdbCursorDel (MDB_cursor *cursor, unsigned int flags=0)
 
int _mdbCursorPut (MDB_cursor *cursor, MDB_val &key, MDB_val &data, unsigned int flags=0)
 
int _mdbCursorRenew (MDB_txn *txn, MDB_cursor *cursor) const
 
MDB_txn * _mdbCursorTxn (MDB_cursor *cursor) const
 
template<class K , class V >
int makeStorage (MDB_txn *transaction, bool duplicates=false)
 A functiion to actually open MDB_dbi storage.
 

Static Protected Member Functions

template<class T >
static std::string toString (const T &value)
 A method to cast a value (which can be a value or a key) to string.
 

Protected Attributes

MDB_dbi dbi
 lmdb storage handle
 
Basedb
 parent database pointer (borrowed)
 
const std::string name
 this storage name
 
const bool duplicates
 true if storage supports duplicates
 

Static Protected Attributes

static const std::string dropMethodName = "drop"
 member function name, just for exceptions
 
static const std::string countMethodName = "count"
 member function name, just for exceptions
 
static const std::string flagsMethodName = "flags"
 member function name, just for exceptions
 
static const std::string addRecordMethodName = "addRecord"
 member function name, just for exceptions
 
static const std::string forceRecordMethodName = "forceRecord"
 member function name, just for exceptions
 
static const std::string changeRecordMethodName = "changeRecord"
 member function name, just for exceptions
 
static const std::string removeRecordMethodName = "removeRecord"
 member function name, just for exceptions
 
static const std::string checkRecordMethodName = "checkRecord"
 member function name, just for exceptions
 
static const std::string getRecordMethodName = "getRecord"
 member function name, just for exceptions
 
static const std::string readAllMethodName = "readAllRecord"
 member function name, just for exceptions
 
static const std::string replaceAllMethodName = "replaceAll"
 member function name, just for exceptions
 
static const std::string addRecordsMethodName = "addRecords"
 member function name, just for exceptions
 

Friends

class Base
 

Detailed Description

Storage interface.

This is a interface-like class, it's designed to be an inner database interface to be used as a polymorphic entity, and provide protected interaction with the database from the heirs code

Constructor & Destructor Documentation

◆ iStorage()

LMDBAL::iStorage::iStorage ( Base * parent,
const std::string & name,
bool duplicates = false )
protected

Constructs a storage interface.

Parameters
[in]parent- LMDBAL::Base pointer for the owning database (borrowed)
[in]name- the name of the storage
[in]duplicates- true if key duplicates are allowed (false by default)

Member Function Documentation

◆ abortTransaction()

void LMDBAL::iStorage::abortTransaction ( LMDBAL::TransactionID id) const
protected

Aborts transaction.

Ment to be called from heirs, name is reported to the database just to be displayed in std::exception::what() message

◆ beginReadOnlyTransaction()

LMDBAL::TransactionID LMDBAL::iStorage::beginReadOnlyTransaction ( ) const
protected

Begins read-only transaction.

Ment to be called from heirs, name is reported to the database just to be displayed in std::exception::what() message

Returns
read only transaction

◆ beginTransaction()

LMDBAL::TransactionID LMDBAL::iStorage::beginTransaction ( ) const
protected

Begins writable transaction.

Ment to be called from heirs, name is reported to the database just to be displayed in std::exception::what() message

Returns
read only transaction

◆ close()

void LMDBAL::iStorage::close ( )
protectedvirtual

A private virtual function I need to close each storage in the database.

Reimplemented in LMDBAL::Storage< K, V >.

◆ commitTransaction()

void LMDBAL::iStorage::commitTransaction ( LMDBAL::TransactionID id)
protected

Commits transaction.

Ment to be called from heirs, name is reported to the database just to be displayed in std::exception::what() message

Exceptions
LMDBAL::Unknownthrown if something unexpected happened

◆ count() [1/3]

LMDBAL::SizeType LMDBAL::iStorage::count ( ) const
virtual

Storage size.

Returns
amount of records in the storage
Exceptions
LMDBAL::Closedthrown if the database was closed
LMDBAL::Unknownthrown if something unexpected happened

Reimplemented in LMDBAL::Cache< K, V >.

◆ count() [2/3]

LMDBAL::SizeType LMDBAL::iStorage::count ( const Transaction & txn) const
virtual

Storage size (public transaction variant)

Parameters
[in]txn- transaction, can be read-only transaction
Returns
amount of records in the storage
Exceptions
LMDBAL::Closedthrown if the database was closed
LMDBAL::Unknownthrown if something unexpected happened
LMDBAL::TransactionTerminatedthrown if the passed transaction not active, any action with it's inner ID is an error

◆ count() [3/3]

LMDBAL::SizeType LMDBAL::iStorage::count ( TransactionID txn) const
protectedvirtual

Storage size (private transaction variant)

Parameters
[in]txn- transaction ID, can be read-only transaction
Returns
amount of records in the storage
Exceptions
LMDBAL::Unknownthrown if something unexpected happened

Reimplemented in LMDBAL::Cache< K, V >.

◆ dbName()

const std::string & LMDBAL::iStorage::dbName ( ) const
protected

Database name.

Ment to be used in heirs, to provide some sort of interface to acces to some of the database information

Returns
database name

◆ drop() [1/3]

void LMDBAL::iStorage::drop ( )
virtual

Drops content of a storage interface.

Designed to drop storage content

Exceptions
LMDBAL::Closedthrown if the database was closed
LMDBAL::Unknownthrown if something unexpected happened

Reimplemented in LMDBAL::Storage< K, V >.

◆ drop() [2/3]

int LMDBAL::iStorage::drop ( const WriteTransaction & txn)
virtual

Drops content of a storage interface (public transaction variant)

Just performs content drop

Parameters
[in]txn- transaction ID, must be writable transaction!
Returns
MDB_SUCCESS if everything went fine, MDB_<error> code otherwise
Exceptions
LMDBAL::TransactionTerminatedthrown if the transaction was not active

Reimplemented in LMDBAL::Cache< K, V >, and LMDBAL::Storage< K, V >.

◆ drop() [3/3]

int LMDBAL::iStorage::drop ( TransactionID transaction)
protectedvirtual

Drops content of a storage interface (transaction variant)

Just performs content drop

Parameters
[in]transaction- transaction ID, must be writable transaction!
Returns
MDB_SUCCESS if everything went fine, MDB_<error> code otherwise

Reimplemented in LMDBAL::Storage< K, V >.

◆ ensureOpened()

void LMDBAL::iStorage::ensureOpened ( const std::string & methodName) const
protected

Helper function, thows exception if the database is not opened.

Parameters
[in]methodName- name of the method this function is called from, just for display in std::exception::what() message
Exceptions
LMDBAL::Closedthrown if the database was closed

◆ extractTransactionId()

LMDBAL::TransactionID LMDBAL::iStorage::extractTransactionId ( const Transaction & txn,
const std::string & action = "" ) const
protected

Checks if the transaction is still active, returns inner TransactionID.

This method is for internal usage only

Parameters
[in]txn- a transaction, you want to extract ID from
[in]action- a description of what you're going to do, in case of exception the error description will be verbose
Returns
- Transaction inner TransactionID
Exceptions
LMDBAL::TransactionTerminatedthrown if the passed transaction not active, any action with it's inner ID is an error

◆ handleDrop()

void LMDBAL::iStorage::handleDrop ( )
protectedvirtual

A method where database additionally handles drop.

It's a protected method that is called to optimise drop process after the transaction is commited. Used just for optimisations.

Reimplemented in LMDBAL::Cache< K, V >.

◆ isDBOpened()

bool LMDBAL::iStorage::isDBOpened ( ) const
protected

Is database opened.

Ment to be used in heirs, to provide some sort of interface to acces to some of the database information

Returns
true if database is ipened, false otherwise

◆ makeStorage()

template<class K , class V >
int LMDBAL::iStorage::makeStorage ( MDB_txn * transaction,
bool duplicates = false )
inlineprotected

A functiion to actually open MDB_dbi storage.

Template Parameters
Ktype of keys in opening storage
Parameters
[in]transaction- lmdb transaction to call mdb_dbi_open, must be a writable transaction!
[in]duplicates- true if key duplicates are allowed (false by default)
Returns
MDB_SUCCESS if everything went smooth or MDB_<error> -like error code

This is a way to optimise database using MDB_INTEGERKEY flag, when the key is actually kind of an integer This infrastructure also allowes us to customize mdb_dbi_open call in the future

◆ open()

virtual int LMDBAL::iStorage::open ( MDB_txn * transaction)
protectedpure virtual

A private virtual function I need to open each storage in the database.

Parameters
[in]transaction- lmdb transaction to call mdb_dbi_open
Returns
MDB_SUCCESS if everything went smooth or MDB_<error> -like error code

Implemented in LMDBAL::Storage< K, V >.

◆ throwCursorNotReady()

void LMDBAL::iStorage::throwCursorNotReady ( const std::string & method) const
protected

Throws LMDBAL::CursorNotReady.

Helper function ment to be used in heirs and reduce the code a bit

Parameters
[in]method- called cursor method name, just to show in std::exception::what() message
Exceptions
LMDBAL::CursorNotReadythrown everytime

◆ throwDuplicate()

void LMDBAL::iStorage::throwDuplicate ( const std::string & key) const
protected

Throws LMDBAL::Exist.

Helper function ment to be used in heirs and reduce the code a bit

Parameters
[in]key- requested key string representation, just to show in std::exception::what() message
Exceptions
LMDBAL::Existthrown everytime

◆ throwDuplicateOrUnknown() [1/2]

void LMDBAL::iStorage::throwDuplicateOrUnknown ( int rc,
const std::string & key ) const
protected

Throws LMDBAL::Exist or LMDBAL::Unknown.

Helper function ment to be used in heirs and reduce the code a bit

Parameters
[in]rc- result of lmdb low level operation
[in]key- requested key string representation, just to show in std::exception::what() message
Exceptions
LMDBAL::Existthrown if rc == MDB_KEYEXIST
LMDBAL::Unknownthrown if rc != MDB_KEYEXIST

◆ throwDuplicateOrUnknown() [2/2]

void LMDBAL::iStorage::throwDuplicateOrUnknown ( int rc,
TransactionID txn,
const std::string & key ) const
protected

Throws LMDBAL::Exist or LMDBAL::Unknown (transaction vairiant)

Helper function ment to be used in heirs and reduce the code a bit

Parameters
[in]rc- result of lmdb low level operation
[in]txn- transaction ID to be aborted, any transaction
[in]key- requested key string representation, just to show in std::exception::what() message
Exceptions
LMDBAL::Existthrown if rc == MDB_KEYEXIST
LMDBAL::Unknownthrown if rc != MDB_KEYEXIST

◆ throwNotFound()

void LMDBAL::iStorage::throwNotFound ( const std::string & key) const
protected

Throws LMDBAL::NotFound.

Helper function ment to be used in heirs and reduce the code a bit

Parameters
[in]key- requested key string representation, just to show in std::exception::what() message
Exceptions
LMDBAL::NotFoundthrown everytime

◆ throwNotFoundOrUnknown() [1/2]

void LMDBAL::iStorage::throwNotFoundOrUnknown ( int rc,
const std::string & key ) const
protected

Throws LMDBAL::NotFound or LMDBAL::Unknown (transaction variant)

Helper function ment to be used in heirs and reduce the code a bit

Parameters
[in]rc- result of lmdb low level operation
[in]key- requested key string representation, just to show in std::exception::what() message
Exceptions
LMDBAL::NotFoundthrown if rc == MDB_NOTFOUND
LMDBAL::Unknownthrown if rc != MDB_NOTFOUND

◆ throwNotFoundOrUnknown() [2/2]

void LMDBAL::iStorage::throwNotFoundOrUnknown ( int rc,
LMDBAL::TransactionID txn,
const std::string & key ) const
protected

Throws LMDBAL::NotFound or LMDBAL::Unknown (transaction vairiant)

Helper function ment to be used in heirs and reduce the code a bit

Parameters
[in]rc- result of lmdb low level operation
[in]txn- transaction ID to be aborted, any transaction
[in]key- requested key string representation, just to show in std::exception::what() message
Exceptions
LMDBAL::NotFoundthrown if rc == MDB_NOTFOUND
LMDBAL::Unknownthrown if rc != MDB_NOTFOUND

◆ throwUnknown() [1/3]

void LMDBAL::iStorage::throwUnknown ( const std::string & message) const
protected

Throws LMDBAL::Unknown.

Helper function ment to be used in heirs and reduce the code a bit

Parameters
[in]message- a message you wish to appear in the exception reason
Exceptions
LMDBAL::Unknownthrown everytime

◆ throwUnknown() [2/3]

void LMDBAL::iStorage::throwUnknown ( int rc) const
protected

Throws LMDBAL::Unknown.

Helper function ment to be used in heirs and reduce the code a bit

Parameters
[in]rc- result of lmdb low level operation
Exceptions
LMDBAL::Unknownthrown everytime

◆ throwUnknown() [3/3]

void LMDBAL::iStorage::throwUnknown ( int rc,
LMDBAL::TransactionID txn ) const
protected

Throws LMDBAL::Unknown (transaction vairiant)

Helper function ment to be used in heirs and reduce the code a bit

Parameters
[in]rc- result of lmdb low level operation
[in]txn- transaction ID to be aborted, any transaction
Exceptions
LMDBAL::Unknownthrown everytime

◆ toString() [1/3]

template<>
std::string LMDBAL::iStorage::toString ( const QString & value)
inline

A method to cast a value (which can be a value or a key) to string.

QString spectialization

Parameters
[in]valuea value that should be converted to string
Returns
a string presentation of value

◆ toString() [2/3]

template<>
std::string LMDBAL::iStorage::toString ( const std::string & value)
inline

A method to cast a value (which can be a value or a key) to string.

std::string spectialization

Parameters
[in]valuea value that should be converted to string
Returns
a string presentation of value

◆ toString() [3/3]

template<class T >
std::string LMDBAL::iStorage::toString ( const T & value)
inlinestaticprotected

A method to cast a value (which can be a value or a key) to string.

This function is mainly used in exceptions, to report which key was duplicated or not found. You can define your own specializations to this function in case std::to_string doesn't cover your case

Parameters
[in]valuea value that should be converted to string
Returns
a string presentation of value

◆ transactionAborted()

void LMDBAL::iStorage::transactionAborted ( LMDBAL::TransactionID txn) const
protectedvirtual

called on abortion of public transaction

This function is called on every storage of the database when user calls LMDBAL::Base::abortTransaction(LMDBAL::TransactionID)

This function is met to be reimplemented in heirs if the heir code requires some transaction custom handling

Parameters
[in]txn- ID of started transaction

Reimplemented in LMDBAL::Cache< K, V >.

◆ transactionCommited()

void LMDBAL::iStorage::transactionCommited ( LMDBAL::TransactionID txn)
protectedvirtual

called on commitment of public transaction

This function is called on every storage of the database when user calls LMDBAL::Base::commitTransaction(LMDBAL::TransactionID)

This function is met to be reimplemented in heirs if the heir code requires some transaction custom handling

Parameters
[in]txn- ID of started transaction

Reimplemented in LMDBAL::Cache< K, V >.

◆ transactionStarted()

void LMDBAL::iStorage::transactionStarted ( LMDBAL::TransactionID txn,
bool readOnly ) const
protectedvirtual

called on beginning of public transaction

This function is called on every storage of the database when user calls LMDBAL::Base::beginTransaction() or LMDBAL::Base::beginReadOnlyTransaction()

This function is met to be reimplemented in heirs if the heir code requires some transaction custom handling

Parameters
[in]txn- ID of started transaction
[in]readOnly- true if transaction is read-only, false otherwise

Reimplemented in LMDBAL::Cache< K, V >.


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