aboutsummaryrefslogtreecommitdiff
path: root/common/section/polymorphism/driver.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-08-15 18:27:56 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-08-15 18:27:56 +0200
commitb336e7a1671fdd504759f87bc5ed23fbc7bcf717 (patch)
treeaca74314d2fe8472090d63c93c2f3b9765acd82b /common/section/polymorphism/driver.cxx
parent010997c50d011f7923ce0b820afa4f2d333d69a5 (diff)
Lock object statements when loading sections
Since we use the id image and loading of object pointers can overwrite it.
Diffstat (limited to 'common/section/polymorphism/driver.cxx')
-rw-r--r--common/section/polymorphism/driver.cxx45
1 files changed, 45 insertions, 0 deletions
diff --git a/common/section/polymorphism/driver.cxx b/common/section/polymorphism/driver.cxx
index c9cfee3..d58e850 100644
--- a/common/section/polymorphism/driver.cxx
+++ b/common/section/polymorphism/driver.cxx
@@ -1754,6 +1754,51 @@ main (int argc, char* argv[])
t.commit ();
}
}
+
+#ifdef HAVE_CXX11
+ // Test reuse/polymorphic inheritance and optimistic mix.
+ //
+ {
+ using namespace test9;
+ using std::shared_ptr;
+
+ unsigned long long id;
+
+ {
+ container c (123);
+
+ c.e1.push_back (shared_ptr<element> (new element (11)));
+ c.e1.push_back (shared_ptr<element> (new element (12)));
+
+ c.e2.push_back (shared_ptr<element> (new element (21)));
+ c.e2.push_back (shared_ptr<element> (new element (22)));
+
+ transaction t (db->begin ());
+
+ db->persist (c.e1[0]);
+ db->persist (c.e1[1]);
+ db->persist (c.e2[0]);
+ db->persist (c.e2[1]);
+
+ id = db->persist (c);
+
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+
+ shared_ptr<container> c (db->load<container> (id));
+
+ assert (c->n == 123);
+ db->load (*c, c->s);
+ assert (c->e1.size () == 2 && c->e1[0]->n == 11 && c->e1[1]->n == 12);
+ assert (c->e2.size () == 2 && c->e2[0]->n == 21 && c->e2[1]->n == 22);
+
+ t.commit ();
+ }
+ }
+#endif
}
catch (const odb::exception& e)
{