Joedb 9.1.4
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Readonly_Client_h.cpp
Go to the documentation of this file.
3
4namespace joedb::generator
5{
6 ////////////////////////////////////////////////////////////////////////////
8 ////////////////////////////////////////////////////////////////////////////
9 (
10 const Compiler_Options &options
11 ):
12 Generator(".", "Readonly_Client.h", options)
13 {
14 }
15
16 ////////////////////////////////////////////////////////////////////////////
18 ////////////////////////////////////////////////////////////////////////////
19 {
21
22 out << R"RRR(
23#include "Database.h"
24#include "joedb/concurrency/Client.h"
25#include "joedb/journal/File.h"
26
27)RRR";
28
30
31 out << R"RRR(
32 namespace detail
33 {
34 class Readonly_Client_Data
35 {
36 protected:
37 joedb::Connection connection;
38 joedb::Readonly_Journal journal;
39 Database db;
40
41 Readonly_Client_Data(joedb::File &file): journal(file)
42 {
43 db.initialize_with_readonly_journal(journal);
44 }
45 };
46 }
47
48 /// Client for a read-only file (allows pulling, unlike @ref Readonly_Database)
49 class Readonly_Client:
50 private detail::Readonly_Client_Data,
51 public joedb::Client
52 {
53 private:
54 const int64_t schema_checkpoint;
55
56 protected:
57 virtual void read_journal() override
58 {
59 journal.play_until_checkpoint(db);
60 if (db.get_schema_checkpoint() > schema_checkpoint)
61 Database::throw_exception("Pulled a schema change");
62 }
63
64 public:
65 Readonly_Client(joedb::File &file):
66 detail::Readonly_Client_Data(file),
67 joedb::Client
68 (
69 journal,
70 Readonly_Client_Data::connection,
71 false
72 ),
73 schema_checkpoint(db.get_schema_checkpoint())
74 {
75 }
76
77 const Database &get_database() const {return db;}
78 };
79)RRR";
80
82 out << "\n#endif\n";
83 }
84}
const std::vector< std::string > & get_name_space() const
const Compiler_Options & options
Definition Generator.h:14
Readonly_Client_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.
Definition Client_h.cpp:5