diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2012-10-15 13:17:31 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2012-10-19 11:41:11 +0200 |
commit | fe82ef79b9276e76b50eaf8fc1cc38646a84d49a (patch) | |
tree | 072d39a4e85eedefd6474a0e1bf55f49f873ece7 | |
parent | 52c34521dcb4778713b922442222cc0e5e413b71 (diff) |
Implement early connection release
-rw-r--r-- | common/threads/driver.cxx | 6 | ||||
-rw-r--r-- | common/transaction/driver.cxx | 140 |
2 files changed, 77 insertions, 69 deletions
diff --git a/common/threads/driver.cxx b/common/threads/driver.cxx index b8a66f1..3f7f171 100644 --- a/common/threads/driver.cxx +++ b/common/threads/driver.cxx @@ -101,10 +101,6 @@ struct task transaction t (db_.begin ()); - { // @@ TMP - - //result r (db_.query<object> (query::str == "another value", false)); - prep_query pq (db_.lookup_query<object> ("object-query")); if (!pq) @@ -127,8 +123,6 @@ struct task } assert (found); - } // @@ TMP - t.commit (); } 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 (); } } |