aboutsummaryrefslogtreecommitdiff
path: root/common/session/custom/session.hxx
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.hxx
parent856a438b33184959b64864f1afdf5a6a2fd6b0d2 (diff)
Add support for post-commit/rollback callbacks
New test: common/transaction/callback.
Diffstat (limited to 'common/session/custom/session.hxx')
-rw-r--r--common/session/custom/session.hxx27
1 files changed, 17 insertions, 10 deletions
diff --git a/common/session/custom/session.hxx b/common/session/custom/session.hxx
index 3b1789a..ce7e43c 100644
--- a/common/session/custom/session.hxx
+++ b/common/session/custom/session.hxx
@@ -10,6 +10,8 @@
#include <typeinfo>
#include <odb/database.hxx>
+#include <odb/transaction.hxx>
+
#include <odb/traits.hxx> // odb::object_traits
#include <odb/details/type-info.hxx> // odb::details::type_info_comparator
@@ -36,28 +38,26 @@ public:
// Change tracking interface.
//
+public:
// Call flush() within a transaction to apply the changes to the
- // database. Then after successfully committing the transaction,
- // call mark() to mark all the changed objects as again unchanged.
+ // database.
//
-public:
void
flush (odb::database&);
- void
- mark ();
-
private:
struct object_map_base
{
virtual
~object_map_base () {}
- virtual void
+ // Return true we flushed anything.
+ //
+ virtual bool
flush (odb::database&) = 0;
virtual void
- mark () = 0;
+ mark (unsigned short event) = 0;
};
enum object_state
@@ -85,11 +85,11 @@ private:
std::map<typename odb::object_traits<T>::id_type,
object_data<T> >
{
- virtual void
+ virtual bool
flush (odb::database&);
virtual void
- mark ();
+ mark (unsigned short event);
};
// Object cache interface.
@@ -150,10 +150,17 @@ public:
erase (odb::database&, const typename odb::object_traits<T>::id_type&);
private:
+ // Post-commit/rollback callback.
+ //
+ static void
+ mark (unsigned short event, void* key, unsigned long long);
+
+private:
typedef std::map<const std::type_info*,
std::shared_ptr<object_map_base>,
odb::details::type_info_comparator> type_map;
type_map map_;
+ odb::transaction* tran_;
};
#include "session.txx"