aboutsummaryrefslogtreecommitdiff
path: root/odb/relational/source.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-03-06 11:34:57 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-03-06 11:34:57 +0200
commitf573927d48a7ceb155cf681e7cbad1e5176b2c0b (patch)
tree57fcdf7d0ad8da94af7a5e234c2a0d10cff8cfce /odb/relational/source.hxx
parent96deed4d2ef7d23b6015c1564866b3e60519d57c (diff)
Detect situations where session is required but not used
Throw session_required.
Diffstat (limited to 'odb/relational/source.hxx')
-rw-r--r--odb/relational/source.hxx18
1 files changed, 18 insertions, 0 deletions
diff --git a/odb/relational/source.hxx b/odb/relational/source.hxx
index fb13ade..a8edcf3 100644
--- a/odb/relational/source.hxx
+++ b/odb/relational/source.hxx
@@ -1195,6 +1195,7 @@ namespace relational
if (lazy_pointer (pt))
os << member << " = ptr_traits::pointer_type (*db, id);";
else
+ {
os << "// If a compiler error points to the line below, then" << endl
<< "// it most likely means that a pointer used in a member" << endl
<< "// cannot be initialized from an object pointer." << endl
@@ -1202,6 +1203,23 @@ namespace relational
<< member << " = ptr_traits::pointer_type (" << endl
<< "db->load< obj_traits::object_type > (id));";
+ // If we are loading into an eager weak pointer, make sure there
+ // is someone else holding a strong pointer to it (normally a
+ // session). Otherwise, the object will be loaded and immediately
+ // deleted. Besides not making much sense, this also breaks the
+ // delayed loading machinery which expects the object to be around
+ // at least until the top-level load() returns.
+ //
+ if (weak_pointer (pt))
+ {
+ os << endl
+ << "if (pointer_traits< ptr_traits::strong_pointer_type >" <<
+ "::null_ptr (" << endl
+ << "ptr_traits::lock (" << member << ")))" << endl
+ << "throw session_required ();";
+ }
+ }
+
// @@ Composite value currently cannot be NULL.
//
if (!composite (mi.t))