summaryrefslogtreecommitdiff
path: root/odb/relational/header.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-10-27 15:16:49 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-10-27 15:16:49 +0200
commit8d82c02a90cd7cc3f161828624db5b973585c34c (patch)
tree7b04f0b5e1b9e6eb3a2e76395df6a132be7a78d0 /odb/relational/header.hxx
parent9d10c570acf1b7e8ed7c0a750ae3edfa70da200b (diff)
Add support for persistent classes without object ids
New pragma id (object). New test: common/no-id.
Diffstat (limited to 'odb/relational/header.hxx')
-rw-r--r--odb/relational/header.hxx119
1 files changed, 71 insertions, 48 deletions
diff --git a/odb/relational/header.hxx b/odb/relational/header.hxx
index 7c74d09..a331b3f 100644
--- a/odb/relational/header.hxx
+++ b/odb/relational/header.hxx
@@ -925,6 +925,7 @@ namespace relational
virtual void
traverse_object (type& c)
{
+ bool abstract (context::abstract (c));
string const& type (c.fq_name ());
semantics::data_member* id (id_member (c));
@@ -1013,6 +1014,15 @@ namespace relational
<< "};";
}
}
+ else if (!abstract)
+ {
+ // Object without id.
+ //
+ os << "typedef void id_type;"
+ << endl
+ << "static const bool auto_id = false;"
+ << endl;
+ }
// image_type
//
@@ -1033,17 +1043,19 @@ namespace relational
// id ()
//
- if (id != 0)
- {
+ if (id != 0 || !abstract)
+ // 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
+ // generic code that will both for both void and non-void ids.
+ //
os << "static id_type" << endl
<< "id (const object_type&);"
<< endl;
- if (options.generate_query ())
- os << "static id_type" << endl
- << "id (const image_type&);"
- << endl;
- }
+ if (id != 0 && options.generate_query ())
+ os << "static id_type" << endl
+ << "id (const image_type&);"
+ << endl;
// grow ()
//
@@ -1095,7 +1107,7 @@ namespace relational
//
// The rest only applies to concrete objects.
//
- if (abstract (c))
+ if (abstract)
{
object_public_extra_post (c);
os << "};";
@@ -1124,8 +1136,9 @@ namespace relational
// Statement cache (forward declaration).
//
- os << "struct container_statement_cache_type;"
- << endl;
+ if (id != 0)
+ os << "struct container_statement_cache_type;"
+ << endl;
// column_count
//
@@ -1139,13 +1152,17 @@ namespace relational
// Statements.
//
- os << "static const char persist_statement[];"
- << "static const char find_statement[];";
+ os << "static const char persist_statement[];";
- if (cc.total != cc.id + cc.inverse + cc.readonly)
- os << "static const char update_statement[];";
+ if (id != 0)
+ {
+ os << "static const char find_statement[];";
- os << "static const char erase_statement[];";
+ if (cc.total != cc.id + cc.inverse + cc.readonly)
+ os << "static const char update_statement[];";
+
+ os << "static const char erase_statement[];";
+ }
if (options.generate_query ())
{
@@ -1178,29 +1195,32 @@ namespace relational
"object_type&);"
<< endl;
- // update ()
- //
- if (!readonly (c))
- os << "static void" << endl
- << "update (database&, const object_type&);"
+ if (id != 0)
+ {
+ // find ()
+ //
+ if (c.default_ctor ())
+ os << "static pointer_type" << endl
+ << "find (database&, const id_type&);"
+ << endl;
+
+ os << "static bool" << endl
+ << "find (database&, const id_type&, object_type&);"
<< endl;
- // erase ()
- //
- os << "static void" << endl
- << "erase (database&, const id_type&);"
- << endl;
+ // update ()
+ //
+ if (!readonly (c))
+ os << "static void" << endl
+ << "update (database&, const object_type&);"
+ << endl;
- // find ()
- //
- if (c.default_ctor ())
- os << "static pointer_type" << endl
- << "find (database&, const id_type&);"
+ // erase ()
+ //
+ os << "static void" << endl
+ << "erase (database&, const id_type&);"
<< endl;
-
- os << "static bool" << endl
- << "find (database&, const id_type&, object_type&);"
- << endl;
+ }
// query ()
//
@@ -1230,21 +1250,24 @@ namespace relational
//
os << "public:" << endl;
- // Load the object image.
- //
- os << "static bool" << endl
- << "find_ (" << db << "::object_statements< object_type >&, " <<
- "const id_type&);"
- << endl;
+ if (id != 0)
+ {
+ // Load the object image.
+ //
+ os << "static bool" << endl
+ << "find_ (" << db << "::object_statements< object_type >&, " <<
+ "const id_type&);"
+ << endl;
- // Load the rest of the object (containers, etc). Expects the id
- // image in the object statements to be initialized to the object
- // id.
- //
- os << "static void" << endl
- << "load_ (" << db << "::object_statements< object_type >&, " <<
- "object_type&);"
- << endl;
+ // Load the rest of the object (containers, etc). Expects the id
+ // image in the object statements to be initialized to the object
+ // id.
+ //
+ os << "static void" << endl
+ << "load_ (" << db << "::object_statements< object_type >&, " <<
+ "object_type&);"
+ << endl;
+ }
os << "};";
}