forked from blue/lmdbal
Some refactor
This commit is contained in:
parent
bfb1d007ad
commit
3ae1fd15c0
5 changed files with 50 additions and 40 deletions
|
@ -71,7 +71,7 @@ LMDBAL::CursorCommon::CursorCommon (CursorCommon&& other):
|
|||
other.dropped();
|
||||
|
||||
if (state == openedPublic)
|
||||
storage->attachCursorToTransaction(id, handle, this);
|
||||
attachToTransaction();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -99,7 +99,7 @@ LMDBAL::CursorCommon& LMDBAL::CursorCommon::operator = (CursorCommon&& other) {
|
|||
other.reset();
|
||||
|
||||
if (state == openedPublic)
|
||||
storage->attachCursorToTransaction(id, handle, this);
|
||||
attachToTransaction();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ void LMDBAL::CursorCommon::terminated () {
|
|||
void LMDBAL::CursorCommon::close () {
|
||||
switch (state) {
|
||||
case openedPublic:
|
||||
storage->disconnectCursorFromTransaction(id, handle);
|
||||
disconnectFromTransaction();
|
||||
storage->_mdbCursorClose(handle);
|
||||
|
||||
state = closed;
|
||||
|
@ -231,7 +231,7 @@ void LMDBAL::CursorCommon::open (const Transaction& transaction) {
|
|||
if (result != MDB_SUCCESS)
|
||||
storage->throwUnknown(result);
|
||||
|
||||
storage->attachCursorToTransaction(id, handle, this);
|
||||
transaction.cursors[id] = this;
|
||||
state = openedPublic;
|
||||
} break;
|
||||
default:
|
||||
|
@ -267,7 +267,7 @@ void LMDBAL::CursorCommon::renew () {
|
|||
storage->openCursorTransaction(&handle, true);
|
||||
break;
|
||||
case openedPublic:
|
||||
storage->disconnectCursorFromTransaction(id, handle);
|
||||
disconnectFromTransaction();
|
||||
storage->openCursorTransaction(&handle, true);
|
||||
state = openedPrivate;
|
||||
break;
|
||||
|
@ -309,16 +309,16 @@ void LMDBAL::CursorCommon::renew (const Transaction& transaction) {
|
|||
if (result != MDB_SUCCESS)
|
||||
storage->throwUnknown(result);
|
||||
|
||||
storage->attachCursorToTransaction(id, handle, this);
|
||||
transaction.cursors[id] = this;
|
||||
state = openedPublic;
|
||||
} break;
|
||||
case openedPublic: {
|
||||
storage->disconnectCursorFromTransaction(id, handle);
|
||||
disconnectFromTransaction();
|
||||
int result = storage->_mdbCursorRenew(txn, handle);
|
||||
if (result != MDB_SUCCESS)
|
||||
storage->throwUnknown(result);
|
||||
|
||||
storage->attachCursorToTransaction(id, handle, this);
|
||||
transaction.cursors[id] = this;
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
|
@ -340,3 +340,27 @@ bool LMDBAL::CursorCommon::empty () const {
|
|||
bool LMDBAL::CursorCommon::opened () const {
|
||||
return state != closed;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Links cursor to the transaction it has been opened with
|
||||
*
|
||||
* Cursor must be opened by a public transaction
|
||||
*
|
||||
* \exception std::out_of_range thrown if LMDBAL::Transaction pointer wasn't found in the LMDBAL::Base
|
||||
*/
|
||||
void LMDBAL::CursorCommon::attachToTransaction () {
|
||||
Transaction* txn = storage->getTransactionForCursor(handle);
|
||||
txn->cursors[id] = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Disconnects cursor from the transaction it has been opened with
|
||||
*
|
||||
* Cursor must be still opened by a public transaction
|
||||
*
|
||||
* \exception std::out_of_range thrown if LMDBAL::Transaction pointer wasn't found in the LMDBAL::Base
|
||||
*/
|
||||
void LMDBAL::CursorCommon::disconnectFromTransaction () {
|
||||
Transaction* txn = storage->getTransactionForCursor(handle);
|
||||
txn->cursors.erase(id);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue