From c93d7f6453f8aebdc80fba44032f692eb5da8a9c Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 4 Sep 2013 12:57:25 +0200 Subject: Container versioning support --- odb/relational/source.cxx | 64 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 15 deletions(-) (limited to 'odb/relational/source.cxx') diff --git a/odb/relational/source.cxx b/odb/relational/source.cxx index 4363dcb..0a8b224 100644 --- a/odb/relational/source.cxx +++ b/odb/relational/source.cxx @@ -1091,7 +1091,12 @@ traverse_object (type& c) // persist () // - bool persist_containers (has_a (c, test_straight_container)); + size_t persist_containers (has_a (c, test_straight_container)); + bool persist_versioned_containers ( + persist_containers > + has_a (c, + test_straight_container | + exclude_deleted | exclude_added | exclude_versioned)); os << "void " << traits << "::" << endl << "persist (database& db, " << (auto_id ? "" : "const ") << @@ -1132,7 +1137,7 @@ traverse_object (type& c) << "throw abstract_class ();" << endl; - if (versioned) + if (versioned || persist_versioned_containers) os << "const schema_version_migration& svm (" << "db.schema_version_migration (" << schema_name << "));"; @@ -1369,9 +1374,16 @@ traverse_object (type& c) // if (id != 0 && (!readonly || poly)) { - bool update_containers ( + size_t update_containers ( has_a (c, test_readwrite_container, &main_section)); + bool update_versioned_containers ( + update_containers > + has_a (c, + test_readwrite_container | + exclude_deleted | exclude_added | exclude_versioned, + &main_section)); + // See if we have any sections that we might have to update. // bool sections (false); @@ -1437,6 +1449,11 @@ traverse_object (type& c) << endl; } + if ((versioned && update_columns) || update_versioned_containers) + os << "const schema_version_migration& svm (" << + "db.schema_version_migration (" << schema_name << "));" + << endl; + // If we have change-updated sections that contain change-tracking // containers, then mark such sections as changed if any of the // containers was changed. Do this before calling the base so that @@ -1458,6 +1475,9 @@ traverse_object (type& c) os << "// " << m.name () << endl << "//" << endl + + //@@ TODO version check. + << "{"; // Section access is always by reference. @@ -1490,11 +1510,6 @@ traverse_object (type& c) << "}"; } - if (versioned && update_columns) - os << "const schema_version_migration& svm (" << - "db.schema_version_migration (" << schema_name << "));" - << endl; - if (poly_derived) { bool readonly_base (context::readonly (*poly_base)); @@ -2535,7 +2550,7 @@ traverse_object (type& c) if (delay_freeing_statement_result) os << "ar.free ();"; - os << "load_ (sts, obj);"; + os << "load_ (sts, obj, false" << (versioned ? ", svm" : "") << ");"; if (poly) // Load the dynamic part of the object unless static and dynamic @@ -2659,7 +2674,7 @@ traverse_object (type& c) if (delay_freeing_statement_result) os << "ar.free ();"; - os << "load_ (sts, obj);" + os << "load_ (sts, obj, false" << (versioned ? ", svm" : "") << ");" << rsts << ".load_delayed (" << (versioned ? "&svm" : "0") << ");" << "l.unlock ();" << "callback (db, obj, callback_event::post_load);" @@ -2781,7 +2796,7 @@ traverse_object (type& c) if (delay_freeing_statement_result) os << "ar.free ();"; - os << "load_ (sts, obj, true);" + os << "load_ (sts, obj, true" << (versioned ? ", svm" : "") << ");" << rsts << ".load_delayed (" << (versioned ? "&svm" : "0") << ");" << "l.unlock ();" << "callback (db, obj, callback_event::post_load);" @@ -3240,9 +3255,16 @@ traverse_object (type& c) // // Load containers, reset/reload sections. // - bool load_containers ( + size_t load_containers ( has_a (c, test_container | include_eager_load, &main_section)); + bool load_versioned_containers ( + load_containers > + has_a (c, + test_container | include_eager_load | + exclude_deleted | exclude_added | exclude_versioned, + &main_section)); + if (poly_derived || load_containers || uss.count (user_sections::count_new | @@ -3254,18 +3276,25 @@ traverse_object (type& c) << "object_type& obj," << endl << "bool reload"; + if (versioned) + os << "," << endl + << "const schema_version_migration& svm"; + if (poly_derived) os << "," << endl << "std::size_t d"; os << ")" << "{" - << "ODB_POTENTIALLY_UNUSED (reload);" - << endl; + << "ODB_POTENTIALLY_UNUSED (reload);"; + if (versioned) + os << "ODB_POTENTIALLY_UNUSED (svm);"; + os << endl; if (poly_derived) os << "if (--d != 0)" << endl << "base_traits::load_ (sts.base_statements (), obj, reload" << + (context::versioned (*poly_base) ? ", svm" : "") << (poly_base != poly_root ? ", d" : "") << ");" << endl; @@ -3277,6 +3306,11 @@ traverse_object (type& c) if (load_containers) { + if (load_versioned_containers && !versioned) + os << "const schema_version_migration& svm (" << endl + << "sts.connection ().database ().schema_version_migration (" << + schema_name << "));"; + instance t (container_calls::load_call, &main_section); t->traverse (c); } @@ -3406,7 +3440,7 @@ traverse_object (type& c) if (empty_depth != 0) os << "}"; - os << "load_ (sts, obj, false, d);" + os << "load_ (sts, obj, false, " << (versioned ? "svm, " : "") << "d);" << "}"; } -- cgit v1.1