From e3dafcdf8b43880c6a1e0451c8ee621f7c3cb954 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 16 Jan 2013 16:31:29 +0200 Subject: Make session cache management functions static, add notifications --- odb/session.txx | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'odb/session.txx') diff --git a/odb/session.txx b/odb/session.txx index 941f059..e89e439 100644 --- a/odb/session.txx +++ b/odb/session.txx @@ -12,7 +12,11 @@ namespace odb { typedef odb::object_traits object_traits; - type_map& tm (db_map_[&db]); + session* s (current_pointer ()); + if (s == 0) + return position (); + + type_map& tm (s->db_map_[&db]); details::shared_ptr& pom (tm[&typeid (T)]); if (!pom) @@ -36,13 +40,17 @@ namespace odb template typename object_traits::pointer_type session:: - find (database_type& db, const typename object_traits::id_type& id) const + find (database_type& db, const typename object_traits::id_type& id) { typedef typename object_traits::pointer_type pointer_type; - database_map::const_iterator di (db_map_.find (&db)); + const session* s (current_pointer ()); + if (s == 0) + return pointer_type (); + + database_map::const_iterator di (s->db_map_.find (&db)); - if (di == db_map_.end ()) + if (di == s->db_map_.end ()) return pointer_type (); const type_map& tm (di->second); @@ -64,9 +72,13 @@ namespace odb void session:: erase (database_type& db, const typename object_traits::id_type& id) { - database_map::iterator di (db_map_.find (&db)); + session* s (current_pointer ()); + if (s == 0) + return; + + database_map::iterator di (s->db_map_.find (&db)); - if (di == db_map_.end ()) + if (di == s->db_map_.end ()) return; type_map& tm (di->second); @@ -87,6 +99,6 @@ namespace odb tm.erase (ti); if (tm.empty ()) - db_map_.erase (di); + s->db_map_.erase (di); } } -- cgit v1.1