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

Database abstraction. More...

Public Member Functions

 Base (const QString &name, uint16_t mapSize=10)
 Creates the database.
 
 ~Base ()
 Destroys the database.
 
void open ()
 Opens the database.
 
void close ()
 Closes the database.
 
bool ready () const
 Returns database state.
 
bool removeDirectory ()
 Removes database directory.
 
QString createDirectory ()
 Creates database directory.
 
QString getName () const
 Returns database name.
 
QString getPath () const
 Returns database name.
 
void drop ()
 Drops the database.
 
Transaction beginReadOnlyTransaction () const
 Begins read-only transaction.
 
WriteTransaction beginTransaction ()
 Begins writable transaction.
 
template<class K , class V >
LMDBAL::Storage< K, V > * addStorage (const std::string &storageName, bool duplicates=false)
 Adds LMDBAL::Storage to the database.
 
template<class K , class V >
LMDBAL::Cache< K, V > * addCache (const std::string &storageName)
 Adds LMDBAL::Cache to the database.
 
template<class K , class V >
LMDBAL::Storage< K, V > * getStorage (const std::string &storageName)
 Returns LMDBAL::Storage handle.
 
template<class K , class V >
LMDBAL::Cache< K, V > * getCache (const std::string &storageName)
 Returns LMDBAL::Cache handle.
 

Friends

class iStorage
 
class Transaction
 
class WriteTransaction
 

Detailed Description

Database abstraction.

This is a basic class that represents the database as a collection of storages. Storages is something key-value database has instead of tables in classic SQL databases.

Constructor & Destructor Documentation

◆ Base()

LMDBAL::Base::Base ( const QString & _name,
uint16_t _mapSize = 10 )

Creates the database.

Parameters
[in]_name- name of the database, it is going to affect folder name that is created to store data
[in]_mapSize- LMDB map size (MiB), multiplied by 1024^2 and passed to mdb_env_set_mapsize during the call of LMDBAL::Base::open()

Member Function Documentation

◆ addCache()

template<class K , class V >
LMDBAL::Cache< K, V > * LMDBAL::Base::addCache ( const std::string & storageName)

Adds LMDBAL::Cache to the database.

Defines that the database is going to have the following cache. The LMDBAL::Base must be closed

Parameters
[in]storageName- cache name
Returns
cache pointer. LMDBAL::Base keeps the ownership of the added cache, you don't need to destoroy it
Template Parameters
K- key type of the cache
V- value type of the cahce
Exceptions
LMDBAL::Openedthrown if this method is called on the opened database
LMDBAL::StorageDuplicatethrown if somebody tries to add cache with repeating name

◆ addStorage()

template<class K , class V >
LMDBAL::Storage< K, V > * LMDBAL::Base::addStorage ( const std::string & storageName,
bool duplicates = false )

Adds LMDBAL::Storage to the database.

Defines that the database is going to have the following storage. The LMDBAL::Base must be closed

Parameters
[in]storageName- storage name
[in]duplicates- true if key duplicates are allowed (false by default)
Returns
storage pointer. LMDBAL::Base keeps the ownership of the added storage, you don't need to destoroy it
Template Parameters
K- key type of the storage
V- value type of the storage
Exceptions
LMDBAL::Openedthrown if this method is called on the opened database
LMDBAL::StorageDuplicatethrown if somebody tries to add storage with repeating name

◆ beginReadOnlyTransaction()

LMDBAL::Transaction LMDBAL::Base::beginReadOnlyTransaction ( ) const

Begins read-only transaction.

This is the legitimate way to retrieve LMDBAL::Transaction. LMDBAL::Transaction is considered runnig right after creation by this method. You can terminate transaction manually calling LMDBAL::Transaction::terminate but it's not required, because transaction will be terminated automatically (if it was not terminated manually) upon the call of the destructor.

You can not use termitated transaction any more.

Returns
read-only transaction
Exceptions
LMDBAL::Closed- thrown if the database is closed
LMDBAL::Unknown- thrown if something unexpected happened

◆ beginTransaction()

LMDBAL::WriteTransaction LMDBAL::Base::beginTransaction ( )

Begins writable transaction.

This is the legitimate way to retrieve LMDBAL::WriteTransaction. LMDBAL::WriteTransaction is considered runnig right after creation by this method. You can commit all the changes made by this transaction calling LMDBAL::WriteTransaction::commit. You can cancel any changes made bu this transaction calling LMDBAL::WriteTransaction::abort (or LMDBAL::Transaction::terminate which LMDBAL::WriteTransaction inherits), but it's not required, because transaction will be aborted automatically (if it was not terminated (committed OR aborted) manually) upon the call of the destructor.

You can not use termitated transaction any more.

Returns
writable transaction
Exceptions
LMDBAL::Closed- thrown if the database is closed
LMDBAL::Unknown- thrown if something unexpected happened

◆ close()

void LMDBAL::Base::close ( )

Closes the database.

Closes all lmdb handles, aborts all public transactions. This function will do nothing on closed database

Exceptions
LMDBAL::Unknown- thrown if something went wrong aborting transactions

◆ createDirectory()

QString LMDBAL::Base::createDirectory ( )

Creates database directory.

Creates or opens existing directory with the given name in the location acquired with QStandardPaths::writableLocation(QStandardPaths::CacheLocation) so, the file system destination of your data would depend on the QCoreApplication configuration of your app. This function does nothing if the directory was already created

Returns
the path of the created directory
Exceptions
LMDBAL::Opened- thrown if called on opened database
LMDBAL::Directory- if the database couldn't create the folder

◆ drop()

void LMDBAL::Base::drop ( )

Drops the database.

Clears all caches and storages of the database

Exceptions
LMDBAL::Closed- thrown if the database is closed
LMDBAL::Unknown- thrown if something unexpected happend

◆ getCache()

template<class K , class V >
LMDBAL::Cache< K, V > * LMDBAL::Base::getCache ( const std::string & storageName)

Returns LMDBAL::Cache handle.

Requested cache must have been added before opening database Note that template parameters is user responsibility zone! If user, for instance, had added cache <int, int> but calling this method with template parameters <std::string, std::string> on the same name of the previously added cache, or calling it on storage - the behaviour is undefined

Parameters
[in]storageName- cache name
Returns
cache pointer. LMDBAL::Base keeps the ownership of the added cache, you don't need to destoroy it
Template Parameters
K- key type of the cache
V- value type of the cahce
Exceptions
std::out_of_rangethrown if cache with the given name was not found

◆ getName()

QString LMDBAL::Base::getName ( ) const

Returns database name.

Returns
database name

◆ getPath()

QString LMDBAL::Base::getPath ( ) const

Returns database name.

Returns
database path

◆ getStorage()

template<class K , class V >
LMDBAL::Storage< K, V > * LMDBAL::Base::getStorage ( const std::string & storageName)

Returns LMDBAL::Storage handle.

Requested storage must have been added before opening database Note that template parameters is user responsibility zone! If user, for instance, had added storage <int, int> but calling this method with template parameters <std::string, std::string> on the same name of the previously added storage, or calling it on cache - the behaviour is undefined

Parameters
[in]storageName- storage name
Returns
storage pointer. LMDBAL::Base keeps the ownership of the added storage, you don't need to destoroy it
Template Parameters
K- key type of the storage
V- value type of the storage
Exceptions
std::out_of_rangethrown if storage with the given name was not found

◆ open()

void LMDBAL::Base::open ( )

Opens the database.

Almost every LMDBAL::Base require it to be opened, this function does it. It laso creates the directory for the database if it was an initial launch. This function will do nothing on opened database

Exceptions
LMDBAL::Unknown- thrown if something went wrong opening storages and caches

◆ ready()

bool LMDBAL::Base::ready ( ) const

Returns database state.

Returns
true if the database is opened and ready for work, false otherwise

◆ removeDirectory()

bool LMDBAL::Base::removeDirectory ( )

Removes database directory.

Returns
true if removal was successfull of if no directory was created where it's expected to be, false otherwise
Exceptions
LMDBAL::Opened- thrown if this function was called on opened database

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