From 9c275a93cec797a021571ba8545906e0b4ffbfbc Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 5 Sep 2011 10:20:47 +0200 Subject: Support for views; native part --- odb/object-result.txx | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 odb/object-result.txx (limited to 'odb/object-result.txx') 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 +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#include +#include + +namespace odb +{ + // + // result_impl + // + + template + result_impl:: + ~result_impl () + { + } + + template + typename result_impl::pointer_type& + result_impl:: + 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::find (database (), id)); + + if (!pointer_traits::null_ptr (p)) + current (p); + else + { + unrestricted_pointer_type up (object_traits::create ()); + + typename + pointer_cache_traits::insert_guard ig ( + pointer_cache_traits::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 + void result_iterator:: + load (object_type& obj) + { + if (res_->end ()) + return; + + if (!session::has_current ()) + res_->load (obj); + else + { + typename reference_cache_traits::insert_guard ig ( + reference_cache_traits::insert ( + res_->database (), res_->load_id (), obj)); + res_->load (obj); + ig.release (); + } + } +} -- cgit v1.1