From 51a71bc5cfe38ab7d4789f90725f8a24f49bd057 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 26 Nov 2010 13:24:00 +0200 Subject: Add support for recursive object loading If an object of a type needs to be loaded recursively, then it is addded to the delayed loading list which is processed once the statements are unlocked. --- odb/cache-traits.hxx | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'odb/cache-traits.hxx') diff --git a/odb/cache-traits.hxx b/odb/cache-traits.hxx index 5d32624..a475d35 100644 --- a/odb/cache-traits.hxx +++ b/odb/cache-traits.hxx @@ -27,12 +27,10 @@ namespace odb struct insert_guard { insert_guard (const position_type& pos): pos_ (pos) {} + ~insert_guard () {erase (pos_);} - ~insert_guard () - { - if (pos_.map_ != 0) - session::current ().erase (pos_); - } + position_type + position () const {return pos_;} void release () {pos_.map_ = 0;} @@ -65,6 +63,13 @@ namespace odb if (session::has_current ()) session::current ().erase (db, id); } + + static void + erase (const position_type& p) + { + if (p.map_ != 0) + session::current ().erase (p); + } }; // Unique pointers don't work with the object cache. @@ -80,7 +85,12 @@ namespace odb struct insert_guard { insert_guard (const position_type&) {} - void release () {} + + position_type + position () const {return position_type ();} + + void + release () {} }; static position_type @@ -94,6 +104,9 @@ namespace odb static void erase (database&, const id_type&) {} + + static void + erase (const position_type&) {} }; // Caching traits for objects passed by reference. Only if the object @@ -108,12 +121,19 @@ namespace odb typedef typename object_traits::pointer_type pointer_type; typedef typename object_traits::id_type id_type; - struct position_type {}; + typedef + typename pointer_cache_traits::position_type + position_type; struct insert_guard { insert_guard (const position_type&) {} - void release () {} + + position_type + position () const {return position_type ();} + + void + release () {} }; static position_type -- cgit v1.1