aboutsummaryrefslogtreecommitdiff
path: root/odb/transaction.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-08-24 13:42:04 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-08-24 13:42:04 +0200
commitf5d79a0cd5dc12a430d17bbdca7ec5aacb45996c (patch)
tree10518f3819b50b78470d3612a36a14580ca1ad11 /odb/transaction.hxx
parent27e362857cf748a54c62b157113cd4abf7eff570 (diff)
Add support for transaction multiplexing
Also delay getting a connection until after we do all the sanity checks (e.g., that there is no active transaction). Otherwise we are running risk of getting blocked rather than throwing an exception.
Diffstat (limited to 'odb/transaction.hxx')
-rw-r--r--odb/transaction.hxx48
1 files changed, 34 insertions, 14 deletions
diff --git a/odb/transaction.hxx b/odb/transaction.hxx
index c2b1f77..0d4f518 100644
--- a/odb/transaction.hxx
+++ b/odb/transaction.hxx
@@ -22,8 +22,11 @@ namespace odb
typedef odb::database database_type;
typedef odb::connection connection_type;
+ // If the second argument is false, then this transaction is not
+ // made the current transaction of the thread.
+ //
explicit
- transaction (transaction_impl*);
+ transaction (transaction_impl*, bool make_current = true);
// Unless the transaction has already been finalized (explicitly
// committed or rolled back), the destructor will roll it back.
@@ -46,16 +49,26 @@ namespace odb
connection_type&
connection ();
+ // Return true if there is a transaction in effect.
+ //
+ static bool
+ has_current ();
+
// Return current transaction or throw if there is no transaction
// in effect.
//
static transaction&
current ();
- // Return true if there is a transaction in effect.
+ // Set the current thread's transaction.
//
- static bool
- has_current ();
+ static void
+ current (transaction&);
+
+ // Revert to the no transaction in effect state for the current thread.
+ //
+ static void
+ reset_current ();
public:
transaction_impl&
@@ -74,21 +87,17 @@ namespace odb
class LIBODB_EXPORT transaction_impl
{
- protected:
- friend class transaction;
-
+ public:
typedef odb::database database_type;
typedef odb::connection connection_type;
- transaction_impl (database_type& db, connection_type& c)
- : database_ (db), connection_ (c)
- {
- }
-
virtual
~transaction_impl ();
virtual void
+ start () = 0;
+
+ virtual void
commit () = 0;
virtual void
@@ -103,12 +112,23 @@ namespace odb
connection_type&
connection ()
{
- return connection_;
+ return *connection_;
+ }
+
+ protected:
+ transaction_impl (database_type& db)
+ : database_ (db), connection_ (0)
+ {
+ }
+
+ transaction_impl (database_type& db, connection_type& c)
+ : database_ (db), connection_ (&c)
+ {
}
protected:
database_type& database_;
- connection_type& connection_;
+ connection_type* connection_;
};
}