aboutsummaryrefslogtreecommitdiff
path: root/common/session/custom/session.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-01-18 10:23:39 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2013-01-18 10:23:39 +0200
commitd304a4b2b19dca115954f209d6a37a6958e73ab9 (patch)
tree0822a40a7d44e7921076b6ad458d29e3ad91c525 /common/session/custom/session.cxx
parent856a438b33184959b64864f1afdf5a6a2fd6b0d2 (diff)
Add support for post-commit/rollback callbacks
New test: common/transaction/callback.
Diffstat (limited to 'common/session/custom/session.cxx')
-rw-r--r--common/session/custom/session.cxx28
1 files changed, 24 insertions, 4 deletions
diff --git a/common/session/custom/session.cxx b/common/session/custom/session.cxx
index f8cd102..0009d79 100644
--- a/common/session/custom/session.cxx
+++ b/common/session/custom/session.cxx
@@ -10,6 +10,7 @@ session* session::current;
session::
session ()
+ : tran_ (0)
{
assert (current == 0);
current = this;
@@ -18,6 +19,11 @@ session ()
session::
~session ()
{
+ // Unregister from transaction.
+ //
+ if (tran_ != 0)
+ tran_->unregister (this);
+
assert (current == this);
current = 0;
}
@@ -25,13 +31,27 @@ session::
void session::
flush (odb::database& db)
{
+ bool flushed (false);
+
for (type_map::iterator i (map_.begin ()), e (map_.end ()); i != e; ++i)
- i->second->flush (db);
+ {
+ 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_->register_ (&mark, this, odb::transaction::event_all, 0, &tran_);
+ }
}
void session::
-mark ()
+mark (unsigned short event, void* key, unsigned long long)
{
- for (type_map::iterator i (map_.begin ()), e (map_.end ()); i != e; ++i)
- i->second->mark ();
+ 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);
}