aboutsummaryrefslogtreecommitdiff
path: root/common/transaction/driver.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'common/transaction/driver.cxx')
-rw-r--r--common/transaction/driver.cxx140
1 files changed, 77 insertions, 63 deletions
diff --git a/common/transaction/driver.cxx b/common/transaction/driver.cxx
index 64351c3..f785870 100644
--- a/common/transaction/driver.cxx
+++ b/common/transaction/driver.cxx
@@ -48,88 +48,102 @@ struct transaction_tracer: odb::tracer
int
main (int argc, char* argv[])
{
- transaction_tracer tracer;
- auto_ptr<database> db (create_database (argc, argv, false));
- db->tracer (tracer);
-
- assert (!transaction::has_current ());
-
- // Current and db accessors.
- //
- cout << "test 001" << endl;
{
- transaction t (db->begin ());
- assert (&t.database () == db.get ());
- assert (transaction::has_current ());
- assert (&transaction::current () == &t);
+ transaction_tracer tracer;
+ auto_ptr<database> db (create_database (argc, argv, false));
+ db->tracer (tracer);
- transaction::reset_current ();
assert (!transaction::has_current ());
- transaction t2 (db->begin (), false);
- assert (!transaction::has_current ());
+ // Current and db accessors.
+ //
+ cout << "test 001" << endl;
+ {
+ transaction t (db->begin ());
+ assert (&t.database () == db.get ());
+ assert (transaction::has_current ());
+ assert (&transaction::current () == &t);
- transaction::current (t2);
- assert (&transaction::current () == &t2);
- }
+ transaction::reset_current ();
+ assert (!transaction::has_current ());
- // Commit.
- //
- cout << "test 002" << endl;
- {
- transaction t (db->begin ());
- t.commit ();
- }
+ transaction t2 (db->begin (), false);
+ assert (!transaction::has_current ());
- // Rollback.
- //
- cout << "test 003" << endl;
- {
- transaction t (db->begin ());
- t.rollback ();
- }
+ transaction::current (t2);
+ assert (&transaction::current () == &t2);
+ }
- // Auto rollback.
- //
- cout << "test 004" << endl;
- {
- transaction t (db->begin ());
- }
+ // Commit.
+ //
+ cout << "test 002" << endl;
+ {
+ transaction t (db->begin ());
+ t.commit ();
+ }
- // Nested transaction.
- //
- cout << "test 005" << endl;
- {
- transaction t (db->begin ());
+ // Rollback.
+ //
+ cout << "test 003" << endl;
+ {
+ transaction t (db->begin ());
+ t.rollback ();
+ }
- try
+ // Auto rollback.
+ //
+ cout << "test 004" << endl;
{
- transaction n (db->begin ());
+ transaction t (db->begin ());
}
- catch (const already_in_transaction&)
+
+ // Nested transaction.
+ //
+ cout << "test 005" << endl;
{
- cout << "already_in_transaction" << endl;
+ transaction t (db->begin ());
+
+ try
+ {
+ transaction n (db->begin ());
+ }
+ catch (const already_in_transaction&)
+ {
+ cout << "already_in_transaction" << endl;
+ }
}
- }
- // Concrete transaction type.
- //
- cout << "test 006" << endl;
- {
- assert (sizeof (odb_db::transaction) == sizeof (transaction));
+ // Concrete transaction type.
+ //
+ cout << "test 006" << endl;
+ {
+ assert (sizeof (odb_db::transaction) == sizeof (transaction));
- odb_db::transaction t (static_cast<odb_db::database&> (*db).begin ());
- odb_db::transaction& r (odb_db::transaction::current ());
- assert (&t == &r);
+ odb_db::transaction t (static_cast<odb_db::database&> (*db).begin ());
+ odb_db::transaction& r (odb_db::transaction::current ());
+ assert (&t == &r);
+ }
+
+ // Transaction restart.
+ //
+ cout << "test 007" << endl;
+ {
+ transaction t (db->begin ());
+ t.commit ();
+ t.reset (db->begin ());
+ t.commit ();
+ }
}
- // Transaction restart.
+ // Test early connection release.
//
- cout << "test 007" << endl;
{
- transaction t (db->begin ());
- t.commit ();
- t.reset (db->begin ());
- t.commit ();
+ auto_ptr<database> db (create_database (argc, argv, false, 1));
+ transaction t1 (db->begin ());
+ t1.commit ();
+ transaction t2 (db->begin ());
+ t2.rollback ();
+ transaction t3 (db->begin ());
+ t3.commit ();
}
}