From 531c792dd4eecd246cc1ccebac812d6888464a78 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 22 Nov 2010 12:03:11 +0200 Subject: Add session, database operations on pointers and const objects Currently, session is just an object cache. The persist, update, and erase database operations are overloaded to also work on object pointers. All the database operations and the query facility now support const objects. New session-related exceptions: not_in_session, already_in_session, const_object. --- odb/session.cxx | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 odb/session.cxx (limited to 'odb/session.cxx') diff --git a/odb/session.cxx b/odb/session.cxx new file mode 100644 index 0000000..b34c1d7 --- /dev/null +++ b/odb/session.cxx @@ -0,0 +1,72 @@ +// file : odb/session.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#include +#include + +#include + +namespace odb +{ + using namespace details; + + static ODB_TLS_POINTER (session) current_session; + + session:: + session () + { + if (has_current ()) + throw already_in_session (); + + current (*this); + } + + session:: + ~session () + { + // If we are the current thread's session, reset it. + // + if (has_current () && ¤t () == this) + reset_current (); + } + + bool session:: + has_current () + { + return tls_get (current_session) != 0; + } + + session& session:: + current () + { + session* cur (tls_get (current_session)); + + if (cur == 0) + throw not_in_session (); + + return *cur; + } + + void session:: + current (session& s) + { + tls_set (current_session, &s); + } + + void session:: + reset_current () + { + session* s (0); + tls_set (current_session, s); + } + + // + // object_map_base + // + session::object_map_base:: + ~object_map_base () + { + } +} -- cgit v1.1