Joedb 9.1.4
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Writable_Database.h
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/doc/source/tutorial/build/joedbc
7// Version: 9.1.4
8// joedbc compilation time: Apr 15 2025 14:46:29
9// Generation of this file: 2025-04-15 12:46:31 GMT
10//
11/////////////////////////////////////////////////////////////////////////////
12#ifndef joedb_db_encoded_file_Writable_Database_declared
13#define joedb_db_encoded_file_Writable_Database_declared
14
15#include "Database.h"
16#include "joedb/Span.h"
17
19{
20 namespace detail
21 {
22 class Client_Data;
23 }
24
25 class Client;
26 class Multiplexer;
27
28 /// A writable @ref Database constructed from a writable @ref joedb::Buffered_File
30 {
31 friend class detail::Client_Data;
32 friend class Client;
33 friend class Multiplexer;
34
35 private:
37 bool ready_to_write;
38
39 void play_journal();
40 void auto_upgrade();
41 void check_single_row();
42
43 void initialize()
44 {
45 play_journal();
47 auto_upgrade();
48 check_single_row();
50 }
51
53 (
55 bool perform_initialization,
57 joedb::Commit_Level commit_level
58 );
59
60 public:
62 (
66 );
67
68 const joedb::Readonly_Journal &get_journal() const {return journal;}
69
70 std::string read_blob_data(joedb::Blob blob) const
71 {
72 return journal.get_file().read_blob_data(blob);
73 }
74
75 joedb::Blob write_blob_data(const std::string &data) final
76 {
77 return journal.write_blob_data(data);
78 }
79
80 int64_t ahead_of_checkpoint() const
81 {
82 return journal.ahead_of_checkpoint();
83 }
84
89
94
99
101 {
102 journal.default_checkpoint();
103 }
104
105 void checkpoint(joedb::Commit_Level commit_level) final
106 {
107 journal.checkpoint(commit_level);
108 }
109
110 void write_comment(const std::string &comment);
111 void write_timestamp();
112 void write_timestamp(int64_t timestamp);
113 void write_valid_data();
114 void flush() override {journal.flush();}
115
116 void clear_buffer_table();
117
119 {
120 id_of_buffer result(Record_Id(storage_of_buffer.freedom_keeper.get_free_record() - 1));
121 storage_of_buffer.resize(storage_of_buffer.freedom_keeper.size());
123
124 journal.insert_into(Table_Id(1), result.get_record_id());
125 return result;
126 }
127
129 {
130 id_of_buffer result(Record_Id(storage_of_buffer.size() + 1));
131 storage_of_buffer.resize(storage_of_buffer.size() + size);
133 journal.insert_vector(Table_Id(1), result.get_record_id(), size);
134 return result;
135 }
136
138 (
139 joedb::Blob field_value_of_data,
140 int64_t field_value_of_size,
141 int64_t field_value_of_offset
142 )
143 {
144 auto result = new_buffer();
145 set_data(result, field_value_of_data);
146 set_size(result, field_value_of_size);
147 set_offset(result, field_value_of_offset);
148 return result;
149 }
150
152 {
154 journal.delete_from(Table_Id(1), record.get_record_id());
155 }
156
158 {
159 for (size_t i = size; i > 0;)
160 delete_buffer(v[--i]);
161 }
162
163 void set_data(id_of_buffer record, joedb::Blob field_value_of_data)
164 {
165 internal_update_buffer__data(record.get_record_id(), field_value_of_data);
166 journal.update_blob(Table_Id(1), record.get_record_id(), Field_Id(1), field_value_of_data);
167 }
168
169 template<typename F> void update_vector_of_data(id_of_buffer record, size_t size, F f)
170 {
171 std::exception_ptr exception;
172 joedb::Span<joedb::Blob> span(&storage_of_buffer.field_value_of_data[record.get_id() - 1], size);
173 try {f(span);}
174 catch (...) {exception = std::current_exception();}
176 journal.update_vector_blob(Table_Id(1), record.get_record_id(), Field_Id(1), size, (span.begin()));
177 if (exception)
178 std::rethrow_exception(exception);
179 }
180
181 void set_size(id_of_buffer record, int64_t field_value_of_size)
182 {
183 internal_update_buffer__size(record.get_record_id(), field_value_of_size);
184 journal.update_int64(Table_Id(1), record.get_record_id(), Field_Id(2), field_value_of_size);
185 }
186
187 template<typename F> void update_vector_of_size(id_of_buffer record, size_t size, F f)
188 {
189 std::exception_ptr exception;
190 joedb::Span<int64_t> span(&storage_of_buffer.field_value_of_size[record.get_id() - 1], size);
191 try {f(span);}
192 catch (...) {exception = std::current_exception();}
194 journal.update_vector_int64(Table_Id(1), record.get_record_id(), Field_Id(2), size, (span.begin()));
195 if (exception)
196 std::rethrow_exception(exception);
197 }
198
199 void set_offset(id_of_buffer record, int64_t field_value_of_offset)
200 {
201 internal_update_buffer__offset(record.get_record_id(), field_value_of_offset);
202 journal.update_int64(Table_Id(1), record.get_record_id(), Field_Id(3), field_value_of_offset);
203 }
204
205 template<typename F> void update_vector_of_offset(id_of_buffer record, size_t size, F f)
206 {
207 std::exception_ptr exception;
208 joedb::Span<int64_t> span(&storage_of_buffer.field_value_of_offset[record.get_id() - 1], size);
209 try {f(span);}
210 catch (...) {exception = std::current_exception();}
212 journal.update_vector_int64(Table_Id(1), record.get_record_id(), Field_Id(3), size, (span.begin()));
213 if (exception)
214 std::rethrow_exception(exception);
215 }
216
217
218 };}
219
220#endif
virtual std::string read_blob_data(Blob blob) const
const Buffered_File & get_file() const
T * begin()
Definition Span.h:40
Blob write_blob_data(const std::string &data) final
void insert_vector(Table_Id table_id, Record_Id record_id, size_t size) final
int64_t ahead_of_checkpoint() const noexcept
void delete_from(Table_Id table_id, Record_Id record_id) final
void insert_into(Table_Id table_id, Record_Id record_id) final
void checkpoint(Commit_Level commit_level) final
void default_checkpoint()
Definition Writable.cpp:32
Handle concurrent access to a joedb::Buffered_File using a joedb::Connection.
Definition Client.h:45
Store all the tables of the database.
Definition Database.h:75
void internal_delete_buffer(Record_Id record_id)
Definition Database.h:101
void internal_update_buffer__size(Record_Id record_id, int64_t field_value_of_size)
Definition Database.h:145
void internal_update_vector_buffer__data(Record_Id record_id, size_t size, const joedb::Blob *value)
Definition Database.h:131
detail::data_of_buffer storage_of_buffer
Definition Database.h:98
void internal_insert_buffer(Record_Id record_id)
Definition Database.h:110
void timestamp(int64_t timestamp) override
Definition Database.h:376
void internal_update_buffer__offset(Record_Id record_id, int64_t field_value_of_offset)
Definition Database.h:169
void internal_update_buffer__data(Record_Id record_id, joedb::Blob field_value_of_data)
Definition Database.h:121
void internal_update_vector_buffer__offset(Record_Id record_id, size_t size, const int64_t *value)
Definition Database.h:179
void comment(const std::string &comment) override
Definition Database.h:375
void internal_vector_insert_buffer(Record_Id record_id, size_t size)
Definition Database.h:115
void internal_update_vector_buffer__size(Record_Id record_id, size_t size, const int64_t *value)
Definition Database.h:155
Write simultaneously to the database and the file (ignore schema changes)
Definition Multiplexer.h:40
A writable Database constructed from a writable joedb::Buffered_File.
void set_data(id_of_buffer record, joedb::Blob field_value_of_data)
void update_vector_of_size(id_of_buffer record, size_t size, F f)
void delete_vector_of_buffer(id_of_buffer v, size_t size)
std::string read_blob_data(joedb::Blob blob) const
void set_size(id_of_buffer record, int64_t field_value_of_size)
void update_vector_of_data(id_of_buffer record, size_t size, F f)
void set_offset(id_of_buffer record, int64_t field_value_of_offset)
void write_comment(const std::string &comment)
void checkpoint(joedb::Commit_Level commit_level) final
const joedb::Readonly_Journal & get_journal() const
joedb::Blob write_blob_data(const std::string &data) final
id_of_buffer new_buffer(joedb::Blob field_value_of_data, int64_t field_value_of_size, int64_t field_value_of_offset)
void update_vector_of_offset(id_of_buffer record, size_t size, F f)
Strongly-typed wrapper around an integer representing a row of the buffer table.
Definition ids.h:25
constexpr size_t get_id() const
Definition ids.h:35
constexpr Record_Id get_record_id() const
Definition ids.h:36
Automatically generated by joedbc.
Definition Client.h:19
Commit_Level
Definition Writable.h:13