diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-09-05 10:20:47 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-09-05 10:20:47 +0200 |
commit | 9c275a93cec797a021571ba8545906e0b4ffbfbc (patch) | |
tree | d1a697417df10bd7b5fc35fa795d20855047c5e9 /odb/object-result.txx | |
parent | 713b3a62d97c6bea7c23597094af6b2439314b8c (diff) |
Support for views; native part
Diffstat (limited to 'odb/object-result.txx')
-rw-r--r-- | odb/object-result.txx | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/odb/object-result.txx b/odb/object-result.txx new file mode 100644 index 0000000..bd4e95e --- /dev/null +++ b/odb/object-result.txx @@ -0,0 +1,91 @@ +// file : odb/object-result.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#include <odb/session.hxx> +#include <odb/cache-traits.hxx> + +namespace odb +{ + // + // result_impl + // + + template <typename T> + result_impl<T, class_object>:: + ~result_impl () + { + } + + template <typename T> + typename result_impl<T, class_object>::pointer_type& + result_impl<T, class_object>:: + current () + { + typedef typename object_traits::pointer_type unrestricted_pointer_type; + typedef typename object_traits::pointer_traits unrestricted_pointer_traits; + + if (pointer_traits::null_ptr (current_) && !end_) + { + if (!session::has_current ()) + { + unrestricted_pointer_type up (object_traits::create ()); + object_type& obj (unrestricted_pointer_traits::get_ref (up)); + current (pointer_type (up)); + load (obj); + } + else + { + // First check the session. + // + const id_type& id (load_id ()); + + pointer_type p ( + pointer_cache_traits<pointer_type>::find (database (), id)); + + if (!pointer_traits::null_ptr (p)) + current (p); + else + { + unrestricted_pointer_type up (object_traits::create ()); + + typename + pointer_cache_traits<unrestricted_pointer_type>::insert_guard ig ( + pointer_cache_traits<unrestricted_pointer_type>::insert ( + database (), id, up)); + + object_type& obj (unrestricted_pointer_traits::get_ref (up)); + current (pointer_type (up)); + load (obj); + ig.release (); + } + } + } + + return current_; + } + + // + // result_iterator + // + + template <typename T> + void result_iterator<T, class_object>:: + load (object_type& obj) + { + if (res_->end ()) + return; + + if (!session::has_current ()) + res_->load (obj); + else + { + typename reference_cache_traits<object_type>::insert_guard ig ( + reference_cache_traits<object_type>::insert ( + res_->database (), res_->load_id (), obj)); + res_->load (obj); + ig.release (); + } + } +} |