RAII transactions
All checks were successful
Main LMDBAL workfow / Archlinux (push) Successful in 40s
All checks were successful
Main LMDBAL workfow / Archlinux (push) Successful in 40s
This commit is contained in:
parent
a9aa6b549f
commit
de741eda21
22 changed files with 689 additions and 222 deletions
341
src/storage.hpp
341
src/storage.hpp
|
@ -91,10 +91,7 @@ void LMDBAL::Storage<K, V>::addRecord(const K& key, const V& value) {
|
|||
}
|
||||
|
||||
/**
|
||||
* \brief Adds a key-value record to the storage (transaction variant)
|
||||
*
|
||||
* This method schedules an addition of a key-value record, but doesn't immidiately adds it.
|
||||
* You can obtain LMDBAL::TransactionID calling LMDBAL::Base::beginTransaction().
|
||||
* \brief Adds a key-value record to the storage (private transaction variant)
|
||||
*
|
||||
* Take a note that if the storage already had a record you want to add LMDBAL::Exist is thrown.
|
||||
* If your storage doesn't support duplicates LMDBAL::Exist is thrown if the record with the same key already exists in the database.
|
||||
|
@ -105,13 +102,10 @@ void LMDBAL::Storage<K, V>::addRecord(const K& key, const V& value) {
|
|||
* \param[in] txn transaction ID, needs to be a writable transaction!
|
||||
*
|
||||
* \exception LMDBAL::Exist thrown if the storage already has a record with the given key
|
||||
* \exception LMDBAL::Closed thrown if the database was not opened
|
||||
* \exception LMDBAL::Unknown thrown if something unexpected happend within lmdb
|
||||
*/
|
||||
template<class K, class V>
|
||||
void LMDBAL::Storage<K, V>::addRecord(const K& key, const V& value, TransactionID txn) {
|
||||
ensureOpened(addRecordMethodName);
|
||||
|
||||
MDB_val lmdbKey = keySerializer.setData(key);
|
||||
MDB_val lmdbData = valueSerializer.setData(value);
|
||||
|
||||
|
@ -126,6 +120,31 @@ void LMDBAL::Storage<K, V>::addRecord(const K& key, const V& value, TransactionI
|
|||
throwDuplicateOrUnknown(rc, toString(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Adds a key-value record to the storage (public transaction variant)
|
||||
*
|
||||
* This method schedules an addition of a key-value record, but doesn't immidiately adds it.
|
||||
* You can obtain LMDBAL::WriteTransaction calling LMDBAL::Base::beginTransaction().
|
||||
*
|
||||
* Take a note that if the storage already had a record you want to add LMDBAL::Exist is thrown.
|
||||
* If your storage doesn't support duplicates LMDBAL::Exist is thrown if the record with the same key already exists in the database.
|
||||
* If your storage supports duplicates LMDBAL::Exist is thrown only if the record with the same key <b>AND</b> already exists in the database.
|
||||
*
|
||||
* \param[in] key key of the record
|
||||
* \param[in] value value of the record
|
||||
* \param[in] txn transaction
|
||||
*
|
||||
* \exception LMDBAL::Exist thrown if the storage already has a record with the given key
|
||||
* \exception LMDBAL::Closed thrown if the database was not opened
|
||||
* \exception LMDBAL::Unknown thrown if something unexpected happend within lmdb
|
||||
* \exception LMDBAL::TransactionTerminated thrown if the passed transaction not active, any action with it's inner ID is an error
|
||||
*/
|
||||
template<class K, class V>
|
||||
void LMDBAL::Storage<K, V>::addRecord(const K& key, const V& value, const WriteTransaction& txn) {
|
||||
ensureOpened(addRecordMethodName);
|
||||
addRecord(key, value, extractTransactionId(txn, addRecordMethodName));
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Adds a key-value record to the storage, overwrites if it already exists
|
||||
*
|
||||
|
@ -160,11 +179,9 @@ bool LMDBAL::Storage<K, V>::forceRecord(const K& key, const V& value) {
|
|||
}
|
||||
|
||||
/**
|
||||
* \brief Adds a key-value record to the storage, overwrites if it already exists (transaction variant)
|
||||
* \brief Adds a key-value record to the storage, overwrites if it already exists (private transaction variant)
|
||||
*
|
||||
* This method schedules an addition of a key-value record, but doesn't immidiately add it.
|
||||
* You can obtain LMDBAL::TransactionID calling LMDBAL::Base::beginTransaction().
|
||||
* If the record did already exist in the database the actual overwrite will be done only after calling LMDBAL::Base::commitTransaction().
|
||||
*
|
||||
* This method is mostly useless in duplicates mode.
|
||||
* In this mode it basically does the same thing LMDBAL::Storage::addRecord() does,
|
||||
|
@ -176,13 +193,10 @@ bool LMDBAL::Storage<K, V>::forceRecord(const K& key, const V& value) {
|
|||
* \param[in] txn transaction ID, needs to be a writable transaction!
|
||||
* \returns true if the record was added, false otherwise
|
||||
*
|
||||
* \exception LMDBAL::Closed thrown if the database was not opened
|
||||
* \exception LMDBAL::Unknown thrown if something unexpected happend within lmdb
|
||||
*/
|
||||
template<class K, class V>
|
||||
bool LMDBAL::Storage<K, V>::forceRecord(const K& key, const V& value, TransactionID txn) {
|
||||
ensureOpened(forceRecordMethodName);
|
||||
|
||||
bool added;
|
||||
if (duplicates) {
|
||||
try {
|
||||
|
@ -216,6 +230,33 @@ bool LMDBAL::Storage<K, V>::forceRecord(const K& key, const V& value, Transactio
|
|||
return added;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Adds a key-value record to the storage, overwrites if it already exists (public transaction variant)
|
||||
*
|
||||
* This method schedules an addition of a key-value record, but doesn't immidiately add it.
|
||||
* You can obtain LMDBAL::WriteTransaction calling LMDBAL::Base::beginTransaction().
|
||||
* If the record did already exist in the database the actual overwrite will be done only after calling LMDBAL::WriteTransaction::commit().
|
||||
*
|
||||
* This method is mostly useless in duplicates mode.
|
||||
* In this mode it basically does the same thing LMDBAL::Storage::addRecord() does,
|
||||
* but suppresses LMDBAL::Exist exception if the record with the same key-value pair existed in the storage.
|
||||
* In this case just false is returned from the method.
|
||||
*
|
||||
* \param[in] key key of the record
|
||||
* \param[in] value value of the record
|
||||
* \param[in] txn transaction
|
||||
* \returns true if the record was added, false otherwise
|
||||
*
|
||||
* \exception LMDBAL::Closed thrown if the database was not opened
|
||||
* \exception LMDBAL::Unknown thrown if something unexpected happend within lmdb
|
||||
* \exception LMDBAL::TransactionTerminated thrown if the passed transaction not active, any action with it's inner ID is an error
|
||||
*/
|
||||
template<class K, class V>
|
||||
bool LMDBAL::Storage<K, V>::forceRecord(const K& key, const V& value, const WriteTransaction& txn) {
|
||||
ensureOpened(forceRecordMethodName);
|
||||
return forceRecord(key, value, extractTransactionId(txn, forceRecordMethodName));
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Changes key-value record to the storage.
|
||||
*
|
||||
|
@ -251,11 +292,9 @@ void LMDBAL::Storage<K, V>::changeRecord(const K& key, const V& value) {
|
|||
}
|
||||
|
||||
/**
|
||||
* \brief Changes key-value record to the storage (transaction variant)
|
||||
* \brief Changes key-value record to the storage (private transaction variant)
|
||||
*
|
||||
* This method schedules a modification of a key-value record, but doesn't immidiately changes it.
|
||||
* You can obtain LMDBAL::TransactionID calling LMDBAL::Base::beginTransaction().
|
||||
*
|
||||
* Take a note that if the storage didn't have a record you want to change LMDBAL::NotFound is thrown
|
||||
*
|
||||
* If duplicates mode is enabled this function will find the first entry of the key
|
||||
|
@ -270,13 +309,10 @@ void LMDBAL::Storage<K, V>::changeRecord(const K& key, const V& value) {
|
|||
*
|
||||
* \exception LMDBAL::NotFound thrown if the storage doesn't have a record with the given key
|
||||
* \exception LMDBAL::Exist thrown in duplicates mode when the given value matches some of existing values for the given key
|
||||
* \exception LMDBAL::Closed thrown if the database was not opened
|
||||
* \exception LMDBAL::Unknown thrown if something unexpected happend within lmdb
|
||||
*/
|
||||
template<class K, class V>
|
||||
void LMDBAL::Storage<K, V>::changeRecord(const K& key, const V& value, TransactionID txn) {
|
||||
ensureOpened(changeRecordMethodName);
|
||||
|
||||
MDB_cursor* cursor;
|
||||
int rc = mdb_cursor_open(txn, dbi, &cursor);
|
||||
if (rc != MDB_SUCCESS)
|
||||
|
@ -313,6 +349,37 @@ void LMDBAL::Storage<K, V>::changeRecord(const K& key, const V& value, Transacti
|
|||
throwDuplicateOrUnknown(rc, toString(key));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Changes key-value record to the storage (public transaction variant)
|
||||
*
|
||||
* This method schedules a modification of a key-value record, but doesn't immidiately changes it.
|
||||
* You can obtain LMDBAL::WriteTransaction calling LMDBAL::Base::beginTransaction().
|
||||
*
|
||||
* Take a note that if the storage didn't have a record you want to change LMDBAL::NotFound is thrown
|
||||
*
|
||||
* If duplicates mode is enabled this function will find the first entry of the key
|
||||
* (which is pretty couterintuitive, see LMDBAL::Storage::getRecord() description)
|
||||
* and change it's value to the given one.
|
||||
* If the given value matches some of the other values for given key the method will throw LMDBAL::Exist,
|
||||
* if no key was found it will still throw LMDBAL::NotFound.
|
||||
*
|
||||
* \param[in] key key of the record
|
||||
* \param[in] value new value of the record
|
||||
* \param[in] txn transaction
|
||||
*
|
||||
* \exception LMDBAL::NotFound thrown if the storage doesn't have a record with the given key
|
||||
* \exception LMDBAL::Exist thrown in duplicates mode when the given value matches some of existing values for the given key
|
||||
* \exception LMDBAL::Closed thrown if the database was not opened
|
||||
* \exception LMDBAL::Unknown thrown if something unexpected happend within lmdb
|
||||
* \exception LMDBAL::TransactionTerminated thrown if the passed transaction not active, any action with it's inner ID is an error
|
||||
*/
|
||||
template<class K, class V>
|
||||
void LMDBAL::Storage<K, V>::changeRecord(const K& key, const V& value, const WriteTransaction& txn) {
|
||||
ensureOpened(changeRecordMethodName);
|
||||
changeRecord(key, value, extractTransactionId(txn, changeRecordMethodName));
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Gets the record from the database
|
||||
|
||||
|
@ -374,10 +441,7 @@ void LMDBAL::Storage<K, V>::getRecord(const K& key, V& value) const {
|
|||
}
|
||||
|
||||
/**
|
||||
* \brief Gets the record from the database (transaction variant)
|
||||
*
|
||||
* You can obtain LMDBAL::TransactionID calling LMDBAL::Base::beginReadOnlyTransaction() or LMDBAL::Base::beginTransaction().
|
||||
* If you just want to read data you should prefer LMDBAL::Base::beginReadOnlyTransaction().
|
||||
* \brief Gets the record from the database (private transaction variant)
|
||||
*
|
||||
* Take a note that if the storage didn't have a record you want to get LMDBAL::NotFound is thrown
|
||||
*
|
||||
|
@ -392,22 +456,19 @@ void LMDBAL::Storage<K, V>::getRecord(const K& key, V& value) const {
|
|||
* \returns the value from the storage
|
||||
*
|
||||
* \exception LMDBAL::NotFound thrown if the storage doesn't have a record with the given key
|
||||
* \exception LMDBAL::Closed thrown if the database was not opened
|
||||
* \exception LMDBAL::Unknown thrown if something unexpected happend within lmdb
|
||||
*/
|
||||
template<class K, class V>
|
||||
V LMDBAL::Storage<K, V>::getRecord(const K& key, TransactionID txn) const {
|
||||
ensureOpened(getRecordMethodName);
|
||||
|
||||
V value;
|
||||
Storage<K, V>::getRecord(key, value, txn);
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Gets the record from the database (transaction, reference variant)
|
||||
* \brief Gets the record from the database (public transaction variant)
|
||||
*
|
||||
* You can obtain LMDBAL::TransactionID calling LMDBAL::Base::beginReadOnlyTransaction() or LMDBAL::Base::beginTransaction().
|
||||
* You can obtain LMDBAL::Transaction calling LMDBAL::Base::beginReadOnlyTransaction() or LMDBAL::Base::beginTransaction().
|
||||
* If you just want to read data you should prefer LMDBAL::Base::beginReadOnlyTransaction().
|
||||
*
|
||||
* Take a note that if the storage didn't have a record you want to get LMDBAL::NotFound is thrown
|
||||
|
@ -419,17 +480,40 @@ V LMDBAL::Storage<K, V>::getRecord(const K& key, TransactionID txn) const {
|
|||
* - if your values are anything else - they are compared byte by byte as if they are strings, it makes it especially complicated to predict the exact value for float or double templated storages. For strings if makes a bit more sence: if the choise is from "50" and "100" - "100" is returned, because the first byte of the "100" is lower than the first byte of the "50"
|
||||
*
|
||||
* \param[in] key key of the record you look for
|
||||
* \param[in] txn transaction ID, can be read only transaction
|
||||
* \returns the value from the storage
|
||||
*
|
||||
* \exception LMDBAL::NotFound thrown if the storage doesn't have a record with the given key
|
||||
* \exception LMDBAL::Closed thrown if the database was not opened
|
||||
* \exception LMDBAL::Unknown thrown if something unexpected happend within lmdb
|
||||
* \exception LMDBAL::TransactionTerminated thrown if the passed transaction not active, any action with it's inner ID is an error
|
||||
*/
|
||||
template<class K, class V>
|
||||
V LMDBAL::Storage<K, V>::getRecord(const K& key, const Transaction& txn) const {
|
||||
ensureOpened(getRecordMethodName);
|
||||
return getRecord(key, extractTransactionId(txn, getRecordMethodName));
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Gets the record from the database (private transaction, reference variant)
|
||||
*
|
||||
* Take a note that if the storage didn't have a record you want to get LMDBAL::NotFound is thrown
|
||||
*
|
||||
* If the storage supports duplicates the exact value returned from it depends on comparison function of lmdb.
|
||||
* It's not very straight forward, so, you shouldn't really use this method if you use duplicates and you rely on exact result.
|
||||
* Anyway:
|
||||
* - if your values are signed or unsigned integer of any size the LOWEST value is returned compared as <b>UNSIGNED</b>. For example for storage with int32_t as value, from the same key, from the set of values {-33, -1, 5573, 77753} 5573 is returned as it is the lowest by <b>UNSIGNED</b> comparison.
|
||||
* - if your values are anything else - they are compared byte by byte as if they are strings, it makes it especially complicated to predict the exact value for float or double templated storages. For strings if makes a bit more sence: if the choise is from "50" and "100" - "100" is returned, because the first byte of the "100" is lower than the first byte of the "50"
|
||||
*
|
||||
* \param[in] key key of the record you look for
|
||||
* \param[out] value the value from the storage
|
||||
* \param[in] txn transaction ID, can be read only transaction
|
||||
*
|
||||
* \exception LMDBAL::NotFound thrown if the storage doesn't have a record with the given key
|
||||
* \exception LMDBAL::Closed thrown if the database was not opened
|
||||
* \exception LMDBAL::Unknown thrown if something unexpected happend within lmdb
|
||||
*/
|
||||
template<class K, class V>
|
||||
void LMDBAL::Storage<K, V>::getRecord(const K& key, V& value, TransactionID txn) const {
|
||||
ensureOpened(getRecordMethodName);
|
||||
|
||||
MDB_val lmdbKey = keySerializer.setData(key);
|
||||
MDB_val lmdbData;
|
||||
|
||||
|
@ -440,6 +524,36 @@ void LMDBAL::Storage<K, V>::getRecord(const K& key, V& value, TransactionID txn)
|
|||
valueSerializer.deserialize(lmdbData, value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Gets the record from the database (public transaction, reference variant)
|
||||
*
|
||||
* You can obtain LMDBAL::Transaction calling LMDBAL::Base::beginReadOnlyTransaction() or LMDBAL::Base::beginTransaction().
|
||||
* If you just want to read data you should prefer LMDBAL::Base::beginReadOnlyTransaction().
|
||||
*
|
||||
* Take a note that if the storage didn't have a record you want to get LMDBAL::NotFound is thrown
|
||||
*
|
||||
* If the storage supports duplicates the exact value returned from it depends on comparison function of lmdb.
|
||||
* It's not very straight forward, so, you shouldn't really use this method if you use duplicates and you rely on exact result.
|
||||
* Anyway:
|
||||
* - if your values are signed or unsigned integer of any size the LOWEST value is returned compared as <b>UNSIGNED</b>. For example for storage with int32_t as value, from the same key, from the set of values {-33, -1, 5573, 77753} 5573 is returned as it is the lowest by <b>UNSIGNED</b> comparison.
|
||||
* - if your values are anything else - they are compared byte by byte as if they are strings, it makes it especially complicated to predict the exact value for float or double templated storages. For strings if makes a bit more sence: if the choise is from "50" and "100" - "100" is returned, because the first byte of the "100" is lower than the first byte of the "50"
|
||||
*
|
||||
* \param[in] key key of the record you look for
|
||||
* \param[out] value the value from the storage
|
||||
* \param[in] txn transaction ID, can be read only transaction
|
||||
*
|
||||
* \exception LMDBAL::NotFound thrown if the storage doesn't have a record with the given key
|
||||
* \exception LMDBAL::Closed thrown if the database was not opened
|
||||
* \exception LMDBAL::Unknown thrown if something unexpected happend within lmdb
|
||||
* \exception LMDBAL::TransactionTerminated thrown if the passed transaction not active, any action with it's inner ID is an error
|
||||
*/
|
||||
template<class K, class V>
|
||||
void LMDBAL::Storage<K, V>::getRecord(const K& key, V& value, const Transaction& txn) const {
|
||||
ensureOpened(getRecordMethodName);
|
||||
getRecord(key, value, extractTransactionId(txn, getRecordMethodName));
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Chechs if storage has value
|
||||
*
|
||||
|
@ -467,22 +581,16 @@ bool LMDBAL::Storage<K, V>::checkRecord(const K& key) const {
|
|||
}
|
||||
|
||||
/**
|
||||
* \brief Chechs if storage has value (transaction variant)
|
||||
*
|
||||
* You can obtain LMDBAL::TransactionID calling LMDBAL::Base::beginReadOnlyTransaction() or LMDBAL::Base::beginTransaction().
|
||||
* If you just want to read data you should prefer LMDBAL::Base::beginReadOnlyTransaction().
|
||||
* \brief Chechs if storage has value (private transaction variant)
|
||||
*
|
||||
* \param[in] key key of the record you look for
|
||||
* \param[in] txn transaction ID, can be read only transaction
|
||||
* \returns true if there was a record with given key, false otherwise
|
||||
*
|
||||
* \exception LMDBAL::Closed thrown if the database was not opened
|
||||
* \exception LMDBAL::Unknown thrown if something unexpected happend within lmdb
|
||||
*/
|
||||
template<class K, class V>
|
||||
bool LMDBAL::Storage<K, V>::checkRecord(const K& key, TransactionID txn) const {
|
||||
ensureOpened(checkRecordMethodName);
|
||||
|
||||
MDB_val lmdbKey = keySerializer.setData(key);
|
||||
MDB_val lmdbData;
|
||||
|
||||
|
@ -496,6 +604,26 @@ bool LMDBAL::Storage<K, V>::checkRecord(const K& key, TransactionID txn) const {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Chechs if storage has value (public transaction variant)
|
||||
*
|
||||
* You can obtain LMDBAL::Transaction calling LMDBAL::Base::beginReadOnlyTransaction() or LMDBAL::Base::beginTransaction().
|
||||
* If you just want to read data you should prefer LMDBAL::Base::beginReadOnlyTransaction().
|
||||
*
|
||||
* \param[in] key key of the record you look for
|
||||
* \param[in] txn transaction, can be read only transaction
|
||||
* \returns true if there was a record with given key, false otherwise
|
||||
*
|
||||
* \exception LMDBAL::Closed thrown if the database was not opened
|
||||
* \exception LMDBAL::Unknown thrown if something unexpected happend within lmdb
|
||||
* \exception LMDBAL::TransactionTerminated thrown if the passed transaction not active, any action with it's inner ID is an error
|
||||
*/
|
||||
template<class K, class V>
|
||||
bool LMDBAL::Storage<K, V>::checkRecord(const K& key, const Transaction& txn) const {
|
||||
ensureOpened(checkRecordMethodName);
|
||||
return checkRecord(key, extractTransactionId(txn, checkRecordMethodName));
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads whole storage into a map
|
||||
*
|
||||
|
@ -545,31 +673,25 @@ void LMDBAL::Storage<K, V>::readAll(std::map<K, V>& result) const {
|
|||
}
|
||||
|
||||
/**
|
||||
* \brief Reads whole storage into a map (transaction variant)
|
||||
* \brief Reads whole storage into a map (private transaction variant)
|
||||
*
|
||||
* Basically just reads all database in an std::map, usefull when you store small storages
|
||||
* You can obtain LMDBAL::TransactionID calling LMDBAL::Base::beginReadOnlyTransaction() or LMDBAL::Base::beginTransaction().
|
||||
* If you just want to read data you should prefer LMDBAL::Base::beginReadOnlyTransaction().
|
||||
*
|
||||
* In case storage supports duplicates <b>only what lmdb considered to be lowest value</b>
|
||||
* (see LMDBAL::Storage::getRecord() description) is returned in the resulting map
|
||||
*
|
||||
* \param[in] txn transaction ID, can be read only transaction
|
||||
*
|
||||
* \exception LMDBAL::Closed thrown if the database was not opened
|
||||
* \exception LMDBAL::Unknown thrown if something unexpected happend within lmdb
|
||||
*/
|
||||
template<class K, class V>
|
||||
std::map<K, V> LMDBAL::Storage<K, V>::readAll(TransactionID txn) const {
|
||||
ensureOpened(readAllMethodName);
|
||||
|
||||
std::map<K, V> result;
|
||||
Storage<K, V>::readAll(result, txn);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads whole storage into a map (transaction, reference variant)
|
||||
* \brief Reads whole storage into a map (public transaction variant)
|
||||
*
|
||||
* Basically just reads all database in an std::map, usefull when you store small storages
|
||||
* You can obtain LMDBAL::TransactionID calling LMDBAL::Base::beginReadOnlyTransaction() or LMDBAL::Base::beginTransaction().
|
||||
|
@ -578,16 +700,32 @@ std::map<K, V> LMDBAL::Storage<K, V>::readAll(TransactionID txn) const {
|
|||
* In case storage supports duplicates <b>only what lmdb considered to be lowest value</b>
|
||||
* (see LMDBAL::Storage::getRecord() description) is returned in the resulting map
|
||||
*
|
||||
* \param[in] txn transaction, can be read only transaction
|
||||
*
|
||||
* \exception LMDBAL::Closed thrown if the database was not opened
|
||||
* \exception LMDBAL::Unknown thrown if something unexpected happend within lmdb
|
||||
* \exception LMDBAL::TransactionTerminated thrown if the passed transaction not active, any action with it's inner ID is an error
|
||||
*/
|
||||
template<class K, class V>
|
||||
std::map<K, V> LMDBAL::Storage<K, V>::readAll(const Transaction& txn) const {
|
||||
ensureOpened(readAllMethodName);
|
||||
return readAll(extractTransactionId(txn, readAllMethodName));
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads whole storage into a map (private transaction, reference variant)
|
||||
*
|
||||
* Basically just reads all database in an std::map, usefull when you store small storages
|
||||
* In case storage supports duplicates <b>only what lmdb considered to be lowest value</b>
|
||||
* (see LMDBAL::Storage::getRecord() description) is returned in the resulting map
|
||||
*
|
||||
* \param[out] result a map that is going to contain all data
|
||||
* \param[in] txn transaction ID, can be read only transaction
|
||||
*
|
||||
* \exception LMDBAL::Closed thrown if the database was not opened
|
||||
* \exception LMDBAL::Unknown thrown if something unexpected happend within lmdb
|
||||
*/
|
||||
template<class K, class V>
|
||||
void LMDBAL::Storage<K, V>::readAll(std::map<K, V>& result, TransactionID txn) const {
|
||||
ensureOpened(readAllMethodName);
|
||||
|
||||
MDB_cursor* cursor;
|
||||
MDB_val lmdbKey, lmdbData;
|
||||
|
||||
|
@ -610,6 +748,29 @@ void LMDBAL::Storage<K, V>::readAll(std::map<K, V>& result, TransactionID txn) c
|
|||
throwUnknown(rc);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Reads whole storage into a map (public transaction, reference variant)
|
||||
*
|
||||
* Basically just reads all database in an std::map, usefull when you store small storages
|
||||
* You can obtain LMDBAL::Transaction calling LMDBAL::Base::beginReadOnlyTransaction() or LMDBAL::Base::beginTransaction().
|
||||
* If you just want to read data you should prefer LMDBAL::Base::beginReadOnlyTransaction().
|
||||
*
|
||||
* In case storage supports duplicates <b>only what lmdb considered to be lowest value</b>
|
||||
* (see LMDBAL::Storage::getRecord() description) is returned in the resulting map
|
||||
*
|
||||
* \param[out] result a map that is going to contain all data
|
||||
* \param[in] txn transaction, can be read only transaction
|
||||
*
|
||||
* \exception LMDBAL::Closed thrown if the database was not opened
|
||||
* \exception LMDBAL::Unknown thrown if something unexpected happend within lmdb
|
||||
* \exception LMDBAL::TransactionTerminated thrown if the passed transaction not active, any action with it's inner ID is an error
|
||||
*/
|
||||
template<class K, class V>
|
||||
void LMDBAL::Storage<K, V>::readAll(std::map<K, V>& result, const Transaction& txn) const {
|
||||
ensureOpened(readAllMethodName);
|
||||
readAll(result, extractTransactionId(txn, readAllMethodName));
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Replaces the content of the whole storage with the given
|
||||
*
|
||||
|
@ -636,22 +797,17 @@ void LMDBAL::Storage<K, V>::replaceAll(const std::map<K, V>& data) {
|
|||
}
|
||||
|
||||
/**
|
||||
* \brief Replaces the content of the whole storage with the given (transaction variant)
|
||||
* \brief Replaces the content of the whole storage with the given (private transaction variant)
|
||||
*
|
||||
* Basically this method drops the database and adds all the records from the given map
|
||||
* This method schedules a data replacement, but doesn't immidiately execute it.
|
||||
* You can obtain LMDBAL::TransactionID calling LMDBAL::Base::beginTransaction().
|
||||
*
|
||||
* \param[in] data new data of the storage
|
||||
* \param[in] txn transaction ID, needs to be a writable transaction!
|
||||
*
|
||||
* \exception LMDBAL::Closed thrown if the database was not opened
|
||||
* \exception LMDBAL::Unknown thrown if something unexpected happend within lmdb
|
||||
*/
|
||||
template<class K, class V>
|
||||
void LMDBAL::Storage<K, V>::replaceAll(const std::map<K, V>& data, TransactionID txn) {
|
||||
ensureOpened(replaceAllMethodName);
|
||||
|
||||
int rc = drop(txn);
|
||||
if (rc != MDB_SUCCESS)
|
||||
throwUnknown(rc);
|
||||
|
@ -667,6 +823,26 @@ void LMDBAL::Storage<K, V>::replaceAll(const std::map<K, V>& data, TransactionID
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Replaces the content of the whole storage with the given (public transaction variant)
|
||||
*
|
||||
* Basically this method drops the database and adds all the records from the given map
|
||||
* This method schedules a data replacement, but doesn't immidiately execute it.
|
||||
* You can obtain LMDBAL::Transaction calling LMDBAL::Base::beginTransaction().
|
||||
*
|
||||
* \param[in] data new data of the storage
|
||||
* \param[in] txn transaction
|
||||
*
|
||||
* \exception LMDBAL::Closed thrown if the database was not opened
|
||||
* \exception LMDBAL::Unknown thrown if something unexpected happend within lmdb
|
||||
* \exception LMDBAL::TransactionTerminated thrown if the passed transaction not active, any action with it's inner ID is an error
|
||||
*/
|
||||
template<class K, class V>
|
||||
void LMDBAL::Storage<K, V>::replaceAll(const std::map<K, V>& data, const WriteTransaction& txn) {
|
||||
ensureOpened(replaceAllMethodName);
|
||||
replaceAll(data, extractTransactionId(txn, replaceAllMethodName));
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Adds records in bulk
|
||||
*
|
||||
|
@ -696,24 +872,20 @@ uint32_t LMDBAL::Storage<K, V>::addRecords(const std::map<K, V>& data, bool over
|
|||
}
|
||||
|
||||
/**
|
||||
* \brief Adds records in bulk (transaction variant)
|
||||
* \brief Adds records in bulk (private transaction variant)
|
||||
*
|
||||
* This method schedules a data addition, but doesn't immidiately execute it.
|
||||
* You can obtain LMDBAL::TransactionID calling LMDBAL::Base::beginTransaction().
|
||||
*
|
||||
* \param[in] data the data to be added
|
||||
* \param[in] txn transaction ID, needs to be a writable transaction!
|
||||
* \param[in] overwrite if false method throws LMDBAL::Exist on repeated key, if true - overwrites it
|
||||
* \returns new actual amount of records in the storage
|
||||
*
|
||||
* \exception LMDBAL::Closed thrown if the database was not opened
|
||||
* \exception LMDBAL::Exist thrown if overwrite==false and at least one of the keys of data already exists in the storage
|
||||
* \exception LMDBAL::Unknown thrown if something unexpected happend within lmdb
|
||||
*/
|
||||
template<class K, class V>
|
||||
uint32_t LMDBAL::Storage<K, V>::addRecords(const std::map<K, V>& data, TransactionID txn, bool overwrite) {
|
||||
ensureOpened(addRecordsMethodName);
|
||||
|
||||
MDB_val lmdbKey, lmdbData;
|
||||
int rc;
|
||||
for (const std::pair<const K, V>& pair : data) {
|
||||
|
@ -736,6 +908,28 @@ uint32_t LMDBAL::Storage<K, V>::addRecords(const std::map<K, V>& data, Transacti
|
|||
return stat.ms_entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Adds records in bulk (public transaction variant)
|
||||
*
|
||||
* This method schedules a data addition, but doesn't immidiately execute it.
|
||||
* You can obtain LMDBAL::Transaction calling LMDBAL::Base::beginTransaction().
|
||||
*
|
||||
* \param[in] data the data to be added
|
||||
* \param[in] txn transaction
|
||||
* \param[in] overwrite if false method throws LMDBAL::Exist on repeated key, if true - overwrites it
|
||||
* \returns new actual amount of records in the storage
|
||||
*
|
||||
* \exception LMDBAL::Closed thrown if the database was not opened
|
||||
* \exception LMDBAL::Exist thrown if overwrite==false and at least one of the keys of data already exists in the storage
|
||||
* \exception LMDBAL::Unknown thrown if something unexpected happend within lmdb
|
||||
* \exception LMDBAL::TransactionTerminated thrown if the passed transaction not active, any action with it's inner ID is an error
|
||||
*/
|
||||
template<class K, class V>
|
||||
uint32_t LMDBAL::Storage<K, V>::addRecords(const std::map<K, V>& data, const WriteTransaction& txn, bool overwrite) {
|
||||
ensureOpened(addRecordsMethodName);
|
||||
return addRecords(data, extractTransactionId(txn, addRecordsMethodName), overwrite);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Removes one of the records
|
||||
*
|
||||
|
@ -763,29 +957,46 @@ void LMDBAL::Storage<K, V>::removeRecord(const K& key) {
|
|||
}
|
||||
|
||||
/**
|
||||
* \brief Removes one of the records (transaction variant)
|
||||
* \brief Removes one of the records (private transaction variant)
|
||||
*
|
||||
* Take a note that if the storage didn't have a record you want to remove LMDBAL::NotFound is thrown
|
||||
* This method schedules a record removal, but doesn't immidiately execute it.
|
||||
* You can obtain LMDBAL::TransactionID calling LMDBAL::Base::beginTransaction().
|
||||
*
|
||||
* \param[in] key key of the record you wish to be removed
|
||||
* \param[in] txn transaction ID, needs to be a writable transaction!
|
||||
*
|
||||
* \exception LMDBAL::Closed thrown if the database was not opened
|
||||
* \exception LMDBAL::NotFound thrown if the record with given key wasn't found
|
||||
* \exception LMDBAL::Unknown thrown if something unexpected happend within lmdb
|
||||
*/
|
||||
template<class K, class V>
|
||||
void LMDBAL::Storage<K, V>::removeRecord(const K& key, TransactionID txn) {
|
||||
ensureOpened(removeRecordMethodName);
|
||||
|
||||
MDB_val lmdbKey = keySerializer.setData(key);
|
||||
int rc = mdb_del(txn, dbi, &lmdbKey, NULL);
|
||||
if (rc != MDB_SUCCESS)
|
||||
throwNotFoundOrUnknown(rc, toString(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Removes one of the records (transaction variant)
|
||||
*
|
||||
* Take a note that if the storage didn't have a record you want to remove LMDBAL::NotFound is thrown
|
||||
* This method schedules a record removal, but doesn't immidiately execute it.
|
||||
* You can obtain LMDBAL::Transaction calling LMDBAL::Base::beginTransaction().
|
||||
*
|
||||
* \param[in] key key of the record you wish to be removed
|
||||
* \param[in] txn transaction ID
|
||||
*
|
||||
* \exception LMDBAL::Closed thrown if the database was not opened
|
||||
* \exception LMDBAL::NotFound thrown if the record with given key wasn't found
|
||||
* \exception LMDBAL::Unknown thrown if something unexpected happend within lmdb
|
||||
* \exception LMDBAL::TransactionTerminated thrown if the passed transaction not active, any action with it's inner ID is an error
|
||||
*/
|
||||
template<class K, class V>
|
||||
void LMDBAL::Storage<K, V>::removeRecord(const K& key, const WriteTransaction& txn) {
|
||||
ensureOpened(removeRecordMethodName);
|
||||
removeRecord(key, extractTransactionId(txn, removeRecordMethodName));
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief A private virtual method I need to open each storage in the database
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue