Joedb 9.4.0
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/compcmake/gcc_debug/joedbc
7// Version: 9.4.0
8// joedbc compilation time: May 2 2025 11:25:14
9// Generation of this file: 2025-05-02 09:25:19 GMT
10//
11/////////////////////////////////////////////////////////////////////////////
12#ifndef joedb_db_multi_server_Writable_Database_declared
13#define joedb_db_multi_server_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();
49 }
50
52 (
54 bool perform_initialization
55 );
56
57 public:
59
60 const joedb::Readonly_Journal &get_journal() const {return journal;}
61
62 std::string read_blob(joedb::Blob blob) const
63 {
64 return journal.get_file().read_blob(blob);
65 }
66
67 joedb::Blob write_blob(const std::string &data) final
68 {
69 return journal.write_blob(data);
70 }
71
72 int64_t ahead_of_checkpoint() const
73 {
74 return journal.ahead_of_checkpoint();
75 }
76
78 {
79 journal.soft_checkpoint();
80 }
81
83 {
84 journal.hard_checkpoint();
85 }
86
87 void write_comment(const std::string &comment);
88 void write_timestamp();
89 void write_timestamp(int64_t timestamp);
90 void write_valid_data();
91 void flush() override {journal.flush();}
92
93 void clear_server_table();
94
96 {
97 id_of_server result(Record_Id(storage_of_server.freedom_keeper.get_free_record() - 1));
98 storage_of_server.resize(storage_of_server.freedom_keeper.size());
100
101 journal.insert_into(Table_Id(1), result.get_record_id());
102 return result;
103 }
104
106 {
107 id_of_server result(Record_Id(storage_of_server.size() + 1));
108 storage_of_server.resize(storage_of_server.size() + size);
110 journal.insert_vector(Table_Id(1), result.get_record_id(), size);
111 return result;
112 }
113
115 (
116 const std::string& field_value_of_file_name,
117 int32_t field_value_of_port,
118 int32_t field_value_of_timeout
119 )
120 {
121 auto result = new_server();
122 set_file_name(result, field_value_of_file_name);
123 set_port(result, field_value_of_port);
124 set_timeout(result, field_value_of_timeout);
125 return result;
126 }
127
129 {
131 journal.delete_from(Table_Id(1), record.get_record_id());
132 }
133
135 {
136 for (size_t i = size; i > 0;)
137 internal_delete_server(v[--i].get_record_id());
138 journal.delete_vector(Table_Id(1), v.get_record_id(), size);
139 }
140
141 void set_file_name(id_of_server record, const std::string& field_value_of_file_name)
142 {
143 internal_update_server__file_name(record.get_record_id(), field_value_of_file_name);
144 journal.update_string(Table_Id(1), record.get_record_id(), Field_Id(1), field_value_of_file_name);
145 }
146
147 template<typename F> void update_vector_of_file_name(id_of_server record, size_t size, F f)
148 {
149 std::exception_ptr exception;
150 joedb::Span<std::string> span(&storage_of_server.field_value_of_file_name[record.get_id() - 1], size);
151 try {f(span);}
152 catch (...) {exception = std::current_exception();}
154 journal.update_vector_string(Table_Id(1), record.get_record_id(), Field_Id(1), size, (span.begin()));
155 if (exception)
156 std::rethrow_exception(exception);
157 }
158
159 void set_port(id_of_server record, int32_t field_value_of_port)
160 {
161 internal_update_server__port(record.get_record_id(), field_value_of_port);
162 journal.update_int32(Table_Id(1), record.get_record_id(), Field_Id(2), field_value_of_port);
163 }
164
165 template<typename F> void update_vector_of_port(id_of_server record, size_t size, F f)
166 {
167 std::exception_ptr exception;
168 joedb::Span<int32_t> span(&storage_of_server.field_value_of_port[record.get_id() - 1], size);
169 try {f(span);}
170 catch (...) {exception = std::current_exception();}
172 journal.update_vector_int32(Table_Id(1), record.get_record_id(), Field_Id(2), size, (span.begin()));
173 if (exception)
174 std::rethrow_exception(exception);
175 }
176
177 void set_timeout(id_of_server record, int32_t field_value_of_timeout)
178 {
179 internal_update_server__timeout(record.get_record_id(), field_value_of_timeout);
180 journal.update_int32(Table_Id(1), record.get_record_id(), Field_Id(3), field_value_of_timeout);
181 }
182
183 template<typename F> void update_vector_of_timeout(id_of_server record, size_t size, F f)
184 {
185 std::exception_ptr exception;
186 joedb::Span<int32_t> span(&storage_of_server.field_value_of_timeout[record.get_id() - 1], size);
187 try {f(span);}
188 catch (...) {exception = std::current_exception();}
190 journal.update_vector_int32(Table_Id(1), record.get_record_id(), Field_Id(3), size, (span.begin()));
191 if (exception)
192 std::rethrow_exception(exception);
193 }
194
195
196 };}
197
198#endif
const Buffered_File & get_file() const
T * begin()
Definition Span.h:40
void delete_vector(Table_Id table_id, Record_Id record_id, size_t size) final
void insert_vector(Table_Id table_id, Record_Id record_id, size_t size) final
int64_t ahead_of_checkpoint() const noexcept
Blob write_blob(const std::string &data) final
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 hard_checkpoint()
Definition Writable.h:23
void soft_checkpoint()
Definition Writable.h:22
Handle concurrent access to a joedb::Buffered_File using a joedb::Connection.
Definition Client.h:39
Store all the tables of the database.
Definition Database.h:82
void comment(const std::string &comment) override
Definition Database.h:428
void internal_update_vector_server__timeout(Record_Id record_id, size_t size, const int32_t *value)
Definition Database.h:232
void internal_update_server__port(Record_Id record_id, int32_t field_value_of_port)
Definition Database.h:192
void internal_update_server__timeout(Record_Id record_id, int32_t field_value_of_timeout)
Definition Database.h:222
void internal_insert_server(Record_Id record_id)
Definition Database.h:150
void internal_delete_server(Record_Id record_id)
Definition Database.h:140
void timestamp(int64_t timestamp) override
Definition Database.h:429
void internal_update_server__file_name(Record_Id record_id, const std::string &field_value_of_file_name)
Definition Database.h:168
void internal_update_vector_server__port(Record_Id record_id, size_t size, const int32_t *value)
Definition Database.h:204
detail::data_of_server storage_of_server
Definition Database.h:105
void internal_vector_insert_server(Record_Id record_id, size_t size)
Definition Database.h:156
void internal_update_vector_server__file_name(Record_Id record_id, size_t size, const std::string *value)
Definition Database.h:178
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.
std::string read_blob(joedb::Blob blob) const
void update_vector_of_timeout(id_of_server record, size_t size, F f)
void update_vector_of_port(id_of_server record, size_t size, F f)
id_of_server new_server(const std::string &field_value_of_file_name, int32_t field_value_of_port, int32_t field_value_of_timeout)
void set_file_name(id_of_server record, const std::string &field_value_of_file_name)
void update_vector_of_file_name(id_of_server record, size_t size, F f)
const joedb::Readonly_Journal & get_journal() const
void set_port(id_of_server record, int32_t field_value_of_port)
void write_comment(const std::string &comment)
void delete_vector_of_server(id_of_server v, size_t size)
joedb::Blob write_blob(const std::string &data) final
void set_timeout(id_of_server record, int32_t field_value_of_timeout)
Strongly-typed wrapper around an integer representing a row of the server table.
Definition ids.h:25
constexpr Record_Id get_record_id() const
Definition ids.h:36
constexpr size_t get_id() const
Definition ids.h:35
Automatically generated by joedbc.
Definition Client.h:19