aboutsummaryrefslogtreecommitdiff
path: root/common/session/custom/session.cxx
blob: 6daa8b0e8d72449d39d52c181e98b2af8e89328d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// file      : common/session/custom/session.cxx
// copyright : Copyright (c) 2009-2015 Code Synthesis Tools CC
// 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);
}