aboutsummaryrefslogtreecommitdiff
path: root/common/object/driver.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2014-08-01 07:15:19 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2014-08-01 11:06:23 +0200
commit06c7e4520615c9d9d7882fb13be5632a709ad5ac (patch)
treeb40d71ac58585bd7092058a7cacb97968b846d2b /common/object/driver.cxx
parent43e329f4cf9c175960154e395556eca23c170a75 (diff)
Add support for defining persistent objects as class template instantiations
Diffstat (limited to 'common/object/driver.cxx')
-rw-r--r--common/object/driver.cxx83
1 files changed, 83 insertions, 0 deletions
diff --git a/common/object/driver.cxx b/common/object/driver.cxx
new file mode 100644
index 0000000..f3bad0e
--- /dev/null
+++ b/common/object/driver.cxx
@@ -0,0 +1,83 @@
+// file : common/object/driver.cxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+// Test persistent classes.
+//
+
+#include <memory> // std::auto_ptr
+#include <cassert>
+#include <iostream>
+
+#include <odb/database.hxx>
+#include <odb/transaction.hxx>
+
+#include <common/common.hxx>
+
+#include "test.hxx"
+#include "test-odb.hxx"
+
+using namespace std;
+using namespace odb::core;
+
+int
+main (int argc, char* argv[])
+{
+ try
+ {
+ auto_ptr<database> db (create_database (argc, argv));
+
+ // Test persistent class template instantiation.
+ //
+ {
+ using namespace test1;
+
+ pair_object po;
+ po.second = "abc";
+
+ derived d;
+ d.x = "abc";
+ d.n = 123;
+
+ // persist
+ //
+ {
+ transaction t (db->begin ());
+ db->persist<pair_object> (po);
+ db->persist (d);
+ t.commit ();
+ }
+
+ // load & check
+ //
+ {
+ transaction t (db->begin ());
+ auto_ptr<pair_object> po1 (db->load<pair_object> (po.first));
+ auto_ptr<derived> d1 (db->load<derived> (d.id));
+ t.commit ();
+
+ assert (po == *po1);
+
+ assert (d.x == d1->x);
+ assert (d.n == d1->n);
+ }
+
+ // Test the API confusion.
+ //
+ {
+ transaction t (db->begin ());
+ db->update<pair_object> (po);
+ db->reload<pair_object> (po);
+ db->erase<pair_object> (po);
+
+ db->query<pair_object> ();
+ t.commit ();
+ }
+ }
+ }
+ catch (const odb::exception& e)
+ {
+ cerr << e.what () << endl;
+ return 1;
+ }
+}