summaryrefslogtreecommitdiff
path: root/odb/relational/header.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'odb/relational/header.cxx')
-rw-r--r--odb/relational/header.cxx435
1 files changed, 262 insertions, 173 deletions
diff --git a/odb/relational/header.cxx b/odb/relational/header.cxx
index 538962b..1295106 100644
--- a/odb/relational/header.cxx
+++ b/odb/relational/header.cxx
@@ -13,15 +13,14 @@ traverse_object (type& c)
using semantics::data_member;
data_member* id (id_member (c));
- bool auto_id (id ? id->count ("auto") : false);
- bool base_id (id ? &id->scope () != &c : false); // Comes from base.
+ bool auto_id (id && auto_ (*id));
+ bool base_id (id && &id->scope () != &c); // Comes from base.
data_member* optimistic (context::optimistic (c));
type* poly_root (polymorphic (c));
bool poly (poly_root != 0);
bool poly_derived (poly && poly_root != &c);
- type* poly_base (poly_derived ? &polymorphic_base (c) : 0);
data_member* discriminator (poly ? context::discriminator (*poly_root) : 0);
bool abst (abstract (c));
@@ -33,14 +32,6 @@ traverse_object (type& c)
os << "// " << class_name (c) << endl
<< "//" << endl;
- // class_traits
- //
- os << "template <>" << endl
- << "struct class_traits< " << type << " >"
- << "{"
- << "static const class_kind kind = class_object;"
- << "};";
-
// pointer_query_columns & query_columns
//
if (options.generate_query ())
@@ -58,59 +49,38 @@ traverse_object (type& c)
pointer_query_columns_type_->traverse (c);
}
- // object_traits
+ // object_traits_impl
//
os << "template <>" << endl
- << "class access::object_traits< " << type << " >"
+ << "class access::object_traits_impl< " << type << ", id_" << db <<
+ " >:" << endl
+ << " public access::object_traits< " << type << " >"
<< "{"
<< "public:" << endl;
object_public_extra_pre (c);
- // object_type & pointer_type
- //
- os << "typedef " << type << " object_type;"
- << "typedef " << c.get<string> ("object-pointer") << " pointer_type;"
- << "typedef odb::pointer_traits<pointer_type> pointer_traits;"
- << endl;
-
- // polymorphic, root_type, base_type, etc.
+ // Polymorphic root_traits, base_traits, and discriminator_image_type.
//
- os << "static const bool polymorphic = " << (poly ? "true" : "false") << ";";
-
if (poly)
{
- os << "typedef " << class_fq_name (*poly_root) << " root_type;"
- << "typedef object_traits<root_type> root_traits;";
+ if (!abst)
+ os << "typedef polymorphic_entry<object_type, id_" << db <<
+ "> entry_type;";
+
+ os << "typedef object_traits_impl<root_type, id_" << db << "> " <<
+ "root_traits;";
if (poly_derived)
{
- os << "typedef " << class_fq_name (*poly_base) << " base_type;"
- << "typedef object_traits<base_type> base_traits;"
- << "typedef root_traits::discriminator_type discriminator_type;"
- << "typedef odb::polymorphic_concrete_info<root_type> info_type;";
-
- if (abst)
- os << "typedef odb::polymorphic_abstract_info<root_type> " <<
- "abstract_info_type;";
- else
- os << "typedef odb::polymorphic_entry<object_type> entry_type;";
-
- // Calculate our hierarchy depth (number of classes).
- //
- size_t depth (polymorphic_depth (c));
-
- os << "static const std::size_t depth = " << depth << "UL;";
+ os << "typedef object_traits_impl<base_type, id_" << db << "> " <<
+ "base_traits;"
+ << endl;
}
else
{
- semantics::names* hint;
- semantics::type& t (utype (*discriminator, hint));
-
- os << "typedef " << t.fq_name (hint) << " discriminator_type;"
- << endl;
-
- os << "struct discriminator_image_type"
+ os << endl
+ << "struct discriminator_image_type"
<< "{";
discriminator_image_member_->traverse (*discriminator);
@@ -120,23 +90,10 @@ traverse_object (type& c)
os << "std::size_t version;"
<< "};";
-
- os << "typedef odb::polymorphic_map<object_type> map_type;"
- << "typedef odb::polymorphic_concrete_info<object_type> info_type;";
-
- if (abst)
- os << "typedef odb::polymorphic_abstract_info<object_type> " <<
- "abstract_info_type;";
- else
- os << "typedef odb::polymorphic_entry<object_type> entry_type;";
-
- os << "static const std::size_t depth = 1UL;";
}
}
- os << endl;
-
- // id_type & id_image_type
+ // id_image_type
//
if (id != 0)
{
@@ -144,44 +101,14 @@ traverse_object (type& c)
{
semantics::class_& b (
dynamic_cast<semantics::class_&> (id->scope ()));
- string const& type (class_fq_name (b));
+ string const& type ();
- os << "typedef object_traits< " << type << " >::id_type id_type;";
-
- if (optimistic != 0)
- os << "typedef object_traits< " << type << " >::version_type " <<
- "version_type;";
-
- if (poly_derived)
- os << "typedef object_traits< " << type << " >:: id_image_type " <<
- "id_image_type;"
- << "static const bool auto_id = false;"
- << endl;
- else
- os << "typedef object_traits< " << type << " >::id_image_type " <<
- "id_image_type;"
- << "static const bool auto_id = object_traits< " << type <<
- " >::auto_id;"
- << endl;
+ os << "typedef object_traits_impl< " << class_fq_name (b) << ", " <<
+ "id_" << db << " >::id_image_type id_image_type;"
+ << endl;
}
else
{
- {
- semantics::names* hint;
- semantics::type& t (utype (*id, hint));
- os << "typedef " << t.fq_name (hint) << " id_type;";
- }
-
- if (optimistic != 0)
- {
- semantics::names* hint;
- semantics::type& t (utype (*optimistic, hint));
- os << "typedef " << t.fq_name (hint) << " version_type;";
- }
-
- os << "static const bool auto_id = " << (auto_id ? "true;" : "false;")
- << endl;
-
os << "struct id_image_type"
<< "{";
@@ -194,19 +121,6 @@ traverse_object (type& c)
<< "};";
}
}
- else if (!reuse_abst)
- {
- // Object without id.
- //
- os << "typedef void id_type;"
- << "static const bool auto_id = false;"
- << endl;
- }
-
- // abstract
- //
- os << "static const bool abstract = " << (abst ? "true" : "false") << ";"
- << endl;
// Polymorphic map.
//
@@ -236,19 +150,9 @@ traverse_object (type& c)
// Functions (abstract and concrete).
//
- // id ()
- //
if (id != 0 || !reuse_abst)
- {
- // We want to generate a dummy void id() accessor even if this
- // object has no id to help us in the runtime. This way we can
- // write generic code that will work for both void and non-void
- // ids.
- //
- os << "static id_type" << endl
- << "id (const object_type&);"
+ os << "using object_traits<object_type>::id;"
<< endl;
- }
if (!poly_derived && id != 0)
{
@@ -370,45 +274,6 @@ traverse_object (type& c)
return;
}
- // Cache traits typedefs.
- //
- if (id == 0)
- {
- os << "typedef" << endl
- << "odb::no_id_pointer_cache_traits<pointer_type>" << endl
- << "pointer_cache_traits;"
- << "typedef" << endl
- << "odb::no_id_reference_cache_traits<object_type>" << endl
- << "reference_cache_traits;"
- << endl;
- }
- else
- {
- char const* p (session (c) ? "" : "no_op_");
-
- if (poly_derived)
- {
- os << "typedef" << endl
- << "odb::" << p << "pointer_cache_traits<" <<
- "root_traits::pointer_type>" << endl
- << "pointer_cache_traits;"
- << "typedef" << endl
- << "odb::" << p << "reference_cache_traits<root_type>" << endl
- << "reference_cache_traits;"
- << endl;
- }
- else
- {
- os << "typedef" << endl
- << "odb::" << p << "pointer_cache_traits<pointer_type>" << endl
- << "pointer_cache_traits;"
- << "typedef" << endl
- << "odb::" << p << "reference_cache_traits<object_type>" << endl
- << "reference_cache_traits;"
- << endl;
- }
- }
-
// Statements typedefs.
//
if (poly)
@@ -418,6 +283,7 @@ traverse_object (type& c)
<< db << "::polymorphic_derived_object_statements" <<
"<object_type>" << endl
<< "statements_type;"
+ << endl
<< "typedef" << endl
<< db << "::polymorphic_root_object_statements<root_type>" << endl
<< "root_statements_type;"
@@ -426,6 +292,7 @@ traverse_object (type& c)
os << "typedef" << endl
<< db << "::polymorphic_root_object_statements<object_type>" << endl
<< "statements_type;"
+ << endl
<< "typedef statements_type root_statements_type;"
<< "typedef " << db << "::object_statements<object_type> " <<
"base_statements_type;"
@@ -451,7 +318,7 @@ traverse_object (type& c)
{
// query_base_type
//
- os << "typedef " << db << "::query query_base_type;"
+ os << "typedef " << db << "::query_base query_base_type;"
<< endl;
}
@@ -526,16 +393,6 @@ traverse_object (type& c)
// Functions (concrete).
//
- // callback ()
- //
- os << "static void" << endl
- << "callback (database&, object_type&, callback_event);"
- << endl;
-
- os << "static void" << endl
- << "callback (database&, const object_type&, callback_event);"
- << endl;
-
// persist ()
//
os << "static void" << endl
@@ -622,13 +479,27 @@ traverse_object (type& c)
//
if (options.generate_query ())
{
- os << "static result<object_type>" << endl
- << "query (database&, const query_base_type&);"
- << endl;
+ if (!options.omit_unprepared ())
+ {
+ os << "static result<object_type>" << endl
+ << "query (database&, const query_base_type&);"
+ << endl;
+ }
os << "static unsigned long long" << endl
<< "erase_query (database&, const query_base_type&);"
<< endl;
+
+ if (options.generate_prepared ())
+ {
+ os << "static odb::details::shared_ptr<prepared_query_impl>" << endl
+ << "prepare_query (connection&, const char*, const query_base_type&);"
+ << endl;
+
+ os << "static odb::details::shared_ptr<result_impl>" << endl
+ << "execute_query (prepared_query_impl&);"
+ << endl;
+ }
}
// create_schema ()
@@ -736,6 +607,224 @@ traverse_object (type& c)
}
os << "};";
+
+
+ // object_traits_impl< , id_default>
+ //
+ // Note that it is not generated for reuse-abstract classes.
+ //
+ if (options.default_database_specified () &&
+ options.default_database () == db)
+ {
+ os << "template <>" << endl
+ << "class access::object_traits_impl< " << type << ", " <<
+ "id_default >:" << endl
+ << " public access::object_traits_impl< " << type << ", " <<
+ "id_" << db << " >"
+ << "{"
+ << "};";
+ }
+}
+
+void relational::header::class1::
+traverse_view (type& c)
+{
+ string const& type (class_fq_name (c));
+
+ os << "// " << class_name (c) << endl
+ << "//" << endl;
+
+ // view_traits_impl
+ //
+ os << "template <>" << endl
+ << "class access::view_traits_impl< " << type << ", id_" <<
+ db << " >:" << endl
+ << " public access::view_traits< " << type << " >"
+ << "{"
+ << "public:" << endl;
+
+ view_public_extra_pre (c);
+
+ // image_type
+ //
+ image_type_->traverse (c);
+
+ os << "typedef " << db << "::view_statements<view_type> statements_type;"
+ << endl;
+
+ //
+ // Query.
+ //
+
+ // query_base_type and query_columns (definition generated by class2).
+ //
+ os << "typedef " << db << "::query_base query_base_type;"
+ << "struct query_columns";
+
+ if (c.get<size_t> ("object-count") == 0)
+ os << "{"
+ << "};";
+ else
+ os << ";"
+ << endl;
+
+ //
+ // Functions.
+ //
+
+ // grow ()
+ //
+ if (generate_grow)
+ {
+ os << "static bool" << endl
+ << "grow (image_type&, " << truncated_vector << ");"
+ << endl;
+ }
+
+ // bind (image_type)
+ //
+ os << "static void" << endl
+ << "bind (" << bind_vector << ", image_type&);"
+ << endl;
+
+ // init (view, image)
+ //
+ os << "static void" << endl
+ << "init (view_type&, const image_type&, database*);"
+ << endl;
+
+ // column_count
+ //
+ os << "static const std::size_t column_count = " <<
+ column_count (c).total << "UL;"
+ << endl;
+
+ // Statements.
+ //
+ view_query& vq (c.get<view_query> ("query"));
+
+ if (vq.kind != view_query::runtime)
+ {
+ os << "static query_base_type" << endl
+ << "query_statement (const query_base_type&);"
+ << endl;
+ }
+
+ //
+ // Functions.
+ //
+
+ // query ()
+ //
+ if (!options.omit_unprepared ())
+ os << "static result<view_type>" << endl
+ << "query (database&, const query_base_type&);"
+ << endl;
+
+ if (options.generate_prepared ())
+ {
+ os << "static odb::details::shared_ptr<prepared_query_impl>" << endl
+ << "prepare_query (connection&, const char*, const query_base_type&);"
+ << endl;
+
+ os << "static odb::details::shared_ptr<result_impl>" << endl
+ << "execute_query (prepared_query_impl&);"
+ << endl;
+ }
+
+ view_public_extra_post (c);
+
+ os << "};";
+
+ // view_traits_impl< , id_default>
+ //
+ if (options.default_database_specified () &&
+ options.default_database () == db)
+ {
+ os << "template <>" << endl
+ << "class access::view_traits_impl< " << type << ", " <<
+ "id_default >:" << endl
+ << " public access::view_traits_impl< " << type << ", " <<
+ "id_" << db << " >"
+ << "{"
+ << "};";
+ }
+}
+
+void relational::header::class1::
+traverse_composite (type& c)
+{
+ string const& type (class_fq_name (c));
+
+ os << "// " << class_name (c) << endl
+ << "//" << endl;
+
+ os << "template <>" << endl
+ << "class access::composite_value_traits< " << type << ", " <<
+ "id_" << db << " >"
+ << "{"
+ << "public:" << endl;
+
+ // value_type
+ //
+ os << "typedef " << type << " value_type;"
+ << endl;
+
+ // image_type
+ //
+ image_type_->traverse (c);
+
+ // Containers.
+ //
+ {
+ instance<container_traits> t (c);
+ t->traverse (c);
+ }
+
+ // grow ()
+ //
+ if (generate_grow)
+ {
+ os << "static bool" << endl
+ << "grow (image_type&, " << truncated_vector << ");"
+ << endl;
+ }
+
+ // bind (image_type)
+ //
+ os << "static void" << endl
+ << "bind (" << bind_vector << ", image_type&, " <<
+ db << "::statement_kind);"
+ << endl;
+
+ // init (image, value)
+ //
+ os << "static " << (generate_grow ? "bool" : "void") << endl
+ << "init (image_type&, const value_type&, " << db << "::statement_kind);"
+ << endl;
+
+ // init (value, image)
+ //
+ os << "static void" << endl
+ << "init (value_type&, const image_type&, database*);"
+ << endl;
+
+ if (!has_a (c, test_container))
+ {
+ // get_null (image)
+ //
+ os << "static bool" << endl
+ << "get_null (const image_type&);"
+ << endl;
+
+ // set_null (image)
+ //
+ os << "static void" << endl
+ << "set_null (image_type&, " << db << "::statement_kind);"
+ << endl;
+ }
+
+ os << "};";
}
void relational::header::