aboutsummaryrefslogtreecommitdiff
path: root/odb/session.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-11-22 12:03:11 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-11-22 12:03:11 +0200
commit531c792dd4eecd246cc1ccebac812d6888464a78 (patch)
tree9bed050c98a2c407c68e808ae1f1d296a65c5fee /odb/session.cxx
parent1cddfd09a7007f77fc243f178b1ca88ea4d0f4f6 (diff)
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.
Diffstat (limited to 'odb/session.cxx')
-rw-r--r--odb/session.cxx72
1 files changed, 72 insertions, 0 deletions
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 <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#include <odb/exceptions.hxx>
+#include <odb/session.hxx>
+
+#include <odb/details/tls.hxx>
+
+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 () && &current () == 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 ()
+ {
+ }
+}