aboutsummaryrefslogtreecommitdiff
path: root/common/session/custom/session.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-01-09 14:50:26 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2013-01-16 07:42:56 +0200
commit5cf30ccfe764701f549e4152ad312187221f5285 (patch)
treef3e558a08ab9d2d8fb00855ab1c0ef42d4d9af91 /common/session/custom/session.cxx
parent9bd664e4cb39f6654e8754c8cfd4c28295ee2d90 (diff)
Implement two-phase session insertion
On the first step an uninitialized object is inserted into the cache as before (this is necessary to handle recursive loading). The second step is to notify the session that the object has been initialized. On this second step the session can perform change tracking preparations, such as make a copy of the object or reset the modification flag. New test: common/session/custom (implements a custom session that uses copies to track changes).
Diffstat (limited to 'common/session/custom/session.cxx')
-rw-r--r--common/session/custom/session.cxx50
1 files changed, 50 insertions, 0 deletions
diff --git a/common/session/custom/session.cxx b/common/session/custom/session.cxx
new file mode 100644
index 0000000..b50493f
--- /dev/null
+++ b/common/session/custom/session.cxx
@@ -0,0 +1,50 @@
+// file : common/session/custom/session.cxx
+// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#include <cassert>
+
+#include "session.hxx"
+
+static session* current_; // Use TLS in multi-threaded applications.
+
+session::
+session ()
+{
+ assert (current_ == 0);
+ current_ = this;
+}
+
+session::
+~session ()
+{
+ assert (current_ == this);
+ current_ = 0;
+}
+
+bool session::
+has_current ()
+{
+ return current_ != 0;
+}
+
+session& session::
+current ()
+{
+ assert (current_ != 0);
+ return *current_;
+}
+
+void session::
+flush (odb::database& db)
+{
+ for (type_map::iterator i (map_.begin ()), e (map_.end ()); i != e; ++i)
+ i->second->flush (db);
+}
+
+void session::
+mark ()
+{
+ for (type_map::iterator i (map_.begin ()), e (map_.end ()); i != e; ++i)
+ i->second->mark ();
+}