summaryrefslogtreecommitdiff
path: root/odb-tests/common/session/custom/session.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2024-01-25 20:32:06 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2024-01-25 20:32:06 +0300
commit0d49ea1fe08cf1eab41a00149393a291c65a59d7 (patch)
tree0391eb09309ca95282e200516937e64d89f3e1bb /odb-tests/common/session/custom/session.cxx
parentfc3fb39c90ab7fe5fccbe3f3bc0eb2645157bb96 (diff)
Turn odb-tests repository into package for muti-package repositoryodb-tests
Diffstat (limited to 'odb-tests/common/session/custom/session.cxx')
-rw-r--r--odb-tests/common/session/custom/session.cxx57
1 files changed, 57 insertions, 0 deletions
diff --git a/odb-tests/common/session/custom/session.cxx b/odb-tests/common/session/custom/session.cxx
new file mode 100644
index 0000000..1a08c79
--- /dev/null
+++ b/odb-tests/common/session/custom/session.cxx
@@ -0,0 +1,57 @@
+// file : common/session/custom/session.cxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#include <cassert>
+
+#include "session.hxx"
+
+session* session::current;
+
+session::
+session ()
+ : tran_ (0)
+{
+ assert (current == 0);
+ current = this;
+}
+
+session::
+~session ()
+{
+ // Unregister from transaction.
+ //
+ if (tran_ != 0)
+ tran_->callback_unregister (this);
+
+ assert (current == this);
+ current = 0;
+}
+
+void session::
+flush (odb::database& db)
+{
+ bool flushed (false);
+
+ for (type_map::iterator i (map_.begin ()), e (map_.end ()); i != e; ++i)
+ {
+ bool r (i->second->flush (db));
+ flushed = flushed || r;
+ }
+
+ // If we flushed anything, then register the post-commit/rollback callback.
+ //
+ if (flushed)
+ {
+ tran_ = &odb::transaction::current ();
+ tran_->callback_register (
+ &mark, this, odb::transaction::event_all, 0, &tran_);
+ }
+}
+
+void session::
+mark (unsigned short event, void* key, unsigned long long)
+{
+ session& s (*static_cast<session*> (key));
+ for (type_map::iterator i (s.map_.begin ()), e (s.map_.end ()); i != e; ++i)
+ i->second->mark (event);
+}