summaryrefslogtreecommitdiff
path: root/odb/common.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-11-06 18:05:19 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-11-06 18:05:19 +0200
commitce696c26d2c9dd5a5813fd865082ab19ac49bcfa (patch)
treec44331b2a6e6fa1d9d518ddff63e711ce5d308c4 /odb/common.cxx
parent727a83dc82fa094aa91630d165d230a9a2dabe60 (diff)
Add support for container persistence
Diffstat (limited to 'odb/common.cxx')
-rw-r--r--odb/common.cxx159
1 files changed, 155 insertions, 4 deletions
diff --git a/odb/common.cxx b/odb/common.cxx
index f398b6e..992b34b 100644
--- a/odb/common.cxx
+++ b/odb/common.cxx
@@ -8,13 +8,157 @@
using namespace std;
//
+// object_members_base
+//
+
+void object_members_base::
+simple (semantics::data_member&)
+{
+}
+
+void object_members_base::
+composite (semantics::data_member&, semantics::type& t)
+{
+ dispatch (t);
+}
+
+void object_members_base::
+container (semantics::data_member&)
+{
+}
+
+void object_members_base::
+traverse_composite (semantics::data_member& m, semantics::type& t)
+{
+ composite (m, t);
+}
+
+void object_members_base::
+traverse (semantics::class_& c)
+{
+ if (build_table_prefix_ && c.count ("object"))
+ {
+ table_prefix_.prefix = ctx_->table_name (c);
+ table_prefix_.prefix += '_';
+ table_prefix_.level = 1;
+
+ inherits (c);
+ names (c);
+
+ table_prefix_.level = 0;
+ table_prefix_.prefix.clear ();
+ }
+ else
+ {
+ inherits (c);
+ names (c);
+ }
+}
+
+void object_members_base::member::
+traverse (semantics::data_member& m)
+{
+ if (m.count ("transient"))
+ return;
+
+ semantics::type& t (m.type ());
+
+ if (context::comp_value (t))
+ {
+ string old_prefix, old_table_prefix;
+
+ if (om_.build_prefix_)
+ {
+ old_prefix = om_.prefix_;
+ om_.prefix_ += om_.ctx_->public_name (m);
+ om_.prefix_ += '_';
+ }
+
+ if (om_.build_table_prefix_)
+ {
+ old_table_prefix = om_.table_prefix_.prefix;
+
+ // If the user provided a table prefix, then use it verbatim. Also
+ // drop the top-level table prefix in this case.
+ //
+ if (m.count ("table"))
+ {
+ if (om_.table_prefix_.level == 1)
+ om_.table_prefix_.prefix.clear ();
+
+ om_.table_prefix_.prefix += m.get<string> ("table");
+ }
+ // Otherwise use the member name and add an underscore unless it is
+ // already there.
+ //
+ else
+ {
+ string name (om_.ctx_->public_name_db (m));
+ size_t n (name.size ());
+
+ om_.table_prefix_.prefix += name;
+
+ if (n != 0 && name[n - 1] != '_')
+ om_.table_prefix_.prefix += '_';
+ }
+
+ om_.table_prefix_.level++;
+ }
+
+ om_.composite (m, t);
+
+ if (om_.build_table_prefix_)
+ {
+ om_.table_prefix_.level--;
+ om_.table_prefix_.prefix = old_table_prefix;
+ }
+
+ if (om_.build_prefix_)
+ om_.prefix_ = old_prefix;
+ }
+ else if (context::container (t))
+ {
+ om_.container (m);
+ }
+ else
+ {
+ om_.simple (m);
+ }
+}
+
+//
// object_columns_base
//
void object_columns_base::
-composite (semantics::data_member& m)
+composite (semantics::data_member&, semantics::type& t)
{
- dispatch (m.type ());
+ dispatch (t);
+}
+
+void object_columns_base::
+traverse_composite (semantics::data_member& m,
+ semantics::type& t,
+ string const& key_prefix,
+ string const& default_name)
+{
+ bool custom (m.count (key_prefix + "-column"));
+ string name (member_.column_name (m, key_prefix, default_name));
+
+ // If the user provided the column prefix, then use it verbatime.
+ // Otherwise, append the underscore, unless it is already there.
+ //
+ member_.prefix_ = name;
+
+ if (!custom)
+ {
+ size_t n (name.size ());
+
+ if (n != 0 && name[n - 1] != '_')
+ member_.prefix_ += '_';
+ }
+
+ composite (m, t);
}
void object_columns_base::
@@ -30,7 +174,9 @@ traverse (semantics::data_member& m)
if (m.count ("transient"))
return;
- if (comp_value (m.type ()))
+ semantics::type& t (m.type ());
+
+ if (comp_value (t))
{
string old_prefix (prefix_);
@@ -50,10 +196,15 @@ traverse (semantics::data_member& m)
prefix_ += '_';
}
- oc_.composite (m);
+ oc_.composite (m, t);
prefix_ = old_prefix;
}
+ else if (container (t))
+ {
+ // Container gets its own table, so nothing to do here.
+ //
+ }
else
{
oc_.column (m, prefix_ + column_name (m), first_);