diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2010-11-26 13:24:00 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2010-11-26 13:24:00 +0200 |
commit | 51a71bc5cfe38ab7d4789f90725f8a24f49bd057 (patch) | |
tree | 066cf64fb40528c1147bb9426b3794e187bea4b9 /odb/cache-traits.hxx | |
parent | e412109818a7e1b77c3cc955cadf56b34dde44a5 (diff) |
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.
Diffstat (limited to 'odb/cache-traits.hxx')
-rw-r--r-- | odb/cache-traits.hxx | 36 |
1 files changed, 28 insertions, 8 deletions
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<element_type> (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<element_type> (db, id); } + + static void + erase (const position_type& p) + { + if (p.map_ != 0) + session::current ().erase<element_type> (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<element_type>::pointer_type pointer_type; typedef typename object_traits<element_type>::id_type id_type; - struct position_type {}; + typedef + typename pointer_cache_traits<pointer_type>::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 |