diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2014-10-09 11:22:05 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2014-11-11 10:28:19 +0200 |
commit | 9381bece0459fab204fceb09349091e838f1e940 (patch) | |
tree | 024249b42c83004af8feea521c7a64d1250e6604 | |
parent | ded152cfb675537ab4ce24f50d0e95cec5b83b18 (diff) |
Initial bulk erase implementation
-rw-r--r-- | odb/database.hxx | 10 | ||||
-rw-r--r-- | odb/database.ixx | 7 | ||||
-rw-r--r-- | odb/database.txx | 45 | ||||
-rw-r--r-- | odb/exceptions.hxx | 2 |
4 files changed, 63 insertions, 1 deletions
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<T>::pointer_type& obj_ptr); + // Bulk erase. + // + template <typename T, typename I> + void + erase (I id_begin, I id_end); + + template <typename I> + void + erase (I obj_begin, I obj_end); + // Erase multiple objects matching a query predicate. // template <typename T> 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_<T, id_common> (pobj); } + template <typename T, typename I> + inline void database:: + erase (I idb, I ide) + { + erase_<T, I, id_common> (idb, ide); + } + template <typename T> 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 <typename T, typename I, database_id DB> + 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_type, DB> 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 <typename T, database_id DB> struct database::query_<T, DB, class_object> { 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_;} |