diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2018-03-21 21:40:28 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2018-04-19 19:39:55 +0300 |
commit | 15dff3c592385466406732cd6ced809dc28cf2e2 (patch) | |
tree | 1da9f0738293eb7906d92ab010a79c689087b655 /bpkg/database.hxx | |
parent | 46842f6cf74d085ced382dd0c187f6a7a578913c (diff) |
Implement build plan simulation
Diffstat (limited to 'bpkg/database.hxx')
-rw-r--r-- | bpkg/database.hxx | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/bpkg/database.hxx b/bpkg/database.hxx index f90aa6b..d97792a 100644 --- a/bpkg/database.hxx +++ b/bpkg/database.hxx @@ -25,7 +25,59 @@ namespace bpkg using odb::session; using odb::sqlite::database; - using odb::sqlite::transaction; + + // Transaction wrapper that allow the creation of dummy transactions (start + // is false) that in reality use an existing transaction. + // + struct transaction + { + using database_type = bpkg::database; + + explicit + transaction (database_type& db, bool start = true) + : db_ (db), start_ (start), t_ () // Finalized. + { + if (start) + t_.reset (db.begin ()); + } + + void + commit () + { + if (start_) + t_.commit (); + } + + void + rollback () + { + if (start_) + t_.rollback (); + } + + database_type& + database () + { + return db_; + } + + static bool + has_current () + { + return odb::sqlite::transaction::has_current (); + } + + static odb::sqlite::transaction& + current () + { + return odb::sqlite::transaction::current (); + } + + private: + database_type& db_; + bool start_; + odb::sqlite::transaction t_; + }; database open (const dir_path& configuration, tracer&, bool create = false); |