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.hxx | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) (limited to 'odb/session.hxx') diff --git a/odb/session.hxx b/odb/session.hxx index 3f58a80..6c9359c 100644 --- a/odb/session.hxx +++ b/odb/session.hxx @@ -42,7 +42,7 @@ namespace odb // thread. // static bool - has_current (); + has_current () {return current_pointer () != 0;} // Get current thread's session. Throw if no session is in effect. // @@ -52,12 +52,18 @@ namespace odb // Set current thread's session. // static void - current (session&); + current (session& s) {current_pointer (&s);} // Revert to the no session in effect state for the current thread. // static void - reset_current (); + reset_current () {current_pointer (0);} + + static session* + current_pointer (); + + static void + current_pointer (session*); // Copying or assignment of sessions is not supported. // @@ -84,7 +90,8 @@ namespace odb public: // Position in the cache of an inserted element. The requirements // for this class template are: default and copy-constructible as - // well as copy-assignable. + // well as copy-assignable. The default constructor creates an + // empty/NULL position. // template struct position @@ -92,35 +99,50 @@ namespace odb typedef object_map map; typedef typename map::iterator iterator; - position () {} + position (): map_ (0) {} position (map& m, const iterator& p): map_ (&m), pos_ (p) {} map* map_; iterator pos_; }; + // The following cache management functions are all static to + // allow for a custom notion of a current session. The erase() + // function is called to remove the object if the operation + // that caused it to be inserted (e.g., load) failed. + // template - position + static position insert (database_type&, const typename object_traits::id_type&, const typename object_traits::pointer_type&); template + static typename object_traits::pointer_type + find (database_type&, const typename object_traits::id_type&); + + template static void - initialize (const position&) {} + erase (const position&); + // Notifications. These are called after per-object callbacks for + // post_{persist, load, update, erase} events. + // template - typename object_traits::pointer_type - find (database_type&, const typename object_traits::id_type&) const; + static void + persist (const position&) {} template - void - erase (database_type&, const typename object_traits::id_type&); + static void + load (const position&) {} template static void - erase (const position&); + update (database_type&, const T&) {} + template + static void + erase (database_type&, const typename object_traits::id_type&); // Low-level object cache access (iteration, etc). // -- cgit v1.1