13 Generator(
".",
"Writable_Database.h", options)
28#include "joedb/Span.h"
47 class Writable_Database: public Database
49 friend class detail::Client_Data;
51 friend class Multiplexer;
54 joedb::Writable_Journal journal;
59 void check_single_row();
75 void custom(const std::string &name) final
77 Database::custom(name);
84 out <<
" if (name == \"" << name <<
"\")\n";
85 out <<
" " << name <<
"(*this);\n";
93 out <<
" static void " << name <<
"(Writable_Database &db);\n";
103 const std::string &name,
111 out <<
"\n void create_table(const std::string &name) override;\n";
117 joedb::Buffered_File &file,
118 bool perform_initialization,
119 joedb::Readonly_Journal::Check check,
120 joedb::Commit_Level commit_level
126 joedb::Buffered_File &file,
127 joedb::Readonly_Journal::Check check = joedb::Readonly_Journal::Check::all,
128 joedb::Commit_Level commit_level = joedb::Commit_Level::no_commit
131 const joedb::Readonly_Journal &get_journal() const {return journal;}
133 std::string read_blob_data(joedb::Blob blob) const
135 return journal.get_file().read_blob_data(blob);
138 joedb::Blob write_blob_data(const std::string &data) final
140 return journal.write_blob_data(data);
143 int64_t ahead_of_checkpoint() const
145 return journal.ahead_of_checkpoint();
148 void checkpoint_no_commit()
150 journal.checkpoint(joedb::Commit_Level::no_commit);
153 void checkpoint_half_commit()
155 journal.checkpoint(joedb::Commit_Level::half_commit);
158 void checkpoint_full_commit()
160 journal.checkpoint(joedb::Commit_Level::full_commit);
165 journal.default_checkpoint();
168 void checkpoint(joedb::Commit_Level commit_level) final
170 journal.checkpoint(commit_level);
173 void write_comment(const std::string &comment);
174 void write_timestamp();
175 void write_timestamp(int64_t timestamp);
176 void write_valid_data();
177 void flush() override {journal.flush();}
180 for (
const auto &[tid, tname]: tables)
190 out <<
" void clear_" << tname <<
"_table();\n";
195 out <<
" private:\n";
200 out <<
" id_of_" << tname <<
" new_" << tname <<
"()\n";
203 out <<
" id_of_" << tname <<
" result(Record_Id(storage_of_" << tname <<
".freedom_keeper.get_free_record() - 1));\n";
204 out <<
" storage_of_" << tname <<
".resize(storage_of_" << tname <<
".freedom_keeper.size());\n";
205 out <<
" internal_insert_" << tname <<
"(result.get_record_id());\n\n";
206 out <<
" journal.insert_into(Table_Id(" << tid <<
"), result.get_record_id());\n";
207 out <<
" return result;\n";
216 out <<
" id_of_" << tname <<
" new_vector_of_" << tname <<
"(size_t size)\n";
218 out <<
" id_of_" << tname <<
" result(Record_Id(storage_of_" << tname;
219 out <<
".size() + 1));\n";
220 out <<
" storage_of_" << tname <<
".resize(storage_of_";
221 out << tname <<
".size() + size);\n";
222 out <<
" internal_vector_insert_" << tname <<
"(result.get_record_id(), size);\n";
223 out <<
" journal.insert_vector(Table_Id(" << tid;
224 out <<
"), result.get_record_id(), size);\n";
225 out <<
" return result;\n";
235 out <<
" id_of_" << tname <<
" new_" << tname <<
'\n';
240 for (
const auto &[fid, fname]: db.
get_fields(tid))
249 out <<
" field_value_of_" << fname;
256 out <<
" auto result = new_" << tname <<
"();\n";
258 for (
const auto &[fid, fname]: db.
get_fields(tid))
259 out <<
" set_" << fname <<
"(result, field_value_of_" << fname <<
");\n";
261 out <<
" return result;\n";
273 out <<
" void delete_" << tname <<
"(id_of_" << tname <<
" record)\n";
275 out <<
" internal_delete_" << tname <<
"(record.get_record_id());\n";
276 out <<
" journal.delete_from(Table_Id(" << tid <<
"), record.get_record_id());\n";
279 out <<
" void delete_vector_of_" << tname <<
"(id_of_" << tname <<
" v, size_t size)\n";
281 out <<
" for (size_t i = size; i > 0;)\n";
282 out <<
" delete_" << tname <<
"(v[--i]);\n";
289 for (
const auto &[fid, fname]: db.
get_fields(tid))
296 out <<
" void set_" << fname;
297 out <<
"(id_of_" << tname <<
" record, ";
299 out <<
" field_value_of_" << fname <<
")\n";
301 out <<
" internal_update_" << tname <<
"__" << fname;
303 out <<
"(record.get_record_id(), ";
304 out <<
"field_value_of_" << fname <<
");\n";
305 out <<
" journal.update_";
307 out <<
"(Table_Id(" << tid <<
"), record.get_record_id(), Field_Id(" << fid <<
"), ";
308 out <<
"field_value_of_" << fname;
309 if (type.
get_type_id() == Type::Type_Id::reference)
310 out <<
".get_record_id()";
319 out <<
" template<typename F> void update_vector_of_" << fname;
320 out <<
"(id_of_" << tname <<
" record, size_t size, F f)\n";
322 out <<
" std::exception_ptr exception;\n";
323 out <<
" joedb::Span<";
325 out <<
"> span(&storage_of_" << tname;
326 out <<
".field_value_of_" << fname <<
"[record.get_id() - 1], size);\n";
327 out <<
" try {f(span);}\n";
328 out <<
" catch (...) {exception = std::current_exception();}\n";
329 out <<
" internal_update_vector_" << tname <<
"__" << fname <<
"(record.get_record_id(), size, span.begin());\n";
330 out <<
" journal.update_vector_" <<
get_type_string(type) <<
"(Table_Id(" << tid <<
"), record.get_record_id(), Field_Id(" << fid <<
"), size, ";
332 if (type.
get_type_id() == Type::Type_Id::reference)
333 out <<
"reinterpret_cast<Record_Id *>";
335 out <<
"(span.begin()));\n";
336 out <<
" if (exception)\n";
337 out <<
" std::rethrow_exception(exception);\n";
const std::vector< std::string > & get_custom_names() const
const std::vector< std::string > & get_name_space() const
bool has_single_row() const
const Table_Options & get_table_options(Table_Id table_id) const
const Database & get_db() const
const std::map< Table_Id, std::string > & get_tables() const override
const Type & get_field_type(Table_Id table_id, Field_Id field_id) const override
const std::map< Field_Id, std::string > & get_fields(Table_Id table_id) const override
Type_Id get_type_id() const
static const char * get_type_string(Type type)
void write_type(Type type, bool return_type, bool setter_type)
const Compiler_Options & options
bool db_has_values() const
Writable_Database_h(const Compiler_Options &options)
void namespace_open(std::ostream &out, const std::vector< std::string > &n)
void namespace_close(std::ostream &out, const std::vector< std::string > &n)
void namespace_include_guard(std::ostream &out, const char *name, const std::vector< std::string > &n)
One code generator for each of the file generated by joedbc.