72 lines
1.4 KiB
C++
72 lines
1.4 KiB
C++
#include "transaction.h"
|
|
|
|
LMDBAL::Transaction::Transaction():
|
|
txn(nullptr),
|
|
active(false),
|
|
parent(nullptr)
|
|
{}
|
|
|
|
LMDBAL::Transaction::Transaction(TransactionID txn, const Base* parent) :
|
|
txn(txn),
|
|
active(true),
|
|
parent(parent)
|
|
{}
|
|
|
|
LMDBAL::Transaction::Transaction(Transaction&& other):
|
|
txn(other.txn),
|
|
active(other.active),
|
|
parent(other.parent)
|
|
{
|
|
other.active = false;
|
|
}
|
|
|
|
LMDBAL::Transaction::~Transaction() {
|
|
terminate();
|
|
}
|
|
|
|
LMDBAL::Transaction& LMDBAL::Transaction::operator=(Transaction&& other) {
|
|
terminate();
|
|
|
|
txn = other.txn;
|
|
active = other.active;
|
|
parent = other.parent;
|
|
|
|
other.active = false;
|
|
|
|
return *this;
|
|
}
|
|
|
|
void LMDBAL::Transaction::terminate() {
|
|
if (active) {
|
|
parent->abortTransaction(txn);
|
|
active = false;
|
|
}
|
|
}
|
|
|
|
bool LMDBAL::Transaction::isActive() const {
|
|
return active; //todo may be it's better if I query it from DB?
|
|
}
|
|
|
|
LMDBAL::WriteTransaction::WriteTransaction(TransactionID txn, Base* parent):
|
|
Transaction(txn, parent)
|
|
{}
|
|
|
|
LMDBAL::WriteTransaction::WriteTransaction():
|
|
Transaction()
|
|
{}
|
|
|
|
LMDBAL::WriteTransaction::WriteTransaction(WriteTransaction&& other):
|
|
Transaction(std::move(other))
|
|
{}
|
|
|
|
void LMDBAL::WriteTransaction::abort() {
|
|
terminate();
|
|
}
|
|
|
|
void LMDBAL::WriteTransaction::commit() {
|
|
if (active) {
|
|
const_cast<Base*>(parent)->commitTransaction(txn);
|
|
active = false;
|
|
}
|
|
}
|