From d304a4b2b19dca115954f209d6a37a6958e73ab9 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 18 Jan 2013 10:23:39 +0200 Subject: Add support for post-commit/rollback callbacks New test: common/transaction/callback. --- common/session/custom/session.hxx | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'common/session/custom/session.hxx') 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 #include +#include + #include // odb::object_traits #include // 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::id_type, object_data > { - 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::id_type&); private: + // Post-commit/rollback callback. + // + static void + mark (unsigned short event, void* key, unsigned long long); + +private: typedef std::map, odb::details::type_info_comparator> type_map; type_map map_; + odb::transaction* tran_; }; #include "session.txx" -- cgit v1.1