Joedb 10.5.0
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Writable_Database.cpp
Go to the documentation of this file.
1/////////////////////////////////////////////////////////////////////////////
2//
3// This code was automatically generated by the joedb compiler
4// https://www.joedb.org/
5//
6// Path to compiler: /home/rcoulom/repos/joedb/compcmake/gcc_debug/joedbc
7// Version: 10.5.0
8// joedbc compilation time: Oct 25 2026 16:06:59
9// Generation of this file: 2026-10-25 19:48:05 GMT
10//
11/////////////////////////////////////////////////////////////////////////////
12#include "Writable_Database.h"
14
15#include <ctime>
16#include <limits>
17
18namespace tutorial
19{
20 ////////////////////////////////////////////////////////////////////////////
22 ////////////////////////////////////////////////////////////////////////////
23 {
24 journal.comment(comment);
25 }
26
27 ////////////////////////////////////////////////////////////////////////////
29 ////////////////////////////////////////////////////////////////////////////
30 {
31 journal.timestamp(std::time(nullptr));
32 }
33
34 ////////////////////////////////////////////////////////////////////////////
36 ////////////////////////////////////////////////////////////////////////////
37 {
38 journal.timestamp(timestamp);
39 }
40
41 ////////////////////////////////////////////////////////////////////////////
43 ////////////////////////////////////////////////////////////////////////////
44 {
45 journal.valid_data();
46 }
47
48 ////////////////////////////////////////////////////////////////////////////
49 void Writable_Database::play_journal()
50 ////////////////////////////////////////////////////////////////////////////
51 {
52 max_record_id = journal.get_checkpoint();
53 ready_to_write = false;
54 journal.play_until_checkpoint(*this);
55 ready_to_write = true;
56 max_record_id = 0;
57 }
58
59 ////////////////////////////////////////////////////////////////////////////
60 void Writable_Database::auto_upgrade()
61 ////////////////////////////////////////////////////////////////////////////
62 {
63 const size_t file_schema_size = size_t(schema_file.get_size());
64
65 if (file_schema_size < detail::schema_string_size)
66 {
67 journal.comment("Automatic schema upgrade");
68
69 joedb::Readonly_Memory_File schema_file(detail::schema_string, detail::schema_string_size);
71
72 schema_journal.skip_directly_to(int64_t(file_schema_size));
73 schema_journal.raw_play_until(journal, detail::schema_string_size);
74
75 schema_journal.skip_directly_to(int64_t(file_schema_size));
76 upgrading_schema = true;
77 schema_journal.raw_play_until(*this, detail::schema_string_size);
78 upgrading_schema = false;
79
80 journal.valid_data();
81 journal.soft_checkpoint();
82 }
83 }
84
85 ////////////////////////////////////////////////////////////////////////////
86 void Writable_Database::initialize()
87 ////////////////////////////////////////////////////////////////////////////
88 {
89 play_journal();
91 auto_upgrade();
92 check_single_row();
93 }
94
95 ////////////////////////////////////////////////////////////////////////////
96 Writable_Database::Writable_Database
97 ////////////////////////////////////////////////////////////////////////////
98 (
99 joedb::Abstract_File &file,
100 joedb::Recovery recovery,
101 bool perform_initialization
102 ):
103 journal(joedb::Journal_Construction_Lock(file, recovery))
104 {
105 journal.rewind();
106
107 if (perform_initialization)
108 initialize();
109 }
110
111 ////////////////////////////////////////////////////////////////////////////
112 Writable_Database::Writable_Database(joedb::Abstract_File &file):
113 ////////////////////////////////////////////////////////////////////////////
114 Writable_Database(file, joedb::Recovery::none, true)
115 {
116 }
117
118 ////////////////////////////////////////////////////////////////////////////
119 Writable_Database::Writable_Database
120 ////////////////////////////////////////////////////////////////////////////
121 (
123 joedb::Recovery recovery
124 ):
125 Writable_Database(file, recovery, true)
126 {
127 }
128
129 ////////////////////////////////////////////////////////////////////////////
130 void Writable_Database::check_single_row()
131 ////////////////////////////////////////////////////////////////////////////
132 {
133 }
134
135 /////////////////////////////////////////////////////////////////////////////
137 /////////////////////////////////////////////////////////////////////////////
138 {
139 while (!get_city_table().is_empty())
140 delete_city(get_city_table().last());
141 }
142
143 /////////////////////////////////////////////////////////////////////////////
145 /////////////////////////////////////////////////////////////////////////////
146 {
147 while (!get_person_table().is_empty())
149 }
150}
int64_t get_size() const override
Get the size of the file, or -1 if it is unknown.
Definition Memory_File.h:27
void raw_play_until(Writable &writable, int64_t end)
void play_until_checkpoint(Writable &writable)
int64_t get_checkpoint() const
void skip_directly_to(int64_t position)
void comment(const std::string &comment) override
void timestamp(int64_t timestamp) override
void comment(const std::string &comment) override
joedb::Writable_Journal schema_journal
container_of_person get_person_table() const
Definition Database.h:554
container_of_city get_city_table() const
Definition Database.h:496
void write_comment(const std::string &comment)
void delete_city(id_of_city record)
void delete_person(id_of_person record)
Automatically generated by joedbc.
Definition Client.h:19