diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2012-04-26 16:45:23 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2012-04-26 16:45:23 +0200 |
commit | cb34a6251a08f78d749fb62b1554b43a877d39d1 (patch) | |
tree | 0c9ccdf54d816398462faf2b87ddb123f60b6409 /doc/manual.xhtml | |
parent | 8e046e3ea7e88f872205c2b65cb7f9b86aaabd93 (diff) |
Add database::reset()
Diffstat (limited to 'doc/manual.xhtml')
-rw-r--r-- | doc/manual.xhtml | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/doc/manual.xhtml b/doc/manual.xhtml index 766844f..a969f7f 100644 --- a/doc/manual.xhtml +++ b/doc/manual.xhtml @@ -2590,7 +2590,10 @@ namespace odb typedef odb::database database_type; typedef odb::connection connection_type; - transaction (transaction_impl*, bool make_current = true) + transaction (transaction_impl*, bool make_current = true); + + void + reset (transaction_impl*, bool make_current = true); void commit (); @@ -2622,7 +2625,7 @@ namespace odb <p>The <code>commit()</code> function commits a transaction and <code>rollback()</code> rolls it back. Unless the transaction has been <em>finalized</em>, that is, explicitly committed or rolled - back, the destructor of the <code>odb::transaction</code> class will + back, the destructor of the <code>transaction</code> class will automatically roll it back when the transaction instance goes out of scope. If we try to commit or roll back a finalized transaction, the <code>odb::transaction_already_finalized</code> @@ -2676,6 +2679,34 @@ transaction::current (t2); // Switch to t2. t2.commit (); </pre> + <p>The <code>reset()</code> modifier allows us to reuse the same + <code>transaction</code> instance to complete several database + transactions. Similar to the destructor, <code>reset()</code> + will roll the current transaction back if it hasn't been finalized. + Here is how we can use this function to commit the current transaction + and start a new one every time a certain number of database operations + has been performed:</p> + + <pre class="c++"> +transaction t (db.begin ()); + +for (size_t i (0); i < n; ++i) +{ + // Perform a database operation, such as persist an object. + + // Commit the current transaction and start a new one after + // every 100 operations. + // + if (i % 100 == 0) + { + t.commit (); + t.reset (db.begin ()); + } +} + +t.commit (); + </pre> + <p>Note that in the above discussion of atomicity, consistency, isolation, and durability, all of those guarantees only apply to the object's state in the database as opposed to the object's |