aboutsummaryrefslogtreecommitdiff
path: root/odb/session.hxx
diff options
context:
space:
mode:
Diffstat (limited to 'odb/session.hxx')
-rw-r--r--odb/session.hxx46
1 files changed, 34 insertions, 12 deletions
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 <typename T>
struct position
@@ -92,35 +99,50 @@ namespace odb
typedef object_map<T> 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 <typename T>
- position<T>
+ static position<T>
insert (database_type&,
const typename object_traits<T>::id_type&,
const typename object_traits<T>::pointer_type&);
template <typename T>
+ static typename object_traits<T>::pointer_type
+ find (database_type&, const typename object_traits<T>::id_type&);
+
+ template <typename T>
static void
- initialize (const position<T>&) {}
+ erase (const position<T>&);
+ // Notifications. These are called after per-object callbacks for
+ // post_{persist, load, update, erase} events.
+ //
template <typename T>
- typename object_traits<T>::pointer_type
- find (database_type&, const typename object_traits<T>::id_type&) const;
+ static void
+ persist (const position<T>&) {}
template <typename T>
- void
- erase (database_type&, const typename object_traits<T>::id_type&);
+ static void
+ load (const position<T>&) {}
template <typename T>
static void
- erase (const position<T>&);
+ update (database_type&, const T&) {}
+ template <typename T>
+ static void
+ erase (database_type&, const typename object_traits<T>::id_type&);
// Low-level object cache access (iteration, etc).
//