From f43bfd544372691933e7b5a0bd44ea66eb79266c Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 9 Jan 2013 14:50:26 +0200 Subject: Implement two-phase session insertion On the first step an uninitialized object is inserted into the cache as before (this is necessary to handle recursive loading). The second step is to notify the session that the object has been initialized. On this second step the session can perform change tracking preparations, such as make a copy of the object or reset the modification flag. New test: common/session/custom (implements a custom session that uses copies to track changes). --- odb/relational/source.cxx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/odb/relational/source.cxx b/odb/relational/source.cxx index 58e40e7..4fceb30 100644 --- a/odb/relational/source.cxx +++ b/odb/relational/source.cxx @@ -2006,7 +2006,8 @@ traverse_object (type& c) else os << "callback (db, obj, callback_event::post_load);"; - os << "}" + os << "pointer_cache_traits::initialize (ig.position ());" + << "}" << "else" << endl << rsts << ".delay_load (id, obj, ig.position ()" << (poly ? ", pi.delayed_loader" : "") << ");" @@ -2089,8 +2090,9 @@ traverse_object (type& c) if (delay_freeing_statement_result) os << "auto_result ar (st);"; - os << "reference_cache_traits::insert_guard ig (" << endl + os << "reference_cache_traits::position_type pos (" << endl << "reference_cache_traits::insert (db, id, obj));" + << "reference_cache_traits::insert_guard ig (pos);" << endl << "callback (db, obj, callback_event::pre_load);" << "init (obj, sts.image (), &db);"; @@ -2104,6 +2106,7 @@ traverse_object (type& c) << rsts << ".load_delayed ();" << "l.unlock ();" << "callback (db, obj, callback_event::post_load);" + << "reference_cache_traits::initialize (pos);" << "ig.release ();" << "return true;"; } -- cgit v1.1