From 91830e3bd38a05c73d03a5dfb88997799d44274b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 6 May 2013 12:05:39 +0200 Subject: Add support for object sections Sections are an optimization mechanism that allows the partitioning of data members of a persistent class into groups that can be separately loaded and/or updated. --- odb/database.txx | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'odb/database.txx') diff --git a/odb/database.txx b/odb/database.txx index 46ec752..5d4829a 100644 --- a/odb/database.txx +++ b/odb/database.txx @@ -2,6 +2,7 @@ // copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file +#include #include #include #include @@ -96,6 +97,20 @@ namespace odb template void database:: + load_ (T& obj, section& s) + { + connection_type& c (transaction::current ().connection ()); + + // T is always object_type. + // + if (object_traits_impl::load (c, obj, s)) + s.reset (true, false); // Loaded, unchanged. + else + throw section_not_in_object (); + } + + template + void database:: reload_ (T& obj) { // T should be object_type (cannot be const). We also don't need to @@ -106,6 +121,26 @@ namespace odb } template + void database:: + update_ (const T& obj, const section& s) + { + if (!s.loaded ()) + throw section_not_loaded (); + + transaction& t (transaction::current ()); + + // T is always object_type. + // + if (object_traits_impl::update (t.connection (), obj, s)) + { + if (s.changed ()) + s.reset (true, false, &t); // Clear the change flag. + } + else + throw section_not_in_object (); + } + + template struct database::query_ { template -- cgit v1.1