From 9381bece0459fab204fceb09349091e838f1e940 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 9 Oct 2014 11:22:05 +0200 Subject: Initial bulk erase implementation --- odb/database.hxx | 10 ++++++++++ odb/database.ixx | 7 +++++++ odb/database.txx | 45 +++++++++++++++++++++++++++++++++++++++++++++ odb/exceptions.hxx | 2 +- 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/odb/database.hxx b/odb/database.hxx index 3ddf914..d399209 100644 --- a/odb/database.hxx +++ b/odb/database.hxx @@ -213,6 +213,16 @@ namespace odb void erase (const typename object_traits::pointer_type& obj_ptr); + // Bulk erase. + // + template + void + erase (I id_begin, I id_end); + + template + void + erase (I obj_begin, I obj_end); + // Erase multiple objects matching a query predicate. // template diff --git a/odb/database.ixx b/odb/database.ixx index d4477e4..9a9b892 100644 --- a/odb/database.ixx +++ b/odb/database.ixx @@ -473,6 +473,13 @@ namespace odb erase_ (pobj); } + template + inline void database:: + erase (I idb, I ide) + { + erase_ (idb, ide); + } + template inline unsigned long long database:: erase_query () diff --git a/odb/database.txx b/odb/database.txx index 8c89394..8003345 100644 --- a/odb/database.txx +++ b/odb/database.txx @@ -279,6 +279,51 @@ namespace odb throw section_not_in_object (); } + template + void database:: + erase_ (I b, I e) + { + // T is explicitly specified by the caller, so assume it is object type. + // + typedef T object_type; + typedef object_traits_impl object_traits; + typedef typename object_traits::id_type id_type; + + multiple_exceptions mex; + try + { + while (b != e) + { + std::size_t n (0); + const id_type* a[object_traits::batch]; + + for (; b != e && n < object_traits::batch; ++n) + // Compiler error pointing here? Perhaps the object id type + // and the sequence element type don't match? + // + a[n] = &(*b++); + + object_traits::erase (*this, a, n, &mex); + + if (mex.fatal ()) + break; + + mex.delta (n); + } + } + catch (const odb::exception& ex) + { + mex.insert (ex, true); + } + + if (!mex.empty ()) + { + mex.prepare (); + throw mex; + } + } + + template struct database::query_ { diff --git a/odb/exceptions.hxx b/odb/exceptions.hxx index 98c92d6..e8ee227 100644 --- a/odb/exceptions.hxx +++ b/odb/exceptions.hxx @@ -366,7 +366,7 @@ namespace odb // don't have an exception has succeeded. The application can try to // correct the errors and re-attempt the operation on the elements // that did cause an exception. In either case, the transactions can - // committed. + // be committed. // bool fatal () const {return fatal_;} -- cgit v1.1