From 654826cdafaac4199c8a8c90ef3396e312f0944f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 5 Sep 2013 13:02:10 +0200 Subject: Versioned section support --- odb/relational/inline.hxx | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'odb/relational/inline.hxx') diff --git a/odb/relational/inline.hxx b/odb/relational/inline.hxx index f5c5102..ed5081d 100644 --- a/odb/relational/inline.hxx +++ b/odb/relational/inline.hxx @@ -224,6 +224,12 @@ namespace relational bool versioned (context::versioned (c)); + // Schema name as a string literal or empty. + // + string schema_name (options.schema_name ()[db]); + if (!schema_name.empty ()) + schema_name = strlit (schema_name); + string const& type (class_fq_name (c)); string traits ("access::object_traits_impl< " + type + ", id_" + db.string () + " >"); @@ -413,18 +419,23 @@ namespace relational { os << "inline" << endl << "void " << traits << "::" << endl - << "load_ (statements_type&," << endl + << "load_ (statements_type& sts," << endl << "object_type& obj," << endl << "bool"; if (versioned) os << "," << endl - << "const schema_version_migration&"; + << "const schema_version_migration& svm"; os << ")" << "{" - << "ODB_POTENTIALLY_UNUSED (obj);" - << endl; + << "ODB_POTENTIALLY_UNUSED (sts);" + << "ODB_POTENTIALLY_UNUSED (obj);"; + + if (versioned) + os << "ODB_POTENTIALLY_UNUSED (svm);"; + + os << endl; // Mark eager sections as loaded. // @@ -437,6 +448,28 @@ namespace relational data_member& m (*i->member); + // If the section is soft- added or deleted, check the version. + // We can only end up here if the object itself is versioned + // (simple value section). + // + unsigned long long av (added (m)); + unsigned long long dv (deleted (m)); + if (av != 0 || dv != 0) + { + os << "if ("; + + if (av != 0) + os << "svm >= schema_version_migration (" << av << "ULL, true)"; + + if (av != 0 && dv != 0) + os << " &&" << endl; + + if (dv != 0) + os << "svm <= schema_version_migration (" << dv << "ULL, true)"; + + os << ")" << endl; + } + // Section access is always by reference. // member_access& ma (m.get ("get")); -- cgit v1.1