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();
74 void custom(const std::string &name) final
76 Database::custom(name);
83 out <<
" if (name == \"" << name <<
"\")\n";
84 out <<
" " << name <<
"(*this);\n";
92 out <<
" static void " << name <<
"(Writable_Database &db);\n";
102 const std::string &name,
110 out <<
"\n void create_table(const std::string &name) override;\n";
116 joedb::Buffered_File &file,
117 bool perform_initialization
121 Writable_Database(joedb::Buffered_File &file);
123 const joedb::Readonly_Journal &get_journal() const {return journal;}
125 std::string read_blob(joedb::Blob blob) const
127 return journal.get_file().read_blob(blob);
130 joedb::Blob write_blob(const std::string &data) final
132 return journal.write_blob(data);
135 int64_t ahead_of_checkpoint() const
137 return journal.ahead_of_checkpoint();
140 void soft_checkpoint()
142 journal.soft_checkpoint();
145 void hard_checkpoint()
147 journal.hard_checkpoint();
150 void write_comment(const std::string &comment);
151 void write_timestamp();
152 void write_timestamp(int64_t timestamp);
153 void write_valid_data();
154 void flush() override {journal.flush();}
157 for (
const auto &[tid, tname]: tables)
167 out <<
" void clear_" << tname <<
"_table();\n";
172 out <<
" private:\n";
177 out <<
" id_of_" << tname <<
" new_" << tname <<
"()\n";
180 out <<
" id_of_" << tname <<
" result(Record_Id(storage_of_" << tname <<
".freedom_keeper.get_free_record() - 1));\n";
181 out <<
" storage_of_" << tname <<
".resize(storage_of_" << tname <<
".freedom_keeper.size());\n";
182 out <<
" internal_insert_" << tname <<
"(result.get_record_id());\n\n";
183 out <<
" journal.insert_into(Table_Id(" << tid <<
"), result.get_record_id());\n";
184 out <<
" return result;\n";
193 out <<
" id_of_" << tname <<
" new_vector_of_" << tname <<
"(size_t size)\n";
195 out <<
" id_of_" << tname <<
" result(Record_Id(storage_of_" << tname;
196 out <<
".size() + 1));\n";
197 out <<
" storage_of_" << tname <<
".resize(storage_of_";
198 out << tname <<
".size() + size);\n";
199 out <<
" internal_vector_insert_" << tname <<
"(result.get_record_id(), size);\n";
200 out <<
" journal.insert_vector(Table_Id(" << tid;
201 out <<
"), result.get_record_id(), size);\n";
202 out <<
" return result;\n";
212 out <<
" id_of_" << tname <<
" new_" << tname <<
'\n';
217 for (
const auto &[fid, fname]: db.
get_fields(tid))
226 out <<
" field_value_of_" << fname;
233 out <<
" auto result = new_" << tname <<
"();\n";
235 for (
const auto &[fid, fname]: db.
get_fields(tid))
236 out <<
" set_" << fname <<
"(result, field_value_of_" << fname <<
");\n";
238 out <<
" return result;\n";
250 out <<
" void delete_" << tname <<
"(id_of_" << tname <<
" record)\n";
252 out <<
" internal_delete_" << tname <<
"(record.get_record_id());\n";
253 out <<
" journal.delete_from(Table_Id(" << tid <<
"), record.get_record_id());\n";
256 out <<
" void delete_vector_of_" << tname <<
"(id_of_" << tname <<
" v, size_t size)\n";
258 out <<
" for (size_t i = size; i > 0;)\n";
259 out <<
" internal_delete_" << tname <<
"(v[--i].get_record_id());\n";
260 out <<
" journal.delete_vector(Table_Id(" << tid <<
"), v.get_record_id(), size);\n";
267 for (
const auto &[fid, fname]: db.
get_fields(tid))
274 out <<
" void set_" << fname;
275 out <<
"(id_of_" << tname <<
" record, ";
277 out <<
" field_value_of_" << fname <<
")\n";
279 out <<
" internal_update_" << tname <<
"__" << fname;
281 out <<
"(record.get_record_id(), ";
282 out <<
"field_value_of_" << fname <<
");\n";
283 out <<
" journal.update_";
285 out <<
"(Table_Id(" << tid <<
"), record.get_record_id(), Field_Id(" << fid <<
"), ";
286 out <<
"field_value_of_" << fname;
287 if (type.
get_type_id() == Type::Type_Id::reference)
288 out <<
".get_record_id()";
297 out <<
" template<typename F> void update_vector_of_" << fname;
298 out <<
"(id_of_" << tname <<
" record, size_t size, F f)\n";
300 out <<
" std::exception_ptr exception;\n";
301 out <<
" joedb::Span<";
303 out <<
"> span(&storage_of_" << tname;
304 out <<
".field_value_of_" << fname <<
"[record.get_id() - 1], size);\n";
305 out <<
" try {f(span);}\n";
306 out <<
" catch (...) {exception = std::current_exception();}\n";
307 out <<
" internal_update_vector_" << tname <<
"__" << fname <<
"(record.get_record_id(), size, span.begin());\n";
308 out <<
" journal.update_vector_" <<
get_type_string(type) <<
"(Table_Id(" << tid <<
"), record.get_record_id(), Field_Id(" << fid <<
"), size, ";
310 if (type.
get_type_id() == Type::Type_Id::reference)
311 out <<
"reinterpret_cast<Record_Id *>";
313 out <<
"(span.begin()));\n";
314 out <<
" if (exception)\n";
315 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.