blob: b0c4d6198bd22c0fe22ea2d42c94cfa17b4d58f5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
// file : odb/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
{
template <typename T>
result_impl<T>::
~result_impl ()
{
}
template <typename T>
typename result_impl<T>::pointer_type& result_impl<T>::
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>::
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 ();
}
}
}
|