Joedb 10.0.1
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Writable_Database_Client.h
Go to the documentation of this file.
1#ifndef joedb_Writable_Database_Client_declared
2#define joedb_Writable_Database_Client_declared
3
6#include "joedb/Multiplexer.h"
7
8namespace joedb
9{
10 namespace detail
11 {
12 class Writable_Database_Client_Data
13 {
14 protected:
15 Writable_Journal data_journal;
16 Database database;
17 Multiplexer multiplexer;
18
19 public:
20 Writable_Database_Client_Data
21 (
22 Buffered_File &file,
23 Record_Id max_record_id,
24 Recovery recovery
25 ):
26 data_journal(Journal_Construction_Lock(file, recovery)),
27 database(max_record_id),
28 multiplexer{database, data_journal}
29 {
30 }
31 };
32 }
33
34 /// @ingroup concurrency
36 protected detail::Writable_Database_Client_Data,
37 public Writable_Client
38 {
40
41 protected:
42 void read_journal() override
43 {
44 data_journal.play_until_checkpoint(database);
45 }
46
47 public:
49 (
50 Buffered_File &file,
52 Content_Check content_check = Content_Check::fast,
53 Record_Id max_record_id = Record_Id::null,
54 Recovery recovery = Recovery::none
55 ):
56 Writable_Database_Client_Data(file, max_record_id, recovery),
57 Writable_Client(data_journal, connection, content_check)
58 {
60 }
61
62 const Database &get_database() const
63 {
64 return database;
65 }
66
67 template<typename F> auto transaction(F transaction)
68 {
70 {
71 return transaction(database, multiplexer);
72 });
73 }
74 };
75
76 /// @ingroup concurrency
78 {
79 public:
84
85 const Readable &get_readable() const
86 {
87 return static_cast<Writable_Database_Client &>(client).database;
88 }
89
91 {
93 return static_cast<Writable_Database_Client &>(client).multiplexer;
94 }
95 };
96}
97
98#endif
Lock object that allows writing to a database managed by a joedb::Client.
Writable_Client & client
Connection & connection
Definition Client.h:16
static const Record_Id null
Definition index_types.h:44
Writable specialization of Client.
auto transaction(F transaction)
Writable_Database_Client_Lock(Writable_Database_Client &client)
Writable_Database_Client(Buffered_File &file, Connection &connection, Content_Check content_check=Content_Check::fast, Record_Id max_record_id=Record_Id::null, Recovery recovery=Recovery::none)
Superclass with all joedb journal event listeners as virtual functions.
Definition Writable.h:17
Content_Check
Definition Connection.h:19
#define JOEDB_DEBUG_ASSERT(x)
assertion tested in debug mode
Definition assert.h:19
@ none
default: fail if file size > checkpoint
Definition Blob.h:7