From d2c1f5f1a3063553483d09dec261efa44c6bc9bf 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/cache-traits.hxx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'odb/cache-traits.hxx') diff --git a/odb/cache-traits.hxx b/odb/cache-traits.hxx index 13363da..5732cfc 100644 --- a/odb/cache-traits.hxx +++ b/odb/cache-traits.hxx @@ -77,6 +77,13 @@ namespace odb return position_type (); } + static void + initialize (const position_type& p) + { + if (!p.empty_) + session_type::template initialize (p.pos_); + } + static position_type insert (odb::database& db, const pointer_type& p) { @@ -107,7 +114,7 @@ namespace odb erase (const position_type& p) { if (!p.empty_) - session_type::current ().template erase (p.pos_); + session_type::template erase (p.pos_); } }; @@ -154,6 +161,12 @@ namespace odb pointer_type p (&obj); return pointer_traits::insert (db, p); } + + static void + initialize (const position_type& p) + { + pointer_traits::initialize (p); + } }; template -- cgit v1.1