forked from blue/lmdbal
RAII transactions
This commit is contained in:
parent
a9aa6b549f
commit
de741eda21
22 changed files with 689 additions and 222 deletions
|
@ -20,6 +20,7 @@
|
|||
#define LMDBAL_CURSOR_HPP
|
||||
|
||||
#include "cursor.h"
|
||||
#include <iostream>
|
||||
|
||||
/**
|
||||
* \class LMDBAL::Cursor
|
||||
|
@ -79,8 +80,8 @@ void LMDBAL::Cursor<K, V>::terminated () const {
|
|||
* This function should be called when the LMDBAL::Storage is already opened and before any query with this cursor!
|
||||
* It will do nothing to a cursor that was already opened (no matter what way).
|
||||
*
|
||||
* \throws LMDBAL::Closed thrown if you try to open the cursor on a closed database
|
||||
* \throws LMDBAL::Unknown thrown if there was a problem opening the cursor by the lmdb, or to begin a transaction
|
||||
* \exception LMDBAL::Closed thrown if you try to open the cursor on a closed database
|
||||
* \exception LMDBAL::Unknown thrown if there was a problem opening the cursor by the lmdb, or to begin a transaction
|
||||
*/
|
||||
template<class K, class V>
|
||||
void LMDBAL::Cursor<K, V>::open () const {
|
||||
|
@ -109,12 +110,16 @@ void LMDBAL::Cursor<K, V>::open () const {
|
|||
* This function should be called when the LMDBAL::Storage is already opened and before any query with this cursor!
|
||||
* It will do nothing to a cursor that was already opened (no matter what way).
|
||||
*
|
||||
* \throws LMDBAL::Closed thrown if you try to open the cursor on a closed database
|
||||
* \throws LMDBAL::Unknown thrown if there was a problem opening the cursor by the lmdb
|
||||
* \param[in] transaction - a transaction, can be read only
|
||||
*
|
||||
* \exception LMDBAL::Closed thrown if you try to open the cursor on a closed database
|
||||
* \exception LMDBAL::Unknown thrown if there was a problem opening the cursor by the 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::Cursor<K, V>::open (TransactionID txn) const {
|
||||
void LMDBAL::Cursor<K, V>::open (const Transaction& transaction) const {
|
||||
storage->ensureOpened(openCursorMethodName);
|
||||
TransactionID txn = storage->extractTransactionId(transaction, openCursorMethodName);
|
||||
switch (state) {
|
||||
case closed: {
|
||||
int result = mdb_cursor_open(txn, storage->dbi, &cursor);
|
||||
|
@ -141,8 +146,8 @@ void LMDBAL::Cursor<K, V>::open (TransactionID txn) const {
|
|||
*
|
||||
* This function does nothing if the cursor is closed
|
||||
*
|
||||
* \throws LMDBAL::Closed thrown if you try to renew the cursor on a closed database
|
||||
* \throws LMDBAL::Unknown thrown if there was a problem beginning new transaction or if there was a problem renewing the cursor by lmdb
|
||||
* \exception LMDBAL::Closed thrown if you try to renew the cursor on a closed database
|
||||
* \exception LMDBAL::Unknown thrown if there was a problem beginning new transaction or if there was a problem renewing the cursor by lmdb
|
||||
*/
|
||||
template<class K, class V>
|
||||
void LMDBAL::Cursor<K, V>::renew () const {
|
||||
|
@ -183,12 +188,14 @@ void LMDBAL::Cursor<K, V>::renew () const {
|
|||
*
|
||||
* \param[in] txn a transaction you wish this cursor to be bound to
|
||||
*
|
||||
* \throws LMDBAL::Closed thrown if you try to renew the cursor on a closed database
|
||||
* \throws LMDBAL::Unknown thrown if there was a problem renewing the cursor by lmdb
|
||||
* \exception LMDBAL::Closed thrown if you try to renew the cursor on a closed database
|
||||
* \exception LMDBAL::Unknown thrown if there was a problem renewing the cursor by 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::Cursor<K, V>::renew (TransactionID txn) const {
|
||||
void LMDBAL::Cursor<K, V>::renew (const Transaction& transaction) const {
|
||||
storage->ensureOpened(renewCursorMethodName);
|
||||
TransactionID txn = storage->extractTransactionId(transaction, renewCursorMethodName);
|
||||
switch (state) {
|
||||
case openedPrivate: {
|
||||
TransactionID txn = mdb_cursor_txn(cursor);
|
||||
|
@ -255,9 +262,9 @@ bool LMDBAL::Cursor<K, V>::opened () const {
|
|||
* \param[out] key a reference to an object the key of queried element is going to be assigned
|
||||
* \param[out] value a reference to an object the value of queried element is going to be assigned
|
||||
*
|
||||
* \throws LMDBAL::CursorNotReady thrown if you try to call this method on a closed cursor
|
||||
* \throws LMDBAL::NotFound thrown if there are no elements in the storage
|
||||
* \throws LMDBAL::Unknown thrown if there was some unexpected problem with lmdb
|
||||
* \exception LMDBAL::CursorNotReady thrown if you try to call this method on a closed cursor
|
||||
* \exception LMDBAL::NotFound thrown if there are no elements in the storage
|
||||
* \exception LMDBAL::Unknown thrown if there was some unexpected problem with lmdb
|
||||
*/
|
||||
template<class K, class V>
|
||||
void LMDBAL::Cursor<K, V>::first (K& key, V& value) const {
|
||||
|
@ -272,9 +279,9 @@ void LMDBAL::Cursor<K, V>::first (K& key, V& value) const {
|
|||
* \param[out] key a reference to an object the key of queried element is going to be assigned
|
||||
* \param[out] value a reference to an object the value of queried element is going to be assigned
|
||||
*
|
||||
* \throws LMDBAL::CursorNotReady thrown if you try to call this method on a closed cursor
|
||||
* \throws LMDBAL::NotFound thrown if there are no elements in the storage
|
||||
* \throws LMDBAL::Unknown thrown if there was some unexpected problem with lmdb
|
||||
* \exception LMDBAL::CursorNotReady thrown if you try to call this method on a closed cursor
|
||||
* \exception LMDBAL::NotFound thrown if there are no elements in the storage
|
||||
* \exception LMDBAL::Unknown thrown if there was some unexpected problem with lmdb
|
||||
*/
|
||||
template<class K, class V>
|
||||
void LMDBAL::Cursor<K, V>::last (K& key, V& value) const {
|
||||
|
@ -295,9 +302,9 @@ void LMDBAL::Cursor<K, V>::last (K& key, V& value) const {
|
|||
* \param[out] key a reference to an object the key of queried element is going to be assigned
|
||||
* \param[out] value a reference to an object the value of queried element is going to be assigned
|
||||
*
|
||||
* \throws LMDBAL::CursorNotReady thrown if you try to call this method on a closed cursor
|
||||
* \throws LMDBAL::NotFound thrown if the cursor already was on the last element or if there are no elements in the storage
|
||||
* \throws LMDBAL::Unknown thrown if there was some unexpected problem with lmdb
|
||||
* \exception LMDBAL::CursorNotReady thrown if you try to call this method on a closed cursor
|
||||
* \exception LMDBAL::NotFound thrown if the cursor already was on the last element or if there are no elements in the storage
|
||||
* \exception LMDBAL::Unknown thrown if there was some unexpected problem with lmdb
|
||||
*/
|
||||
template<class K, class V>
|
||||
void LMDBAL::Cursor<K, V>::next (K& key, V& value) const {
|
||||
|
@ -318,9 +325,9 @@ void LMDBAL::Cursor<K, V>::next (K& key, V& value) const {
|
|||
* \param[out] key a reference to an object the key of queried element is going to be assigned
|
||||
* \param[out] value a reference to an object the value of queried element is going to be assigned
|
||||
*
|
||||
* \throws LMDBAL::CursorNotReady thrown if you try to call this method on a closed cursor
|
||||
* \throws LMDBAL::NotFound thrown if the cursor already was on the first element or if there are no elements in the storage
|
||||
* \throws LMDBAL::Unknown thrown if there was some unexpected problem with lmdb
|
||||
* \exception LMDBAL::CursorNotReady thrown if you try to call this method on a closed cursor
|
||||
* \exception LMDBAL::NotFound thrown if the cursor already was on the first element or if there are no elements in the storage
|
||||
* \exception LMDBAL::Unknown thrown if there was some unexpected problem with lmdb
|
||||
*/
|
||||
template<class K, class V>
|
||||
void LMDBAL::Cursor<K, V>::prev (K& key, V& value) const {
|
||||
|
@ -337,9 +344,9 @@ void LMDBAL::Cursor<K, V>::prev (K& key, V& value) const {
|
|||
* \param[out] key a reference to an object the key of queried element is going to be assigned
|
||||
* \param[out] value a reference to an object the value of queried element is going to be assigned
|
||||
*
|
||||
* \throws LMDBAL::CursorNotReady thrown if you try to call this method on a closed cursor
|
||||
* \throws LMDBAL::NotFound probably never thrown but there might be still some corner case I don't know about
|
||||
* \throws LMDBAL::Unknown thrown if there was some unexpected problem with lmdb
|
||||
* \exception LMDBAL::CursorNotReady thrown if you try to call this method on a closed cursor
|
||||
* \exception LMDBAL::NotFound probably never thrown but there might be still some corner case I don't know about
|
||||
* \exception LMDBAL::Unknown thrown if there was some unexpected problem with lmdb
|
||||
*/
|
||||
template<class K, class V>
|
||||
void LMDBAL::Cursor<K, V>::current (K& key, V& value) const {
|
||||
|
@ -353,9 +360,9 @@ void LMDBAL::Cursor<K, V>::current (K& key, V& value) const {
|
|||
*
|
||||
* \returns std::pair where first is element key and second is element value
|
||||
*
|
||||
* \throws LMDBAL::CursorNotReady thrown if you try to call this method on a closed cursor
|
||||
* \throws LMDBAL::NotFound thrown if there are no elements in the storage
|
||||
* \throws LMDBAL::Unknown thrown if there was some unexpected problem with lmdb
|
||||
* \exception LMDBAL::CursorNotReady thrown if you try to call this method on a closed cursor
|
||||
* \exception LMDBAL::NotFound thrown if there are no elements in the storage
|
||||
* \exception LMDBAL::Unknown thrown if there was some unexpected problem with lmdb
|
||||
*/
|
||||
template<class K, class V>
|
||||
std::pair<K, V> LMDBAL::Cursor<K, V>::first () const {
|
||||
|
@ -371,9 +378,9 @@ std::pair<K, V> LMDBAL::Cursor<K, V>::first () const {
|
|||
*
|
||||
* \returns std::pair where first is element key and second is element value
|
||||
*
|
||||
* \throws LMDBAL::CursorNotReady thrown if you try to call this method on a closed cursor
|
||||
* \throws LMDBAL::NotFound thrown if there are no elements in the storage
|
||||
* \throws LMDBAL::Unknown thrown if there was some unexpected problem with lmdb
|
||||
* \exception LMDBAL::CursorNotReady thrown if you try to call this method on a closed cursor
|
||||
* \exception LMDBAL::NotFound thrown if there are no elements in the storage
|
||||
* \exception LMDBAL::Unknown thrown if there was some unexpected problem with lmdb
|
||||
*/
|
||||
template<class K, class V>
|
||||
std::pair<K, V> LMDBAL::Cursor<K, V>::last () const {
|
||||
|
@ -395,9 +402,9 @@ std::pair<K, V> LMDBAL::Cursor<K, V>::last () const {
|
|||
*
|
||||
* \returns std::pair where first is element key and second is element value
|
||||
*
|
||||
* \throws LMDBAL::CursorNotReady thrown if you try to call this method on a closed cursor
|
||||
* \throws LMDBAL::NotFound thrown if the cursor already was on the last element or if there are no elements in the storage
|
||||
* \throws LMDBAL::Unknown thrown if there was some unexpected problem with lmdb
|
||||
* \exception LMDBAL::CursorNotReady thrown if you try to call this method on a closed cursor
|
||||
* \exception LMDBAL::NotFound thrown if the cursor already was on the last element or if there are no elements in the storage
|
||||
* \exception LMDBAL::Unknown thrown if there was some unexpected problem with lmdb
|
||||
*/
|
||||
template<class K, class V>
|
||||
std::pair<K, V> LMDBAL::Cursor<K, V>::next () const {
|
||||
|
@ -419,9 +426,9 @@ std::pair<K, V> LMDBAL::Cursor<K, V>::next () const {
|
|||
*
|
||||
* \returns std::pair where first is element key and second is element value
|
||||
*
|
||||
* \throws LMDBAL::CursorNotReady thrown if you try to call this method on a closed cursor
|
||||
* \throws LMDBAL::NotFound thrown if the cursor already was on the first element or if there are no elements in the storage
|
||||
* \throws LMDBAL::Unknown thrown if there was some unexpected problem with lmdb
|
||||
* \exception LMDBAL::CursorNotReady thrown if you try to call this method on a closed cursor
|
||||
* \exception LMDBAL::NotFound thrown if the cursor already was on the first element or if there are no elements in the storage
|
||||
* \exception LMDBAL::Unknown thrown if there was some unexpected problem with lmdb
|
||||
*/
|
||||
template<class K, class V>
|
||||
std::pair<K, V> LMDBAL::Cursor<K, V>::prev () const {
|
||||
|
@ -439,9 +446,9 @@ std::pair<K, V> LMDBAL::Cursor<K, V>::prev () const {
|
|||
*
|
||||
* \returns std::pair where first is element key and second is element value
|
||||
*
|
||||
* \throws LMDBAL::CursorNotReady thrown if you try to call this method on a closed cursor
|
||||
* \throws LMDBAL::NotFound probably never thrown but there might be still some corner case I don't know about
|
||||
* \throws LMDBAL::Unknown thrown if there was no positioning operation before of if there was some unexpected problem with lmdb
|
||||
* \exception LMDBAL::CursorNotReady thrown if you try to call this method on a closed cursor
|
||||
* \exception LMDBAL::NotFound probably never thrown but there might be still some corner case I don't know about
|
||||
* \exception LMDBAL::Unknown thrown if there was no positioning operation before of if there was some unexpected problem with lmdb
|
||||
*/
|
||||
template<class K, class V>
|
||||
std::pair<K, V> LMDBAL::Cursor<K, V>::current () const {
|
||||
|
@ -461,9 +468,9 @@ std::pair<K, V> LMDBAL::Cursor<K, V>::current () const {
|
|||
* \param[in] methodName a name of the method you called it from, just for the exception message if something goes not as expected
|
||||
* \param[in] operationName a name of the opeartion, just for the exception message if something goes not as expected
|
||||
*
|
||||
* \throws LMDBAL::CursorNotReady thrown if you try to call this method on a closed cursor
|
||||
* \throws LMDBAL::NotFound mostly thrown if the query wasn't found
|
||||
* \throws LMDBAL::Unknown mostly thrown if there was some unexpected problem with lmdb
|
||||
* \exception LMDBAL::CursorNotReady thrown if you try to call this method on a closed cursor
|
||||
* \exception LMDBAL::NotFound mostly thrown if the query wasn't found
|
||||
* \exception LMDBAL::Unknown mostly thrown if there was some unexpected problem with lmdb
|
||||
*/
|
||||
template<class K, class V>
|
||||
void LMDBAL::Cursor<K, V>::operateCursorRead(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue