34#include "exceptions.h"
46template <
class K,
class V>
49template <
class K,
class V>
56 friend class StorageCommon;
57 friend class Transaction;
58 friend class WriteTransaction;
62 Base(
const QString& path,
const QString& name = QString(), uint16_t mapSize = 10);
76 template <
class K,
class V>
79 template <
class K,
class V>
82 template <
class K,
class V>
85 template <
class K,
class V>
89 typedef std::map<std::string, LMDBAL::StorageCommon *> Storages;
90 typedef std::map<TransactionID, Transaction*> Transactions;
91 typedef std::set<Session*> Sessions;
97 void commitTransaction(
TransactionID id, std::string_view storageName);
98 void abortTransaction(
TransactionID id, std::string_view storageName)
const;
100 TransactionID beginPrivateReadOnlyTransaction(std::string_view storageName)
const;
101 TransactionID beginPrivateTransaction(std::string_view storageName)
const;
102 void commitPrivateTransaction(
TransactionID id, std::string_view storageName);
103 void abortPrivateTransaction(
TransactionID id, std::string_view storageName)
const;
105 void registerSession(Session* session);
106 void unregisterSession(Session* session);
107 void replaceSession(Session* closing, Session* opening);
117 MDB_env* environment;
119 mutable Transactions transactions;
122 inline static constexpr std::string_view emptyName =
"";
123 inline static constexpr std::string_view beginReadOnlyTransactionMethodName =
"beginReadOnlyTransaction";
124 inline static constexpr std::string_view beginTransactionMethodName =
"beginTransaction";
125 inline static constexpr std::string_view abortTransactionMethodName =
"abortTransaction";
126 inline static constexpr std::string_view commitTransactionMethodName =
"commitTransaction";
130#include "operators.hpp"
149template <
class K,
class V>
152 throw Opened(name,
"add storage " + storageName);
154 auto storage =
new Storage<K, V>(
this, storageName, duplicates);
155 std::pair<Storages::const_iterator, bool> pair = storages.emplace(storageName,
static_cast<StorageCommon *
>(storage));
177template<
class K,
class V>
180 throw Opened(name,
"add cache " + storageName);
182 auto cache =
new Cache<K, V>(
this, storageName,
false);
183 std::pair<Storages::const_iterator, bool> pair = storages.emplace(storageName,
static_cast<StorageCommon *
>(cache));
207template <
class K,
class V>
209 return static_cast<Storage<K, V>*
>(storages.at(storageName));
229template <
class K,
class V>
231 return static_cast<Cache<K, V>*
>(storages.at(storageName));
bool opened() const
Returns database state.
Definition base.cpp:149
Transaction beginReadOnlyTransaction() const
Begins read-only transaction.
Definition base.cpp:195
LMDBAL::Cache< K, V > * getCache(const std::string &storageName)
Returns LMDBAL::Cache handle.
Definition base.h:230
void drop()
Drops the database.
Definition base.cpp:161
WriteTransaction beginTransaction()
Begins writable transaction.
Definition base.cpp:218
QString getName() const
Returns database name.
Definition base.cpp:132
LMDBAL::Cache< K, V > * addCache(const std::string &storageName)
Adds LMDBAL::Cache to the database.
Definition base.h:178
LMDBAL::Storage< K, V > * addStorage(const std::string &storageName, bool duplicates=false)
Adds LMDBAL::Storage to the database.
Definition base.h:150
LMDBAL::Storage< K, V > * getStorage(const std::string &storageName)
Returns LMDBAL::Storage handle.
Definition base.h:208
bool removeDirectory()
Removes database directory.
Definition base.cpp:85
~Base()
Destroys the database.
Definition base.cpp:60
Base(const QString &path, const QString &name=QString(), uint16_t mapSize=10)
Creates the database.
Definition base.cpp:43
QString getPath() const
Returns database name.
Definition base.cpp:140
bool createDirectory()
Creates database directory.
Definition base.cpp:111
Storage with additional caching in std::map.
Definition cache.h:30
Thrown if something in the database was called on opened state and it is not supported.
Definition exceptions.h:118
A class handling serialization/deserialization.
Definition serializer.h:35
RAII guard that keeps the database environment active.
Definition session.h:25
Storage interface.
Definition storagecommon.h:34
Thrown if there was attempt to define storages with conflicting names.
Definition exceptions.h:154
This is a basic key value storage.
Definition storage.h:38
Public read only transaction.
Definition transaction.h:27
Public writable transaction.
Definition transaction.h:54
Destroys a cache.
Definition base.h:36
MDB_txn * TransactionID
I'm going to use transaction pointers as transaction IDs.
Definition base.h:52
uint32_t SizeType
All LMDBAL sizes are uint32.
Definition base.h:53