aboutsummaryrefslogtreecommitdiff
path: root/common/bulk
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2014-11-21 08:16:49 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2014-11-21 08:16:49 +0200
commitb9f83d0d666037b7f7728b674362d365470a244a (patch)
tree6287f592a2ff6ded3b9bfc9298af315c064c2e48 /common/bulk
parent073bee5841f466154bc1fb767cbd23bb0034288e (diff)
Add support for stopping after a failed batch
Diffstat (limited to 'common/bulk')
-rw-r--r--common/bulk/driver.cxx62
-rw-r--r--common/bulk/test.std9
2 files changed, 56 insertions, 15 deletions
diff --git a/common/bulk/driver.cxx b/common/bulk/driver.cxx
index c043931..4b3b9f8 100644
--- a/common/bulk/driver.cxx
+++ b/common/bulk/driver.cxx
@@ -81,7 +81,7 @@ struct element_traits<I, std::unique_ptr<T>>
template <typename I>
void
-persist (const auto_ptr<database>& db, I b, I e)
+persist (const auto_ptr<database>& db, I b, I e, bool cont = true)
{
typedef element_traits<I> traits;
typedef typename traits::type type;
@@ -89,7 +89,7 @@ persist (const auto_ptr<database>& db, I b, I e)
{
transaction t (db->begin ());
- db->persist (b, e);
+ db->persist (b, e, cont);
t.commit ();
}
@@ -111,11 +111,11 @@ persist (const auto_ptr<database>& db, I b, I e)
template <typename I>
void
-try_persist (const auto_ptr<database>& db, I b, I e)
+try_persist (const auto_ptr<database>& db, I b, I e, bool cont = true)
{
try
{
- persist (db, b, e);
+ persist (db, b, e, cont);
assert (false);
}
catch (const multiple_exceptions& e)
@@ -126,7 +126,8 @@ try_persist (const auto_ptr<database>& db, I b, I e)
template <typename I>
void
-update (const auto_ptr<database>& db, I b, I e, bool modify = true)
+update (const auto_ptr<database>& db, I b, I e,
+ bool modify = true, bool cont = true)
{
typedef element_traits<I> traits;
typedef typename traits::type type;
@@ -144,7 +145,7 @@ update (const auto_ptr<database>& db, I b, I e, bool modify = true)
{
transaction t (db->begin ());
- db->update (b, e);
+ db->update (b, e, cont);
t.commit ();
}
@@ -166,11 +167,11 @@ update (const auto_ptr<database>& db, I b, I e, bool modify = true)
template <typename I>
void
-try_update (const auto_ptr<database>& db, I b, I e)
+try_update (const auto_ptr<database>& db, I b, I e, bool cont = true)
{
try
{
- update (db, b, e, false);
+ update (db, b, e, false, cont);
assert (false);
}
catch (const multiple_exceptions& e)
@@ -209,14 +210,14 @@ erase (const auto_ptr<database>& db, I b, I e)
template <typename T, typename I>
void
-erase_id (const auto_ptr<database>& db, I b, I e)
+erase_id (const auto_ptr<database>& db, I b, I e, bool cont = true)
{
typedef element_traits<T*> traits;
typedef T type;
{
transaction t (db->begin ());
- db->erase<T> (b, e);
+ db->erase<T> (b, e, cont);
t.commit ();
}
@@ -234,11 +235,11 @@ erase_id (const auto_ptr<database>& db, I b, I e)
template <typename T, typename A>
void
-try_erase (const auto_ptr<database>& db, const A& a)
+try_erase (const auto_ptr<database>& db, const A& a, bool cont = true)
{
try
{
- erase_id<T> (db, a, a + sizeof (a) / sizeof (a[0]));
+ erase_id<T> (db, a, a + sizeof (a) / sizeof (a[0]), cont);
assert (false);
}
catch (const multiple_exceptions& e)
@@ -589,13 +590,25 @@ main (int argc, char* argv[])
vector<object> v; // mixture
v.push_back (object (0, 0));
v.push_back (object (6, 6));
- v.push_back (object (2, 2));
+ v.push_back (object (1, 1));
v.push_back (object (7, 7));
- v.push_back (object (3, 3));
+ v.push_back (object (2, 2));
v.push_back (object (8, 8));
- v.push_back (object (4, 4));
+ v.push_back (object (3, 3));
try_persist (db, v.begin (), v.end ());
}
+
+ // Test stopping after failure.
+ //
+ {
+ vector<object> v; // batch
+ v.push_back (object (0, 0));
+ v.push_back (object (1, 1));
+ v.push_back (object (6, 6));
+ v.push_back (object (2, 2));
+ v.push_back (object (3, 3));
+ try_persist (db, v.begin (), v.end (), false);
+ }
}
// update
@@ -735,6 +748,18 @@ main (int argc, char* argv[])
try_update (db, v.begin (), v.end ());
}
+ // Test stopping after failure.
+ //
+ {
+ vector<object> v; // batch
+ v.push_back (object (6, 6));
+ v.push_back (object (7, 7));
+ v.push_back (object (0, 0));
+ v.push_back (object (8, 8));
+ v.push_back (object (9, 9));
+ try_update (db, v.begin (), v.end (), false);
+ }
+
// Test a database exception (unique constraint violation)
//
try
@@ -842,6 +867,13 @@ main (int argc, char* argv[])
unsigned long a[] = {0, 1, 2, 6, 7, 8, 3, 4, 5, 9}; // mixture
try_erase<object> (db, a);
}
+
+ // Test stopping after failure.
+ //
+ {
+ unsigned long a[] = {6, 7, 0, 8, 9};
+ try_erase<object> (db, a, false);
+ }
}
erase (db, v.begin (), v.end ());
diff --git a/common/bulk/test.std b/common/bulk/test.std
index 354ad62..6c4bdf9 100644
--- a/common/bulk/test.std
+++ b/common/bulk/test.std
@@ -64,6 +64,9 @@ multiple exceptions, 7 elements attempted, 3 failed:
[3] object already persistent
[5] object already persistent
+multiple exceptions, 3 elements attempted, 1 failed:
+[2] object already persistent
+
multiple exceptions, 1 element attempted, 1 failed:
[0] object not persistent
@@ -131,6 +134,9 @@ multiple exceptions, 7 elements attempted, 4 failed:
[2] object not persistent
[6] object not persistent
+multiple exceptions, 3 elements attempted, 3 failed:
+[0-2] (some) object not persistent
+
multiple exceptions, 1 element attempted, 1 failed:
[0] object not persistent
@@ -207,3 +213,6 @@ multiple exceptions, 10 elements attempted, 6 failed:
[7] object not persistent
[8] object not persistent
+multiple exceptions, 3 elements attempted, 3 failed:
+[0-2] (some) object not persistent
+