From 15dff3c592385466406732cd6ced809dc28cf2e2 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 21 Mar 2018 21:40:28 +0300 Subject: Implement build plan simulation --- bpkg/database.hxx | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'bpkg/database.hxx') 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); -- cgit v1.1