aboutsummaryrefslogtreecommitdiff
path: root/odb/relational/source.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-03-05 11:59:00 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-03-05 11:59:00 +0200
commitcd44a367fd73293b1c8edc36aa61667ca020a2eb (patch)
tree1e4ce550a525e23fb7c8c29f18ddda31b61bf066 /odb/relational/source.hxx
parent2528431334b0c8aa07c85ec798be5fc9eb5b2add (diff)
Add support for generating schema creation code into separate C++ file
Diffstat (limited to 'odb/relational/source.hxx')
-rw-r--r--odb/relational/source.hxx224
1 files changed, 4 insertions, 220 deletions
diff --git a/odb/relational/source.hxx b/odb/relational/source.hxx
index ab5220a..fb13ade 100644
--- a/odb/relational/source.hxx
+++ b/odb/relational/source.hxx
@@ -12,7 +12,6 @@
#include <sstream>
#include <odb/diagnostics.hxx>
-#include <odb/emitter.hxx>
#include <odb/relational/context.hxx>
#include <odb/relational/common.hxx>
@@ -2665,10 +2664,6 @@ namespace relational
query_parameters& qp_;
};
- //@@ (im)-perfect forwarding.
- //
- static schema_format format_embedded (schema_format::embedded);
-
//
//
struct class_: traversal::class_, virtual context
@@ -2683,14 +2678,7 @@ namespace relational
init_id_image_member_ ("id_", "id"),
init_version_image_member_ ("version_", "(*v)"),
init_id_value_member_ ("id"),
- init_version_value_member_ ("v"),
- stream_ (emitter_),
- drop_model_ (emitter_, stream_, format_embedded),
- drop_table_ (emitter_, stream_, format_embedded),
- drop_index_ (emitter_, stream_, format_embedded),
- create_model_ (emitter_, stream_, format_embedded),
- create_table_ (emitter_, stream_, format_embedded),
- create_index_ (emitter_, stream_, format_embedded)
+ init_version_value_member_ ("v")
{
init ();
}
@@ -2705,14 +2693,7 @@ namespace relational
init_id_image_member_ ("id_", "id"),
init_version_image_member_ ("version_", "(*v)"),
init_id_value_member_ ("id"),
- init_version_value_member_ ("v"),
- stream_ (emitter_),
- drop_model_ (emitter_, stream_, format_embedded),
- drop_table_ (emitter_, stream_, format_embedded),
- drop_index_ (emitter_, stream_, format_embedded),
- create_model_ (emitter_, stream_, format_embedded),
- create_table_ (emitter_, stream_, format_embedded),
- create_index_ (emitter_, stream_, format_embedded)
+ init_version_value_member_ ("v")
{
init ();
}
@@ -2734,17 +2715,6 @@ namespace relational
init_value_base_inherits_ >> init_value_base_;
init_value_member_names_ >> init_value_member_;
-
- if (embedded_schema)
- {
- drop_model_ >> drop_names_;
- drop_names_ >> drop_table_;
- drop_names_ >> drop_index_;
-
- create_model_ >> create_names_;
- create_names_ >> create_table_;
- create_names_ >> create_index_;
- }
}
virtual void
@@ -4016,180 +3986,7 @@ namespace relational
}
if (embedded_schema)
- schema (c);
- }
-
- struct schema_emitter: emitter, virtual context
- {
- void
- pass (unsigned short p)
- {
- empty_ = true;
- pass_ = p;
- new_pass_ = true;
- }
-
- // Did this pass produce anything?
- //
- bool
- empty () const
- {
- return empty_;
- }
-
- virtual void
- pre ()
- {
- first_ = true;
- }
-
- virtual void
- line (const string& l)
- {
- if (l.empty ())
- return; // Ignore empty lines.
-
- if (first_)
- {
- first_ = false;
-
- // If this line starts a new pass, then output the
- // switch/case blocks.
- //
- if (new_pass_)
- {
- new_pass_ = false;
- empty_ = false;
-
- if (pass_ == 1)
- {
- os << "switch (pass)"
- << "{"
- << "case 1:" << endl
- << "{";
- }
- else
- {
- os << "return true;" // One more pass.
- << "}"
- << "case " << pass_ << ":" << endl
- << "{";
- }
- }
-
- os << "db.execute (";
- }
- else
- os << strlit (line_ + '\n') << endl;
-
- line_ = l;
- }
-
- virtual void
- post ()
- {
- if (!first_) // Ignore empty statements.
- os << strlit (line_) << ");" << endl;
- }
-
- private:
- std::string line_;
- bool first_;
- bool empty_;
- bool new_pass_;
- unsigned short pass_;
- };
-
- virtual void
- schema (type& c)
- {
- typedef sema_rel::model::names_iterator iterator;
-
- iterator begin (c.get<iterator> ("model-range-first"));
- iterator end (c.get<iterator> ("model-range-last"));
-
- if (begin == model->names_end ())
- return; // This class doesn't have any model entities (e.g.,
- // a second class mapped to the same table).
-
- ++end; // Transform the range from [begin, end] to [begin, end).
-
- string const& type (class_fq_name (c));
- string traits ("access::object_traits< " + type + " >");
-
- // create_schema ()
- //
- os << "bool " << traits << "::" << endl
- << "create_schema (database& db, unsigned short pass, bool drop)"
- << "{"
- << "ODB_POTENTIALLY_UNUSED (db);"
- << "ODB_POTENTIALLY_UNUSED (pass);"
- << endl;
-
- // Drop.
- //
- {
- bool close (false);
-
- os << "if (drop)"
- << "{";
-
- for (unsigned short pass (1); pass < 3; ++pass)
- {
- emitter_.pass (pass);
- drop_model_->pass (pass);
- drop_table_->pass (pass);
- drop_index_->pass (pass);
-
- drop_model_->traverse (begin, end);
-
- close = close || !emitter_.empty ();
- }
-
- if (close) // Close the last case and the switch block.
- os << "return false;"
- << "}" // case
- << "}"; // switch
-
- os << "}";
- }
-
- // Create.
- //
- {
- bool close (false);
-
- os << "else"
- << "{";
-
- for (unsigned short pass (1); pass < 3; ++pass)
- {
- emitter_.pass (pass);
- create_model_->pass (pass);
- create_table_->pass (pass);
- create_index_->pass (pass);
-
- create_model_->traverse (begin, end);
-
- close = close || !emitter_.empty ();
- }
-
- if (close) // Close the last case and the switch block.
- os << "return false;"
- << "}" // case
- << "}"; // switch
-
- os << "}";
- }
-
- os << "return false;"
- << "}";
-
- os << "static const schema_catalog_entry" << endl
- << "schema_catalog_entry_" << flat_name (type) << "_ (" << endl
- << strlit (options.schema_name ()) << "," << endl
- << "&" << traits << "::create_schema);"
- << endl;
+ schema_->traverse (c);
}
//
@@ -5120,9 +4917,7 @@ namespace relational
}
private:
- bool id_;
size_t index_;
-
instance<grow_base> grow_base_;
traversal::inherits grow_base_inherits_;
instance<grow_member> grow_member_;
@@ -5151,18 +4946,7 @@ namespace relational
instance<init_value_member> init_id_value_member_;
instance<init_value_member> init_version_value_member_;
- schema_emitter emitter_;
- emitter_ostream stream_;
-
- trav_rel::qnames drop_names_;
- instance<schema::drop_model> drop_model_;
- instance<schema::drop_table> drop_table_;
- instance<schema::drop_index> drop_index_;
-
- trav_rel::qnames create_names_;
- instance<schema::create_model> create_model_;
- instance<schema::create_table> create_table_;
- instance<schema::create_index> create_index_;
+ instance<schema::cxx_object> schema_;
};
struct include: virtual context