43static uint32_t idCounter = 0;
50template<
class K,
class V>
57 storage->cursors[id] =
this;
65template<
class K,
class V>
76template<
class K,
class V>
78 storage(other.storage),
85 storage->cursors[
id] =
this;
96template<
class K,
class V>
101 storage->cursors.erase(
id);
103 storage = other.storage;
104 cursor = other.cursor;
110 other.state = closed;
112 storage->cursors[id] =
this;
123template<
class K,
class V>
128 storage->cursors.erase(
id);
137template<
class K,
class V>
142 storage->cursors.erase(
id);
153template<
class K,
class V>
165template<
class K,
class V>
177template<
class K,
class V>
185template<
class K,
class V>
203template<
class K,
class V>
208 storage->ensureOpened(openCursorMethodName);
211 TransactionID txn = storage->beginReadOnlyTransaction();
212 int result = storage->_mdbCursorOpen(txn, &cursor);
213 if (result != MDB_SUCCESS)
214 storage->throwUnknown(result, txn);
216 storage->transactionStarted(txn,
true);
217 state = openedPrivate;
240template<
class K,
class V>
245 storage->ensureOpened(openCursorMethodName);
246 TransactionID txn = storage->extractTransactionId(transaction, openCursorMethodName);
249 int result = storage->_mdbCursorOpen(txn, &cursor);
250 if (result != MDB_SUCCESS)
251 storage->throwUnknown(result);
253 state = openedPublic;
277template<
class K,
class V>
282 storage->ensureOpened(renewCursorMethodName);
284 case openedPrivate: {
285 TransactionID txn = storage->_mdbCursorTxn(cursor);
286 storage->abortTransaction(txn);
287 storage->transactionAborted(txn);
291 TransactionID txn = storage->beginReadOnlyTransaction();
292 int result = storage->_mdbCursorRenew(txn, cursor);
293 if (result != MDB_SUCCESS)
294 storage->throwUnknown(result, txn);
296 storage->transactionStarted(txn,
true);
297 state = openedPrivate;
324template<
class K,
class V>
329 storage->ensureOpened(renewCursorMethodName);
330 TransactionID txn = storage->extractTransactionId(transaction, renewCursorMethodName);
332 case openedPrivate: {
333 TransactionID txn = storage->_mdbCursorTxn(cursor);
334 storage->abortTransaction(txn);
335 storage->transactionAborted(txn);
339 int result = storage->_mdbCursorRenew(txn, cursor);
340 if (result != MDB_SUCCESS)
341 storage->throwUnknown(result);
343 state = openedPublic;
360template<
class K,
class V>
364 storage->_mdbCursorClose(cursor);
368 case openedPrivate: {
369 TransactionID txn = storage->_mdbCursorTxn(cursor);
370 storage->_mdbCursorClose(cursor);
371 storage->abortTransaction(txn);
372 storage->transactionAborted(txn);
384template<
class K,
class V>
386 return state != closed;
401template<
class K,
class V>
403 operateCursorRead(key, value, MDB_FIRST, firstMethodName, firstOperationName);
418template<
class K,
class V>
420 operateCursorRead(key, value, MDB_LAST, lastMethodName, lastOperationName);
441template<
class K,
class V>
443 operateCursorRead(key, value, MDB_NEXT, nextMethodName, nextOperationName);
464template<
class K,
class V>
466 operateCursorRead(key, value, MDB_PREV, prevMethodName, prevOperationName);
483template<
class K,
class V>
485 operateCursorRead(key, value, MDB_GET_CURRENT, currentMethodName, currentOperationName);
499template<
class K,
class V>
501 std::pair<K, V> result;
502 operateCursorRead(result.first, result.second, MDB_FIRST, firstMethodName, firstOperationName);
517template<
class K,
class V>
519 std::pair<K, V> result;
520 operateCursorRead(result.first, result.second, MDB_LAST, lastMethodName, lastOperationName);
541template<
class K,
class V>
543 std::pair<K, V> result;
544 operateCursorRead(result.first, result.second, MDB_NEXT, nextMethodName, nextOperationName);
565template<
class K,
class V>
567 std::pair<K, V> result;
568 operateCursorRead(result.first, result.second, MDB_PREV, prevMethodName, prevOperationName);
585template<
class K,
class V>
587 std::pair<K, V> result;
588 operateCursorRead(result.first, result.second, MDB_GET_CURRENT, currentMethodName, currentOperationName);
604template<
class K,
class V>
607 storage->throwCursorNotReady(setMethodName);
609 MDB_val mdbKey = storage->keySerializer.setData(key);
610 int result = storage->_mdbCursorSet(cursor, mdbKey);
611 if (result == MDB_SUCCESS)
613 else if (result == MDB_NOTFOUND)
616 storage->throwUnknown(result);
635template<
class K,
class V>
639 MDB_cursor_op operation,
640 const std::string& methodName,
641 const std::string& operationName
644 storage->throwCursorNotReady(methodName);
646 MDB_val mdbKey, mdbValue;
647 int result = storage->_mdbCursorGet(cursor, mdbKey, mdbValue, operation);
648 if (result != MDB_SUCCESS)
649 storage->throwNotFoundOrUnknown(result, operationName);
651 storage->keySerializer.deserialize(mdbKey, key);
652 storage->valueSerializer.deserialize(mdbValue, value);
654 if (state == openedPrivate)
655 storage->discoveredRecord(key, value);
657 storage->discoveredRecord(key, value, storage->_mdbCursorTxn(cursor));
Thrown if an empty cursor was somehow operated.
Definition exceptions.h:102
An object to iterate storages.
Definition cursor.h:31
std::pair< K, V > first()
Queries the first element in the storage.
Definition cursor.hpp:500
void drop()
Turns cursor into an empty one, releasing resources.
Definition cursor.hpp:138
bool empty() const
Returns true if the cursor is empty.
Definition cursor.hpp:178
void renew()
Renews a cursor.
Definition cursor.hpp:278
~Cursor()
Destroys a cursor.
Definition cursor.hpp:124
void close()
Termiates a sequence of operations with the cursor.
Definition cursor.hpp:361
bool opened() const
Tells if the cursor is open.
Definition cursor.hpp:385
void open()
Opens the cursor for operations.
Definition cursor.hpp:204
std::pair< K, V > prev()
Queries the previous element from the storage.
Definition cursor.hpp:566
std::pair< K, V > last()
Queries the last element in the storage.
Definition cursor.hpp:518
std::pair< K, V > current() const
Returns current cursor element from the storage.
Definition cursor.hpp:586
bool set(const K &target)
Sets cursors to the defined position.
Definition cursor.hpp:605
Cursor()
Creates an empty cursor.
Definition cursor.hpp:66
std::pair< K, V > next()
Queries the next element from the storage.
Definition cursor.hpp:542
This is a basic key value storage.
Definition storage.h:134
Public read only transaction.
Definition transaction.h:26