aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-12-04 11:30:33 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2013-12-04 11:30:33 +0200
commit4f22837bda784e29f17750c8f1d623b40c1093d4 (patch)
tree136b42d29c180fb52a1327ea61894025770d0f90
parent33a8e17efb8c622413a861047c5c4589a9828f62 (diff)
Implement on_delete pragma for object pointers
Translates to the ON DELETE SQL clause.
-rw-r--r--common/makefile5
-rw-r--r--common/relationship/basics/driver.cxx (renamed from common/relationship/driver.cxx)2
-rw-r--r--common/relationship/basics/makefile (renamed from common/relationship/makefile)6
-rw-r--r--common/relationship/basics/test.hxx (renamed from common/relationship/test.hxx)2
-rw-r--r--common/relationship/basics/test.std (renamed from common/relationship-query/test.std)0
-rw-r--r--common/relationship/on-delete/driver.cxx81
-rw-r--r--common/relationship/on-delete/makefile117
-rw-r--r--common/relationship/on-delete/test.hxx59
-rw-r--r--common/relationship/on-delete/test.std (renamed from common/relationship/test.std)0
-rw-r--r--common/relationship/query/driver.cxx (renamed from common/relationship-query/driver.cxx)2
-rw-r--r--common/relationship/query/makefile (renamed from common/relationship-query/makefile)6
-rw-r--r--common/relationship/query/test.hxx (renamed from common/relationship-query/test.hxx)2
-rw-r--r--common/relationship/query/test.std0
13 files changed, 270 insertions, 12 deletions
diff --git a/common/makefile b/common/makefile
index 1ad2389..8aa48c1 100644
--- a/common/makefile
+++ b/common/makefile
@@ -38,8 +38,9 @@ prepared \
query/basics \
query/array \
readonly \
-relationship \
-relationship-query \
+relationship/basics \
+relationship/on-delete \
+relationship/query \
schema/namespace \
schema/embedded/basics \
schema/embedded/order \
diff --git a/common/relationship/driver.cxx b/common/relationship/basics/driver.cxx
index 127a894..8ad866f 100644
--- a/common/relationship/driver.cxx
+++ b/common/relationship/basics/driver.cxx
@@ -1,4 +1,4 @@
-// file : common/relationship/driver.cxx
+// file : common/relationship/basics/driver.cxx
// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
// license : GNU GPL v2; see accompanying LICENSE file
diff --git a/common/relationship/makefile b/common/relationship/basics/makefile
index 5857ca0..068f60a 100644
--- a/common/relationship/makefile
+++ b/common/relationship/basics/makefile
@@ -1,8 +1,8 @@
-# file : common/relationship/makefile
+# file : common/relationship/basics/makefile
# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
# license : GNU GPL v2; see accompanying LICENSE file
-include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
+include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make
cxx_tun := driver.cxx
odb_hdr := test.hxx
@@ -29,7 +29,7 @@ $(cxx_obj) $(cxx_od): $(common.l.cpp-options)
$(gen): $(odb)
$(gen): odb := $(odb)
$(gen) $(dist): export odb_options += --generate-schema --generate-query \
---table-prefix t_relationship_
+--table-prefix t_rel_basics_
$(gen): cpp_options := -I$(src_base)
$(gen): $(common.l.cpp-options)
diff --git a/common/relationship/test.hxx b/common/relationship/basics/test.hxx
index ecfd6a3..a320c00 100644
--- a/common/relationship/test.hxx
+++ b/common/relationship/basics/test.hxx
@@ -1,4 +1,4 @@
-// file : common/relationship/test.hxx
+// file : common/relationship/basics/test.hxx
// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
// license : GNU GPL v2; see accompanying LICENSE file
diff --git a/common/relationship-query/test.std b/common/relationship/basics/test.std
index e69de29..e69de29 100644
--- a/common/relationship-query/test.std
+++ b/common/relationship/basics/test.std
diff --git a/common/relationship/on-delete/driver.cxx b/common/relationship/on-delete/driver.cxx
new file mode 100644
index 0000000..25b534b
--- /dev/null
+++ b/common/relationship/on-delete/driver.cxx
@@ -0,0 +1,81 @@
+// file : common/relationship/on-delete/driver.cxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+// Test ON DELETE functionality.
+//
+
+#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));
+
+ object o;
+
+ cascade c;
+ c.p = &o;
+
+ cascade_cont cc;
+ cc.p.push_back (&o);
+
+ set_null n;
+ n.p = &o;
+
+ set_null_cont nc;
+ nc.p.push_back (&o);
+
+ {
+ transaction t (db->begin ());
+ db->persist (o);
+ db->persist (c);
+ db->persist (cc);
+ db->persist (n);
+ db->persist (nc);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ db->erase (o);
+ t.commit ();
+ }
+
+ {
+ transaction t (db->begin ());
+ assert (db->find<cascade> (c.id) == 0);
+
+ auto_ptr<cascade_cont> pcc (db->load<cascade_cont> (cc.id));
+ assert (pcc->p.empty ());
+
+ auto_ptr<set_null> pn (db->load<set_null> (n.id));
+ assert (pn->p == 0);
+
+ auto_ptr<set_null_cont> pnc (db->load<set_null_cont> (nc.id));
+ assert (pnc->p.size () == 1 && pnc->p[0] == 0);
+
+ t.commit ();
+ }
+ }
+ catch (const odb::exception& e)
+ {
+ cerr << e.what () << endl;
+ return 1;
+ }
+}
diff --git a/common/relationship/on-delete/makefile b/common/relationship/on-delete/makefile
new file mode 100644
index 0000000..bdda5be
--- /dev/null
+++ b/common/relationship/on-delete/makefile
@@ -0,0 +1,117 @@
+# file : common/relationship/on-delete/makefile
+# copyright : Copyright (c) 2009-2013 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
+genf := $(call odb-gen,$(odb_hdr))
+gen := $(addprefix $(out_base)/,$(genf))
+cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o)) $(filter %.o,$(gen:.cxx=.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
+
+# 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)
+
+$(gen): $(odb)
+$(gen): odb := $(odb)
+$(gen) $(dist): export odb_options += --generate-schema \
+--fkeys-deferrable-mode mysql:not_deferrable \
+--fkeys-deferrable-mode mssql:not_deferrable \
+--table-prefix t_rel_on_d_
+$(gen): cpp_options := -I$(src_base)
+$(gen): $(common.l.cpp-options)
+
+ifneq ($(db_id),common)
+$(gen): odb_options += --database $(db_id)
+else
+$(gen): odb_options += --multi-database dynamic
+endif
+
+$(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): sources := $(cxx_tun)
+$(dist): headers := $(odb_hdr)
+$(dist): data_dist := test.std
+$(dist): export name := $(name)
+$(dist): export extra_dist := $(data_dist) $(call vc8projs,$(name)) \
+$(call vc9projs,$(name)) $(call vc10projs,$(name)) $(call vc11projs,$(name))
+$(dist):
+ $(call dist-data,$(sources) $(headers) $(data_dist))
+ $(call meta-automake,../template/Makefile.am)
+ $(call meta-vc8projs,../template/template,$(name))
+ $(call meta-vc9projs,../template/template,$(name))
+ $(call meta-vc10projs,../template/template,$(name))
+ $(call meta-vc11projs,../template/template,$(name))
+
+# Test.
+#
+ifneq ($(db_id),common)
+$(eval $(call test-rule))
+else
+$(foreach d,$(databases),$(eval $(call test-rule,$d)))
+endif
+
+# Clean.
+#
+$(clean): \
+ $(driver).o.clean \
+ $(addsuffix .cxx.clean,$(cxx_obj)) \
+ $(addsuffix .cxx.clean,$(cxx_od)) \
+ $(addsuffix .hxx.clean,$(filter %.cxx,$(gen)))
+ $(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/vc8proj.make)
+$(call include,$(bld_root)/meta/vc9proj.make)
+$(call include,$(bld_root)/meta/vc10proj.make)
+$(call include,$(bld_root)/meta/vc11proj.make)
+$(call include,$(bld_root)/meta/automake.make)
+
+$(call include,$(bld_root)/cxx/standard.make) # cxx_standard
+ifdef cxx_standard
+$(gen): odb_options += --std $(cxx_standard)
+$(call include,$(odb_rules))
+endif
+
+$(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/relationship/on-delete/test.hxx b/common/relationship/on-delete/test.hxx
new file mode 100644
index 0000000..dba04c3
--- /dev/null
+++ b/common/relationship/on-delete/test.hxx
@@ -0,0 +1,59 @@
+// file : common/relationship/on-delete/test.hxx
+// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST_HXX
+#define TEST_HXX
+
+#include <vector>
+
+#include <odb/core.hxx>
+
+#pragma db object
+struct object
+{
+ #pragma db id auto
+ unsigned long id;
+};
+
+#pragma db object
+struct cascade
+{
+ #pragma db id auto
+ unsigned long id;
+
+ #pragma db on_delete(cascade)
+ object* p;
+};
+
+#pragma db object
+struct cascade_cont
+{
+ #pragma db id auto
+ unsigned long id;
+
+ #pragma db on_delete(cascade)
+ std::vector<object*> p;
+};
+
+#pragma db object
+struct set_null
+{
+ #pragma db id auto
+ unsigned long id;
+
+ #pragma db on_delete(set_null)
+ object* p;
+};
+
+#pragma db object
+struct set_null_cont
+{
+ #pragma db id auto
+ unsigned long id;
+
+ #pragma db on_delete(set_null)
+ std::vector<object*> p;
+};
+
+#endif // TEST_HXX
diff --git a/common/relationship/test.std b/common/relationship/on-delete/test.std
index e69de29..e69de29 100644
--- a/common/relationship/test.std
+++ b/common/relationship/on-delete/test.std
diff --git a/common/relationship-query/driver.cxx b/common/relationship/query/driver.cxx
index 785aa94..2ca05f4 100644
--- a/common/relationship-query/driver.cxx
+++ b/common/relationship/query/driver.cxx
@@ -1,4 +1,4 @@
-// file : common/relationship-query/driver.cxx
+// file : common/relationship-query/query/driver.cxx
// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
// license : GNU GPL v2; see accompanying LICENSE file
diff --git a/common/relationship-query/makefile b/common/relationship/query/makefile
index 14d5e5c..3a43749 100644
--- a/common/relationship-query/makefile
+++ b/common/relationship/query/makefile
@@ -1,8 +1,8 @@
-# file : common/relationship-query/makefile
+# file : common/relationship-query/query/makefile
# copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
# license : GNU GPL v2; see accompanying LICENSE file
-include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make
+include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make
cxx_tun := driver.cxx
odb_hdr := test.hxx
@@ -29,7 +29,7 @@ $(cxx_obj) $(cxx_od): $(common.l.cpp-options)
$(gen): $(odb)
$(gen): odb := $(odb)
$(gen) $(dist): export odb_options += --generate-schema --generate-query \
---generate-session --table-prefix relationship_query_
+--generate-session --table-prefix t_rel_query_
$(gen): cpp_options := -I$(src_base)
$(gen): $(common.l.cpp-options)
diff --git a/common/relationship-query/test.hxx b/common/relationship/query/test.hxx
index b2f9568..3876b27 100644
--- a/common/relationship-query/test.hxx
+++ b/common/relationship/query/test.hxx
@@ -1,4 +1,4 @@
-// file : common/relationship-query/test.hxx
+// file : common/relationship-query/query/test.hxx
// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC
// license : GNU GPL v2; see accompanying LICENSE file
diff --git a/common/relationship/query/test.std b/common/relationship/query/test.std
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/common/relationship/query/test.std