aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/composite-id/driver.cxx633
-rw-r--r--common/composite-id/makefile108
-rw-r--r--common/composite-id/test.hxx418
-rw-r--r--common/composite-id/test.std0
-rw-r--r--common/makefile1
5 files changed, 1160 insertions, 0 deletions
diff --git a/common/composite-id/driver.cxx b/common/composite-id/driver.cxx
new file mode 100644
index 0000000..3ad71ac
--- /dev/null
+++ b/common/composite-id/driver.cxx
@@ -0,0 +1,633 @@
+// file : common/composite-id/driver.cxx
+// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+// Test composite object ids.
+//
+
+#include <memory> // std::auto_ptr
+#include <cassert>
+#include <iostream>
+
+#include <odb/database.hxx>
+#include <odb/transaction.hxx>
+#include <odb/session.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 1.
+ //
+ {
+ using namespace test1;
+
+ object o1 (scomp ("aaa", "bbb", "ccc"), 123);
+ o1.vec.push_back (scomp ("xxx", "xxx", "xxx"));
+ o1.vec.push_back (scomp ("yyy", "yyy", "yyy"));
+
+ object o2 (scomp ("aaa", "bbb", "ccd"), 234);
+ o2.vec.push_back (scomp ("zzz", "", "zzz"));
+
+ object o3 (scomp ("baa", "bbb", "ccc"), 345);
+
+ // Persist.
+ //
+ {
+ transaction t (db->begin ());
+ db->persist (o1);
+ db->persist (o2);
+ db->persist (o3);
+ t.commit ();
+ }
+
+ // Load.
+ //
+ {
+ transaction t (db->begin ());
+ auto_ptr<object> p1 (db->load<object> (o1.id));
+ auto_ptr<object> p2 (db->load<object> (o2.id));
+ auto_ptr<object> p3 (db->load<object> (o3.id));
+ t.commit ();
+
+ assert (*p1 == o1);
+ assert (*p2 == o2);
+ assert (*p3 == o3);
+ }
+
+ // Update.
+ //
+ {
+ transaction t (db->begin ());
+ auto_ptr<object> p (db->load<object> (o1.id));
+ p->num++;
+ db->update (*p);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ auto_ptr<object> p (db->load<object> (o1.id));
+ t.commit ();
+
+ assert (p->num == o1.num + 1);
+ }
+
+ // Erase.
+ //
+ {
+ transaction t (db->begin ());
+ db->erase<object> (o1.id);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ auto_ptr<object> p (db->find<object> (o1.id));
+ assert (p.get () == 0);
+ t.commit ();
+ }
+ }
+
+ // Test 2.
+ //
+ {
+ using namespace test2;
+
+ object2 o2 (ncomp (2, 0, 1));
+ o2.o1 = new object1 (scomp ("o1", "o2", "aaa"));
+
+ object3 o3 (ncomp (3, 0, 1));
+ o3.o1.push_back (new object1 (scomp ("o1", "o3", "aaa")));
+ o3.o1.push_back (new object1 (scomp ("o1", "o3", "bbb")));
+
+ object4 o4 (ncomp (4, 0, 1));
+ o4.c.o2 = new object2 (ncomp (2, 4, 1));
+ o4.c.o2->o1 = new object1 (scomp ("o1", "o2", "ccc"));
+
+ // Persist.
+ //
+ {
+ transaction t (db->begin ());
+ db->persist (o2.o1);
+ db->persist (o2);
+ db->persist (o3.o1[0]);
+ db->persist (o3.o1[1]);
+ db->persist (o3);
+ db->persist (o4.c.o2->o1);
+ db->persist (o4.c.o2);
+ db->persist (o4);
+ t.commit ();
+ }
+
+ // Load.
+ //
+ {
+ transaction t (db->begin ());
+ auto_ptr<object2> p2 (db->load<object2> (o2.id));
+ auto_ptr<object3> p3 (db->load<object3> (o3.id));
+ auto_ptr<object4> p4 (db->load<object4> (o4.id));
+ t.commit ();
+
+ assert (p2->o1->id == o2.o1->id);
+ assert (p3->o1.size () == o3.o1.size ());
+ assert (p3->o1[0]->id == o3.o1[0]->id);
+ assert (p3->o1[1]->id == o3.o1[1]->id);
+ assert (p4->c.o2->id == o4.c.o2->id);
+ assert (p4->c.o2->o1->id == o4.c.o2->o1->id);
+ }
+
+ // Update.
+ //
+ {
+ scomp id2, id3;
+
+ {
+ transaction t (db->begin ());
+
+ auto_ptr<object2> p2 (db->load<object2> (o2.id));
+ delete p2->o1;
+ p2->o1 = new object1 (scomp ("o1", "o2", "bbb"));
+ id2 = db->persist (p2->o1);
+ db->update (*p2);
+
+ auto_ptr<object3> p3 (db->load<object3> (o3.id));
+ delete p3->o1.back ();
+ p3->o1.pop_back ();
+ p3->o1.push_back (new object1 (scomp ("o1", "o3", "ccc")));
+ id3 = db->persist (p3->o1.back ());
+ db->update (*p3);
+
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ auto_ptr<object2> p2 (db->load<object2> (o2.id));
+ auto_ptr<object3> p3 (db->load<object3> (o3.id));
+ t.commit ();
+
+ assert (p2->o1->id == id2);
+ assert (p3->o1.back ()->id == id3);
+ }
+ }
+
+ // Query.
+ //
+ {
+ {
+ typedef odb::query<object2> query;
+ typedef odb::result<object2> result;
+
+ transaction t (db->begin ());
+
+ {
+ result r (db->query<object2> (query::o1->id.str3 == "bbb"));
+ result::iterator i (r.begin ());
+ assert (i != r.end ());
+ assert (i->id == o2.id);
+ assert (++i == r.end ());
+ }
+
+ {
+ // As id (dual interface).
+ //
+ result r (db->query<object2> (query::o1.str3 == "bbb"));
+ result::iterator i (r.begin ());
+ assert (i != r.end ());
+ assert (i->id == o2.id);
+ assert (++i == r.end ());
+ }
+
+ t.commit ();
+ }
+
+ // Second level composite object pointer.
+ //
+ {
+ typedef odb::query<object4> query;
+ typedef odb::result<object4> result;
+
+ transaction t (db->begin ());
+
+ result r (db->query<object4> (query::c.o2->o1.str3 == "ccc"));
+ result::iterator i (r.begin ());
+ assert (i != r.end ());
+ assert (i->id == o4.id);
+ assert (++i == r.end ());
+
+ t.commit ();
+ }
+ }
+
+ // View.
+ //
+ {
+ transaction t (db->begin ());
+
+ {
+ typedef odb::query<view2> query;
+ typedef odb::result<view2> result;
+
+ result r (db->query<view2> (query::object2::id.num2 == 0));
+ result::iterator i (r.begin ());
+ assert (i != r.end ());
+ assert (i->num == 1 && i->str == "bbb");
+ assert (++i == r.end ());
+ }
+
+ {
+ typedef odb::query<view3> query;
+ typedef odb::result<view3> result;
+
+ result r (db->query<view3> ((query::object3::id.num2 == 0) +
+ "ORDER BY" + query::object1::id.str3));
+ result::iterator i (r.begin ());
+ assert (i != r.end ());
+ assert (i->num == 1 && i->str == "aaa");
+ assert (++i != r.end ());
+ assert (i->num == 1 && i->str == "ccc");
+ assert (++i == r.end ());
+ }
+
+ {
+ typedef odb::query<view4> query;
+ typedef odb::result<view4> result;
+
+ result r (db->query<view4> (query::object4::id.num2 == 0));
+ result::iterator i (r.begin ());
+ assert (i != r.end ());
+ assert (i->num4 == 1 && i->num2 == 1 && i->str == "ccc");
+ assert (++i == r.end ());
+ }
+
+ t.commit ();
+ }
+ }
+
+ // Test 3.
+ //
+ {
+ using namespace test3;
+
+ object2 o2 (ncomp (2, 0, 1));
+ o2.o1 = new object1 (scomp ("o1", "o2", "aaa"));
+ o2.o1->o2 = &o2;
+
+ // Persist.
+ //
+ {
+ transaction t (db->begin ());
+ db->persist (o2.o1);
+ db->persist (o2);
+ t.commit ();
+ }
+
+ // Load.
+ //
+ {
+ session s;
+ transaction t (db->begin ());
+ auto_ptr<object2> p2 (db->load<object2> (o2.id));
+ t.commit ();
+
+ assert (p2->o1->o2->id == o2.id);
+ }
+
+ // Query.
+ //
+ {
+ typedef odb::query<object1> query;
+ typedef odb::result<object1> result;
+
+ transaction t (db->begin ());
+
+ {
+ session s;
+
+ result r (db->query<object1> (query::o2->id.num2 == 0));
+ result::iterator i (r.begin ());
+ assert (i != r.end ());
+ assert (i->id == o2.o1->id);
+
+ i->o2->o1 = 0;
+ delete i->o2;
+
+ assert (++i == r.end ());
+ }
+
+ t.commit ();
+ }
+
+ // View.
+ //
+ {
+ typedef odb::query<view> query;
+ typedef odb::result<view> result;
+
+ transaction t (db->begin ());
+
+ result r (db->query<view> (query::object1::id.str2 == "o2"));
+ result::iterator i (r.begin ());
+ assert (i != r.end ());
+ assert (i->num == 1 && i->str == "aaa");
+ assert (++i == r.end ());
+
+ t.commit ();
+ }
+ }
+
+ // Test 4.
+ //
+ {
+ using namespace test4;
+
+ object2 o2 (ncomp (2, 0, 1));
+
+ o2.o1.push_back (new object1 (scomp ("o1", "o2", "aaa")));
+ o2.o1.back ()->o2 = &o2;
+
+ o2.o1.push_back (new object1 (scomp ("o1", "o2", "bbb")));
+ o2.o1.back ()->o2 = &o2;
+
+ // Persist.
+ //
+ {
+ transaction t (db->begin ());
+ db->persist (o2.o1[0]);
+ db->persist (o2.o1[1]);
+ db->persist (o2);
+ t.commit ();
+ }
+
+ // Load.
+ //
+ {
+ session s;
+ transaction t (db->begin ());
+ auto_ptr<object2> p2 (db->load<object2> (o2.id));
+ t.commit ();
+
+ assert (p2->o1.size () == 2);
+ assert (p2->o1[0]->o2->id == o2.id);
+ assert (p2->o1[1]->o2->id == o2.id);
+ }
+
+ // Query.
+ //
+ {
+ typedef odb::query<object1> query;
+ typedef odb::result<object1> result;
+
+ transaction t (db->begin ());
+
+ {
+ session s;
+
+ result r (db->query<object1> (query::o2->id.num2 == 0));
+ result::iterator i (r.begin ());
+ assert (i != r.end ());
+ assert (i->id == o2.o1[0]->id);
+ i->o2->o1.clear ();
+
+ assert (++i != r.end ());
+ assert (i->id == o2.o1[1]->id);
+
+ i->o2->o1.clear ();
+ delete i->o2;
+
+ assert (++i == r.end ());
+ }
+
+ t.commit ();
+ }
+
+ // View.
+ //
+ {
+ typedef odb::query<view> query;
+ typedef odb::result<view> result;
+
+ transaction t (db->begin ());
+
+ result r (db->query<view> (query::object1::id.str3 == "bbb"));
+ result::iterator i (r.begin ());
+ assert (i != r.end ());
+ assert (i->num == 1 && i->str == "bbb");
+ assert (++i == r.end ());
+
+ t.commit ();
+ }
+ }
+
+ // Test 5.
+ //
+ {
+ using namespace test5;
+
+ object2 o2 (ncomp (2, 0, 1));
+
+ o2.o1.push_back (new object1 (scomp ("o1", "o2", "aaa")));
+ o2.o1.back ()->o2 = &o2;
+
+ o2.o1.push_back (new object1 (scomp ("o1", "o2", "bbb")));
+ o2.o1.back ()->o2 = &o2;
+
+ // Persist.
+ //
+ {
+ transaction t (db->begin ());
+ db->persist (o2.o1[0]);
+ db->persist (o2.o1[1]);
+ db->persist (o2);
+ t.commit ();
+ }
+
+ // Load.
+ //
+ {
+ session s;
+ transaction t (db->begin ());
+ auto_ptr<object2> p2 (db->load<object2> (o2.id));
+ t.commit ();
+
+ assert (p2->o1.size () == 2);
+
+ assert (p2->o1[0]->id == o2.o1[0]->id);
+ assert (p2->o1[0]->o2->id == o2.id);
+
+ assert (p2->o1[1]->id == o2.o1[1]->id);
+ assert (p2->o1[1]->o2->id == o2.id);
+ }
+
+ // View.
+ //
+ {
+ typedef odb::query<view> query;
+ typedef odb::result<view> result;
+
+ transaction t (db->begin ());
+
+ result r (db->query<view> ((query::object2::id.num2 == 0) +
+ "ORDER BY" + query::object1::id.str3));
+ result::iterator i (r.begin ());
+ assert (i != r.end ());
+ assert (i->num == 1 && i->str == "aaa");
+ assert (++i != r.end ());
+ assert (i->num == 1 && i->str == "bbb");
+ assert (++i == r.end ());
+
+ t.commit ();
+ }
+ }
+
+ // Test 6.
+ //
+ {
+ using namespace test6;
+
+ object2 o2 (ncomp (2, 0, 1));
+
+ o2.o1.push_back (new object1 (scomp ("o1", "o2", "aaa")));
+ o2.o1.back ()->o2.push_back (&o2);
+
+ o2.o1.push_back (new object1 (scomp ("o1", "o2", "bbb")));
+ o2.o1.back ()->o2.push_back (&o2);
+
+ // Persist.
+ //
+ {
+ transaction t (db->begin ());
+ db->persist (o2.o1[0]);
+ db->persist (o2.o1[1]);
+ db->persist (o2);
+ t.commit ();
+ }
+
+ // Load.
+ //
+ {
+ session s;
+ transaction t (db->begin ());
+ auto_ptr<object2> p2 (db->load<object2> (o2.id));
+ t.commit ();
+
+ assert (p2->o1.size () == 2);
+
+ assert (p2->o1[0]->id == o2.o1[0]->id);
+ assert (p2->o1[0]->o2[0]->id == o2.id);
+
+ assert (p2->o1[1]->id == o2.o1[1]->id);
+ assert (p2->o1[1]->o2[0]->id == o2.id);
+ }
+
+ // View.
+ //
+ {
+ typedef odb::query<view> query;
+ typedef odb::result<view> result;
+
+ transaction t (db->begin ());
+
+ result r (db->query<view> ((query::object2::id.num2 == 0) +
+ "ORDER BY" + query::object1::id.str3));
+ result::iterator i (r.begin ());
+ assert (i != r.end ());
+ assert (i->num == 1 && i->str == "aaa");
+ assert (++i != r.end ());
+ assert (i->num == 1 && i->str == "bbb");
+ assert (++i == r.end ());
+
+ t.commit ();
+ }
+ }
+
+ // Test 7.
+ //
+ {
+ using namespace test7;
+
+ object o (scomp ("aaa", "bbb", "ccc"), 123);
+
+ // Persist.
+ //
+ {
+ transaction t (db->begin ());
+ db->persist (o);
+ t.commit ();
+ }
+
+ // Load.
+ //
+ {
+ transaction t (db->begin ());
+ auto_ptr<object> p (db->load<object> (o.id));
+ t.commit ();
+
+ assert (*p == o);
+ }
+
+ // Update.
+ //
+ {
+ transaction t (db->begin ());
+ auto_ptr<object> p (db->load<object> (o.id));
+ p->num++;
+ db->update (*p);
+
+ try
+ {
+ db->update (o);
+ assert (false);
+ }
+ catch (const object_changed&)
+ {
+ }
+
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ auto_ptr<object> p (db->load<object> (o.id));
+ t.commit ();
+
+ assert (p->num == o.num + 1);
+ }
+
+ // Erase.
+ //
+ {
+ transaction t (db->begin ());
+
+ try
+ {
+ db->update (o);
+ assert (false);
+ }
+ catch (const object_changed&)
+ {
+ }
+
+ t.commit ();
+ }
+ }
+
+ }
+ catch (const odb::exception& e)
+ {
+ cerr << e.what () << endl;
+ return 1;
+ }
+}
diff --git a/common/composite-id/makefile b/common/composite-id/makefile
new file mode 100644
index 0000000..774b8c7
--- /dev/null
+++ b/common/composite-id/makefile
@@ -0,0 +1,108 @@
+# file : common/composite-id/makefile
+# copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+# license : GNU GPL v2; see accompanying LICENSE file
+
+include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
+
+cxx_tun := driver.cxx
+odb_hdr := test.hxx
+cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o))
+cxx_od := $(cxx_obj:.o=.o.d)
+
+common.l := $(out_root)/libcommon/common/common.l
+common.l.cpp-options := $(out_root)/libcommon/common/common.l.cpp-options
+
+driver := $(out_base)/driver
+dist := $(out_base)/.dist
+test := $(out_base)/.test
+clean := $(out_base)/.clean
+
+# Import.
+#
+$(call import,\
+ $(scf_root)/import/odb/stub.make,\
+ odb: odb,odb-rules: odb_rules)
+
+# Build.
+#
+$(driver): $(cxx_obj) $(common.l)
+$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base)
+$(cxx_obj) $(cxx_od): $(common.l.cpp-options)
+
+genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql)
+gen := $(addprefix $(out_base)/,$(genf))
+
+$(gen): $(odb)
+$(gen): odb := $(odb)
+$(gen) $(dist): export odb_options += --database $(db_id) --generate-schema \
+--generate-query --table-prefix t_comp_id_
+$(gen): cpp_options := -I$(src_base)
+$(gen): $(common.l.cpp-options)
+
+$(call include-dep,$(cxx_od),$(cxx_obj),$(gen))
+
+# Alias for default target.
+#
+$(out_base)/: $(driver)
+
+# Dist
+#
+name := $(subst /,-,$(subst $(src_root)/common/,,$(src_base)))
+
+$(dist): db_id := @database@
+$(dist): sources := $(cxx_tun)
+$(dist): headers := $(odb_hdr)
+$(dist): data_dist := test.std
+$(dist): export name := $(name)
+$(dist): export extra_dist := $(data_dist) $(call vc9projs,$(name)) \
+$(call vc10projs,$(name))
+$(dist):
+ $(call dist-data,$(sources) $(headers) $(data_dist))
+ $(call meta-automake,../template/Makefile.am)
+ $(call meta-vc9projs,../template/template,$(name))
+ $(call meta-vc10projs,../template/template,$(name))
+
+# Test.
+#
+$(test): $(driver) $(src_base)/test.std
+ $(call schema)
+ $(call message,test $<,$< --options-file $(dcf_root)/db.options \
+>$(out_base)/test.out)
+ $(call message,,diff -u $(src_base)/test.std $(out_base)/test.out)
+ $(call message,,rm -f $(out_base)/test.out)
+
+# Clean.
+#
+$(clean): \
+ $(driver).o.clean \
+ $(addsuffix .cxx.clean,$(cxx_obj)) \
+ $(addsuffix .cxx.clean,$(cxx_od)) \
+ $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean))
+ $(call message,,rm -f $(out_base)/test.out)
+
+# Generated .gitignore.
+#
+ifeq ($(out_base),$(src_base))
+$(driver): | $(out_base)/.gitignore
+
+$(out_base)/.gitignore: files := driver $(genf)
+$(clean): $(out_base)/.gitignore.clean
+
+$(call include,$(bld_root)/git/gitignore.make)
+endif
+
+# How to.
+#
+$(call include,$(bld_root)/dist.make)
+$(call include,$(bld_root)/meta/vc9proj.make)
+$(call include,$(bld_root)/meta/vc10proj.make)
+$(call include,$(bld_root)/meta/automake.make)
+
+$(call include,$(odb_rules))
+$(call include,$(bld_root)/cxx/cxx-d.make)
+$(call include,$(bld_root)/cxx/cxx-o.make)
+$(call include,$(bld_root)/cxx/o-e.make)
+
+# Dependencies.
+#
+$(call import,$(src_root)/libcommon/makefile)
diff --git a/common/composite-id/test.hxx b/common/composite-id/test.hxx
new file mode 100644
index 0000000..a5fb375
--- /dev/null
+++ b/common/composite-id/test.hxx
@@ -0,0 +1,418 @@
+// file : common/composite-id/test.hxx
+// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST_HXX
+#define TEST_HXX
+
+#include <string>
+#include <vector>
+
+#include <odb/core.hxx>
+
+#pragma db value
+struct scomp
+{
+ scomp () {}
+ scomp (std::string const& s1, std::string const& s2, std::string const& s3)
+ : str1 (s1), str2 (s2), str3 (s3)
+ {
+ }
+
+ std::string str1;
+ std::string str2;
+ std::string str3;
+};
+
+inline bool
+operator== (const scomp& x, const scomp& y)
+{
+ return x.str1 == y.str1 && x.str2 == y.str2 && x.str3 == y.str3;
+}
+
+//@@ tmp?
+//
+inline bool
+operator< (const scomp& x, const scomp& y)
+{
+ return x.str1 < y.str1 ||
+ (x.str1 == y.str1 && x.str2 < y.str2) ||
+ (x.str1 == y.str1 && x.str2 == y.str2 && x.str3 < y.str3);
+}
+
+#pragma db value
+struct ncomp
+{
+ ncomp () {}
+ ncomp (unsigned short n1, unsigned short n2, unsigned short n3)
+ : num1 (n1), num2 (n2), num3 (n3)
+ {
+ }
+
+ unsigned short num1;
+ unsigned short num2;
+ unsigned short num3;
+};
+
+inline bool
+operator== (const ncomp& x, const ncomp& y)
+{
+ return x.num1 == y.num1 && x.num2 == y.num2 && x.num3 == y.num3;
+}
+
+//@@ tmp?
+//
+inline bool
+operator< (const ncomp& x, const ncomp& y)
+{
+ return x.num1 < y.num1 ||
+ (x.num1 == y.num1 && x.num2 < y.num2) ||
+ (x.num1 == y.num1 && x.num2 == y.num2 && x.num3 < y.num3);
+}
+
+// Test object with composite id, container.
+//
+namespace test1
+{
+ #pragma db object
+ struct object
+ {
+ object () {}
+ object (scomp const& i, unsigned long n): id (i), num (n) {}
+
+ #pragma db id
+ scomp id;
+
+ unsigned long num;
+ std::vector<scomp> vec;
+ };
+
+ inline bool
+ operator== (const object& x, const object& y)
+ {
+ return x.id == y.id && x.num == y.num && x.vec == y.vec;
+ }
+}
+
+// Test to-one and to-many relationships with composite id as well as
+// queries and views.
+//
+namespace test2
+{
+ #pragma db object
+ struct object1
+ {
+ object1 () {}
+ object1 (scomp const& i): id (i) {}
+
+ #pragma db id
+ scomp id;
+ };
+
+ #pragma db object
+ struct object2
+ {
+ object2 (): o1 (0) {}
+ object2 (ncomp const& i): id (i), o1 (0) {}
+ ~object2 () {delete o1;}
+
+ #pragma db id
+ ncomp id;
+
+ object1* o1;
+ };
+
+ #pragma db object
+ struct object3
+ {
+ object3 () {}
+ object3 (ncomp const& i): id (i) {}
+
+ ~object3 ()
+ {
+ for (std::vector<object1*>::iterator i (o1.begin ());
+ i != o1.end (); ++i)
+ delete *i;
+ }
+
+ #pragma db id
+ ncomp id;
+
+ std::vector<object1*> o1;
+ };
+
+ // Test second-level query pointer test as well as pointers in
+ // composite types.
+ //
+ #pragma db value
+ struct comp
+ {
+ comp (): o2 (0) {}
+ ~comp () {delete o2;}
+
+ object2* o2;
+ };
+
+ #pragma db object
+ struct object4
+ {
+ object4 () {}
+ object4 (ncomp const& i): id (i) {}
+
+ #pragma db id
+ ncomp id;
+
+ comp c;
+ };
+
+ #pragma db view object(object2) object(object1)
+ struct view2
+ {
+ #pragma db column (object2::id.num3)
+ unsigned short num;
+
+ #pragma db column (object1::id.str3)
+ std::string str;
+ };
+
+ #pragma db view object(object3) object(object1)
+ struct view3
+ {
+ #pragma db column (object3::id.num3)
+ unsigned short num;
+
+ #pragma db column (object1::id.str3)
+ std::string str;
+ };
+
+ #pragma db view object(object4) object(object2) object(object1)
+ struct view4
+ {
+ #pragma db column (object4::id.num3)
+ unsigned short num4;
+
+ #pragma db column (object2::id.num3)
+ unsigned short num2;
+
+ #pragma db column (object1::id.str3)
+ std::string str;
+ };
+}
+
+// Test one-to-one(i) relationship with composite id.
+//
+namespace test3
+{
+ struct object2;
+
+ #pragma db object table("test3_object1")
+ struct object1
+ {
+ object1 () {}
+ object1 (scomp const& i): id (i) {}
+
+ #pragma db id
+ scomp id;
+
+ #pragma db inverse(o1)
+ object2* o2;
+ };
+
+ #pragma db object table("test3_object2")
+ struct object2
+ {
+ object2 (): o1 (0) {}
+ object2 (ncomp const& i): id (i), o1 (0) {}
+ ~object2 () {delete o1;}
+
+ #pragma db id
+ ncomp id;
+
+ object1* o1;
+ };
+
+ #pragma db view object(object2) object(object1)
+ struct view
+ {
+ #pragma db column (object2::id.num3)
+ unsigned short num;
+
+ #pragma db column (object1::id.str3)
+ std::string str;
+ };
+}
+
+// Test many-to-one(i) relationship with composite id.
+//
+namespace test4
+{
+ struct object2;
+
+ #pragma db object table("test4_object1")
+ struct object1
+ {
+ object1 () {}
+ object1 (scomp const& i): id (i) {}
+
+ #pragma db id
+ scomp id;
+
+ #pragma db inverse(o1)
+ object2* o2;
+ };
+
+ #pragma db object table("test4_object2")
+ struct object2
+ {
+ object2 () {}
+ object2 (ncomp const& i): id (i) {}
+
+ ~object2 ()
+ {
+ for (std::vector<object1*>::iterator i (o1.begin ());
+ i != o1.end (); ++i)
+ delete *i;
+ }
+
+ #pragma db id
+ ncomp id;
+
+ std::vector<object1*> o1;
+ };
+
+ #pragma db view object(object2) object(object1)
+ struct view
+ {
+ #pragma db column (object2::id.num3)
+ unsigned short num;
+
+ #pragma db column (object1::id.str3)
+ std::string str;
+ };
+}
+
+// Test one-to-many(i) relationship with composite id.
+//
+namespace test5
+{
+ struct object2;
+
+ #pragma db object table("test5_object1")
+ struct object1
+ {
+ object1 () {}
+ object1 (scomp const& i): id (i) {}
+
+ #pragma db id
+ scomp id;
+
+ object2* o2;
+ };
+
+ #pragma db object table("test5_object2")
+ struct object2
+ {
+ object2 () {}
+ object2 (ncomp const& i): id (i) {}
+
+ ~object2 ()
+ {
+ for (std::vector<object1*>::iterator i (o1.begin ());
+ i != o1.end (); ++i)
+ delete *i;
+ }
+
+ #pragma db id
+ ncomp id;
+
+ #pragma db inverse(o2)
+ std::vector<object1*> o1;
+ };
+
+ #pragma db view object(object2) object(object1)
+ struct view
+ {
+ #pragma db column (object2::id.num3)
+ unsigned short num;
+
+ #pragma db column (object1::id.str3)
+ std::string str;
+ };
+}
+
+// Test many-to-many(i) relationship with composite id.
+//
+namespace test6
+{
+ struct object2;
+
+ #pragma db object table("test6_object1")
+ struct object1
+ {
+ object1 () {}
+ object1 (scomp const& i): id (i) {}
+
+ #pragma db id
+ scomp id;
+
+ std::vector<object2*> o2;
+ };
+
+ #pragma db object table("test6_object2")
+ struct object2
+ {
+ object2 () {}
+ object2 (ncomp const& i): id (i) {}
+
+ ~object2 ()
+ {
+ for (std::vector<object1*>::iterator i (o1.begin ());
+ i != o1.end (); ++i)
+ delete *i;
+ }
+
+ #pragma db id
+ ncomp id;
+
+ #pragma db inverse(o2)
+ std::vector<object1*> o1;
+ };
+
+ #pragma db view object(object2) object(object1)
+ struct view
+ {
+ #pragma db column (object2::id.num3)
+ unsigned short num;
+
+ #pragma db column (object1::id.str3)
+ std::string str;
+ };
+}
+
+// Test object with composite id and version (optimistic concurrency).
+//
+namespace test7
+{
+ #pragma db object optimistic table("test7_object")
+ struct object
+ {
+ object () {}
+ object (scomp const& i, unsigned long n): id (i), num (n) {}
+
+ #pragma db id
+ scomp id;
+
+ #pragma db version
+ unsigned long ver;
+
+ unsigned long num;
+ };
+
+ inline bool
+ operator== (const object& x, const object& y)
+ {
+ return x.id == y.id && x.ver == y.ver && x.num == y.num ;
+ }
+}
+
+#endif // TEST_HXX
diff --git a/common/composite-id/test.std b/common/composite-id/test.std
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/common/composite-id/test.std
diff --git a/common/makefile b/common/makefile
index e75f66f..80aa030 100644
--- a/common/makefile
+++ b/common/makefile
@@ -9,6 +9,7 @@ auto \
blob \
callback \
composite \
+composite-id \
const-object \
const-member \
container \