27#include "transaction.h"
35 friend class CursorCommon;
39 virtual ~ StorageCommon();
47 virtual int open(MDB_txn * transaction) = 0;
52 const std::string&
dbName()
const;
74 virtual int drop(TransactionID transaction);
75 virtual SizeType
count(TransactionID txn)
const;
82 int _mdbOpen(MDB_txn* txn,
unsigned int flags = 0);
84 int _mdbPut(MDB_txn* txn, MDB_val& key, MDB_val& data,
unsigned int flags = 0);
85 int _mdbGet(MDB_txn* txn, MDB_val& key, MDB_val& data)
const;
86 int _mdbDel(MDB_txn* txn, MDB_val& key);
87 int _mdbDel(MDB_txn* txn, MDB_val& key, MDB_val& data);
89 int _mdbStat(MDB_txn* txn, MDB_stat& stat)
const;
90 int _mdbFlags(MDB_txn* txn, uint32_t& flags)
const;
92 int _mdbCursorOpen(MDB_txn* txn, MDB_cursor** cursor)
const;
93 void _mdbCursorClose(MDB_cursor* cursor)
const;
94 int _mdbCursorGet(MDB_cursor* cursor, MDB_val& key, MDB_val& data, MDB_cursor_op operation)
const;
95 int _mdbCursorSet(MDB_cursor* cursor, MDB_val& key)
const;
96 int _mdbCursorDel(MDB_cursor* cursor,
unsigned int flags = 0);
97 int _mdbCursorPut(MDB_cursor* cursor, MDB_val& key, MDB_val& data,
unsigned int flags = 0);
99 int _mdbCursorRenew(MDB_txn* txn, MDB_cursor* cursor)
const;
100 MDB_txn* _mdbCursorTxn(MDB_cursor* cursor)
const;
105 virtual SizeType
count()
const;
130 template <
class K,
class V>
134 static std::string
toString(
const T& value);
139#include "storagecommon.hpp"
An object to manage cursor internals and state.
Definition cursorcommon.h:31
StorageCommon(Base *parent, const std::string &name, bool duplicates=false)
Constructs a storage interface.
Definition storagecommon.cpp:42
void commitTransaction(TransactionID id)
Commits transaction.
Definition storagecommon.cpp:454
static const std::string getRecordMethodName
member function name, just for exceptions
Definition storagecommon.h:123
virtual void transactionCommited(TransactionID txn)
called on commitment of public transaction
Definition storagecommon.cpp:485
void throwNotFound(const std::string &key) const
Throws LMDBAL::NotFound.
Definition storagecommon.cpp:404
void throwCursorNotReady(const std::string &method) const
Throws LMDBAL::CursorNotReady.
Definition storagecommon.cpp:416
TransactionID beginReadOnlyTransaction() const
Begins read-only transaction.
Definition storagecommon.cpp:426
static const std::string openCursorTransactionMethodName
member function name, just for exceptions
Definition storagecommon.h:127
int makeStorage(MDB_txn *transaction, bool duplicates=false)
A functiion to actually open MDB_dbi storage.
Definition storagecommon.hpp:38
void abortTransaction(TransactionID id) const
Aborts transaction.
Definition storagecommon.cpp:444
static std::string toString(const T &value)
A method to cast a value (which can be a value or a key) to string.
Definition storagecommon.hpp:71
static const std::string forceRecordMethodName
member function name, just for exceptions
Definition storagecommon.h:119
Transaction * getTransactionForCursor(MDB_cursor *cursor) const
Retrieves public transaction object for a cursor handle.
Definition storagecommon.cpp:173
virtual SizeType count() const
Storage size.
Definition storagecommon.cpp:148
virtual void close()
A private virtual function to close each storage in the database.
Definition storagecommon.cpp:57
static const std::string countMethodName
member function name, just for exceptions
Definition storagecommon.h:115
static const std::string flagsMethodName
member function name, just for exceptions
Definition storagecommon.h:116
const std::string name
this storage name
Definition storagecommon.h:111
static const std::string checkRecordMethodName
member function name, just for exceptions
Definition storagecommon.h:122
virtual void handleDrop()
A method where database additionally handles drop.
Definition storagecommon.cpp:508
virtual int open(MDB_txn *transaction)=0
A private virtual function I need to open each storage in the database.
const std::string & dbName() const
Database name.
Definition storagecommon.cpp:346
static const std::string dropMethodName
member function name, just for exceptions
Definition storagecommon.h:114
TransactionID extractTransactionId(const Transaction &txn, const std::string &action="") const
Checks if the transaction is still active, returns inner TransactionID.
Definition storagecommon.cpp:72
static const std::string readAllMethodName
member function name, just for exceptions
Definition storagecommon.h:124
void closeCursorTransaction(MDB_cursor *cursor, bool closeCursor=false) const
Closes transaction that is private to LMDBAL::Cursor, but public to the LMDBAL::Storage.
Definition storagecommon.cpp:213
static const std::string changeRecordMethodName
member function name, just for exceptions
Definition storagecommon.h:120
void throwDuplicate(const std::string &key) const
Throws LMDBAL::Exist.
Definition storagecommon.cpp:392
virtual void transactionAborted(TransactionID txn) const
called on abortion of public transaction
Definition storagecommon.cpp:499
static const std::string addRecordsMethodName
member function name, just for exceptions
Definition storagecommon.h:126
void throwUnknown(int rc, TransactionID txn) const
Throws LMDBAL::Unknown (transaction vairiant)
Definition storagecommon.cpp:334
MDB_dbi dbi
lmdb storage handle
Definition storagecommon.h:109
void throwDuplicateOrUnknown(int rc, const std::string &key) const
Throws LMDBAL::Exist or LMDBAL::Unknown.
Definition storagecommon.cpp:299
void throwNotFoundOrUnknown(int rc, const std::string &key) const
Throws LMDBAL::NotFound or LMDBAL::Unknown (transaction variant)
Definition storagecommon.cpp:317
TransactionID beginTransaction() const
Begins writable transaction.
Definition storagecommon.cpp:436
static const std::string addRecordMethodName
member function name, just for exceptions
Definition storagecommon.h:118
const bool duplicates
true if storage supports duplicates
Definition storagecommon.h:112
void ensureOpened(const std::string &methodName) const
Helper function, thows exception if the database is not opened.
Definition storagecommon.cpp:135
static const std::string replaceAllMethodName
member function name, just for exceptions
Definition storagecommon.h:125
static const std::string removeRecordMethodName
member function name, just for exceptions
Definition storagecommon.h:121
bool isDBOpened() const
Is database opened.
Definition storagecommon.cpp:356
void openCursorTransaction(MDB_cursor **cursor, bool renew=false) const
Opens a transaction that is ment to be private to LMDBAL::Cursor, but public to the LMDBAL::Storage.
Definition storagecommon.cpp:189
virtual void transactionStarted(TransactionID txn, bool readOnly) const
called on beginning of public transaction
Definition storagecommon.cpp:469
Base * db
parent database pointer (borrowed)
Definition storagecommon.h:110
virtual void drop()
Drops content of a storage interface.
Definition storagecommon.cpp:87
Public read only transaction.
Definition transaction.h:27
Public writable transaction.
Definition transaction.h:54