pragma once and minor change in transactions
This commit is contained in:
parent
43d4900809
commit
56d35d4832
29 changed files with 79 additions and 143 deletions
24
src/base.cpp
24
src/base.cpp
|
@ -43,7 +43,7 @@ LMDBAL::Base::Base(const QString& _name, uint16_t _mapSize):
|
|||
size(_mapSize),
|
||||
environment(),
|
||||
storages(),
|
||||
transactions(new Transactions())
|
||||
transactions()
|
||||
{}
|
||||
|
||||
/**
|
||||
|
@ -52,8 +52,6 @@ LMDBAL::Base::Base(const QString& _name, uint16_t _mapSize):
|
|||
LMDBAL::Base::~Base() {
|
||||
close();
|
||||
|
||||
delete transactions;
|
||||
|
||||
for (const std::pair<const std::string, iStorage*>& pair : storages)
|
||||
delete pair.second;
|
||||
}
|
||||
|
@ -68,14 +66,14 @@ LMDBAL::Base::~Base() {
|
|||
*/
|
||||
void LMDBAL::Base::close() {
|
||||
if (opened) {
|
||||
for (const LMDBAL::TransactionID id : *transactions)
|
||||
for (const LMDBAL::TransactionID id : transactions)
|
||||
abortTransaction(id, emptyName);
|
||||
|
||||
for (const std::pair<const std::string, iStorage*>& pair : storages)
|
||||
pair.second->close();
|
||||
|
||||
mdb_env_close(environment);
|
||||
transactions->clear();
|
||||
transactions.clear();
|
||||
opened = false;
|
||||
}
|
||||
}
|
||||
|
@ -301,7 +299,7 @@ LMDBAL::TransactionID LMDBAL::Base::beginReadOnlyTransaction(const std::string&
|
|||
throw Closed("beginReadOnlyTransaction", name, storageName);
|
||||
|
||||
TransactionID txn = beginPrivateReadOnlyTransaction(storageName);
|
||||
transactions->emplace(txn);
|
||||
transactions.emplace(txn);
|
||||
for (const std::pair<const std::string, LMDBAL::iStorage*>& pair : storages)
|
||||
pair.second->transactionStarted(txn, true);
|
||||
|
||||
|
@ -325,7 +323,7 @@ LMDBAL::TransactionID LMDBAL::Base::beginTransaction(const std::string& storageN
|
|||
throw Closed("beginTransaction", name, storageName);
|
||||
|
||||
TransactionID txn = beginPrivateTransaction(storageName);
|
||||
transactions->emplace(txn);
|
||||
transactions.emplace(txn);
|
||||
for (const std::pair<const std::string, LMDBAL::iStorage*>& pair : storages)
|
||||
pair.second->transactionStarted(txn, false);
|
||||
|
||||
|
@ -349,15 +347,15 @@ void LMDBAL::Base::abortTransaction(LMDBAL::TransactionID id, const std::string&
|
|||
if (!opened)
|
||||
throw Closed("abortTransaction", name, storageName);
|
||||
|
||||
Transactions::iterator itr = transactions->find(id);
|
||||
if (itr == transactions->end()) //TODO may be it's a good idea to make an exception class for this
|
||||
Transactions::iterator itr = transactions.find(id);
|
||||
if (itr == transactions.end()) //TODO may be it's a good idea to make an exception class for this
|
||||
throw Unknown(name, "unable to abort transaction: transaction was not found", storageName);
|
||||
|
||||
abortPrivateTransaction(id, storageName);
|
||||
for (const std::pair<const std::string, LMDBAL::iStorage*>& pair : storages)
|
||||
pair.second->transactionAborted(id);
|
||||
|
||||
transactions->erase(itr);
|
||||
transactions.erase(itr);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -376,15 +374,15 @@ void LMDBAL::Base::commitTransaction(LMDBAL::TransactionID id, const std::string
|
|||
if (!opened)
|
||||
throw Closed("abortTransaction", name, storageName);
|
||||
|
||||
Transactions::iterator itr = transactions->find(id);
|
||||
if (itr == transactions->end()) //TODO may be it's a good idea to make an exception class for this
|
||||
Transactions::iterator itr = transactions.find(id);
|
||||
if (itr == transactions.end()) //TODO may be it's a good idea to make an exception class for this
|
||||
throw Unknown(name, "unable to commit transaction: transaction was not found", storageName);
|
||||
|
||||
commitPrivateTransaction(id, storageName);
|
||||
for (const std::pair<const std::string, LMDBAL::iStorage*>& pair : storages)
|
||||
pair.second->transactionCommited(id);
|
||||
|
||||
transactions->erase(itr);
|
||||
transactions.erase(itr);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue