LMDBAL 0.6.0
LMDB (Lightning Memory-Mapped Database Manager) Abstraction Layer
Loading...
Searching...
No Matches
transaction.h
1/*
2 * LMDB Abstraction Layer.
3 * Copyright (C) 2023 Yury Gubich <blue@macaw.me>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#pragma once
20
21#include "base.h"
22
23namespace LMDBAL {
24class StorageCommon;
25class CursorCommon;
26
28 friend class Base;
29 friend class StorageCommon;
30 friend class CursorCommon;
31public:
32 explicit Transaction();
33 explicit Transaction(Transaction&& other);
34 Transaction(const Transaction& other) = delete;
35 Transaction& operator = (const Transaction& other) = delete;
36 Transaction& operator = (Transaction&& other);
37 virtual ~Transaction();
38
39 void terminate();
40 bool isActive() const;
41
42protected:
43 Transaction(TransactionID txn, const Base* parent);
44 void reset();
45 void closeCursors();
46
47protected:
48 TransactionID txn;
49 bool active;
50 const Base* parent;
51 mutable std::map<uint32_t, CursorCommon*> cursors;
52};
53
55 friend class Base;
56public:
57 explicit WriteTransaction();
58 explicit WriteTransaction(WriteTransaction&& other);
59 WriteTransaction(const WriteTransaction& other) = delete;
60 WriteTransaction& operator = (const WriteTransaction& other) = delete;
61 WriteTransaction& operator = (WriteTransaction&& other);
62
63 void commit();
64 void abort();
65
66protected:
67 WriteTransaction(TransactionID txn, Base* parent);
68};
69
70}
An object to manage cursor internals and state.
Definition cursorcommon.h:31
Definition storagecommon.h:33
bool active
Transaction state.
Definition transaction.h:49
TransactionID txn
Transaction inner handler.
Definition transaction.h:48
virtual ~Transaction()
Destroys transaction.
Definition transaction.cpp:80
void reset()
Resets inner transaction properties to inactive state.
Definition transaction.cpp:125
void closeCursors()
Closes attached curors;.
Definition transaction.cpp:135
std::map< uint32_t, CursorCommon * > cursors
a collection of cursors curently opened under this transaction
Definition transaction.h:51
void terminate()
Terminates transaction if it was active.
Definition transaction.cpp:112
Transaction()
Constructs inactive transaction.
Definition transaction.cpp:42
const Base * parent
Pointer to the database this transaction belongs to.
Definition transaction.h:50
bool isActive() const
Returns transaction states.
Definition transaction.cpp:145
WriteTransaction()
Constructs inactive write transaction.
Definition transaction.cpp:182
void commit()
Commits transaction submitting all changes.
Definition transaction.cpp:213
void abort()
Aborts transaction cancelling all changes.
Definition transaction.cpp:204