aboutsummaryrefslogtreecommitdiff
path: root/odb/traversal
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-10-24 16:32:51 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-10-24 16:32:51 +0200
commit08a47c70ad517b80b72914d47d547463f576bcd3 (patch)
tree8a6ab07cf05e8668ea3c91735dfe97e2a98f3f05 /odb/traversal
parenta976183dc95a8b7a9bd7a308c3ea94f08982c426 (diff)
Generate database schema from database model instead of C++ model
We now first create the so-called database model from C++ model and then use that to generate the database schema. The new approach also adds more general support for primary/foreign keys, including multi- column keys. Finally, for MySQL we now generate out-of-line foreign key definitions. Because MySQL does not support deferred constraints checking, deferred foreign keys are written commented out, for documentation.
Diffstat (limited to 'odb/traversal')
-rw-r--r--odb/traversal/relational.hxx18
-rw-r--r--odb/traversal/relational/column.hxx20
-rw-r--r--odb/traversal/relational/elements.cxx18
-rw-r--r--odb/traversal/relational/elements.hxx147
-rw-r--r--odb/traversal/relational/foreign-key.hxx20
-rw-r--r--odb/traversal/relational/index.hxx20
-rw-r--r--odb/traversal/relational/key.hxx43
-rw-r--r--odb/traversal/relational/model.hxx20
-rw-r--r--odb/traversal/relational/primary-key.hxx20
-rw-r--r--odb/traversal/relational/table.hxx22
10 files changed, 348 insertions, 0 deletions
diff --git a/odb/traversal/relational.hxx b/odb/traversal/relational.hxx
new file mode 100644
index 0000000..1e0d9e6
--- /dev/null
+++ b/odb/traversal/relational.hxx
@@ -0,0 +1,18 @@
+// file : odb/traversal/relational.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v3; see accompanying LICENSE file
+
+#ifndef ODB_TRAVERSAL_RELATIONAL_HXX
+#define ODB_TRAVERSAL_RELATIONAL_HXX
+
+#include <odb/traversal/relational/column.hxx>
+#include <odb/traversal/relational/elements.hxx>
+#include <odb/traversal/relational/foreign-key.hxx>
+#include <odb/traversal/relational/index.hxx>
+#include <odb/traversal/relational/key.hxx>
+#include <odb/traversal/relational/model.hxx>
+#include <odb/traversal/relational/primary-key.hxx>
+#include <odb/traversal/relational/table.hxx>
+
+#endif // ODB_TRAVERSAL_RELATIONAL_HXX
diff --git a/odb/traversal/relational/column.hxx b/odb/traversal/relational/column.hxx
new file mode 100644
index 0000000..20c8716
--- /dev/null
+++ b/odb/traversal/relational/column.hxx
@@ -0,0 +1,20 @@
+// file : odb/traversal/relational/column.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v3; see accompanying LICENSE file
+
+#ifndef ODB_TRAVERSAL_RELATIONAL_COLUMN_HXX
+#define ODB_TRAVERSAL_RELATIONAL_COLUMN_HXX
+
+#include <odb/semantics/relational/column.hxx>
+#include <odb/traversal/relational/elements.hxx>
+
+namespace traversal
+{
+ namespace relational
+ {
+ struct column: node<semantics::relational::column> {};
+ }
+}
+
+#endif // ODB_TRAVERSAL_RELATIONAL_COLUMN_HXX
diff --git a/odb/traversal/relational/elements.cxx b/odb/traversal/relational/elements.cxx
new file mode 100644
index 0000000..de9c259
--- /dev/null
+++ b/odb/traversal/relational/elements.cxx
@@ -0,0 +1,18 @@
+// file : odb/traversal/relational/elements.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v3; see accompanying LICENSE file
+
+#include <odb/traversal/relational/elements.hxx>
+
+namespace traversal
+{
+ namespace relational
+ {
+ void names::
+ traverse (type& e)
+ {
+ dispatch (e.nameable ());
+ }
+ }
+}
diff --git a/odb/traversal/relational/elements.hxx b/odb/traversal/relational/elements.hxx
new file mode 100644
index 0000000..72b8c39
--- /dev/null
+++ b/odb/traversal/relational/elements.hxx
@@ -0,0 +1,147 @@
+// file : odb/traversal/relational/elements.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v3; see accompanying LICENSE file
+
+#ifndef ODB_TRAVERSAL_RELATIONAL_ELEMENTS_HXX
+#define ODB_TRAVERSAL_RELATIONAL_ELEMENTS_HXX
+
+#include <cutl/compiler/traversal.hxx>
+#include <odb/semantics/relational/elements.hxx>
+
+namespace traversal
+{
+ namespace relational
+ {
+ using namespace cutl;
+
+ //
+ //
+ typedef compiler::dispatcher<semantics::relational::node> node_dispatcher;
+ typedef compiler::dispatcher<semantics::relational::edge> edge_dispatcher;
+
+ //
+ //
+ struct node_base: node_dispatcher, edge_dispatcher
+ {
+ void
+ edge_traverser (edge_dispatcher& d)
+ {
+ edge_dispatcher::traverser (d);
+ }
+
+ edge_dispatcher&
+ edge_traverser ()
+ {
+ return *this;
+ }
+
+ using node_dispatcher::dispatch;
+ using edge_dispatcher::dispatch;
+
+ using edge_dispatcher::iterate_and_dispatch;
+ };
+
+ struct edge_base: edge_dispatcher, node_dispatcher
+ {
+ void
+ node_traverser (node_dispatcher& d)
+ {
+ node_dispatcher::traverser (d);
+ }
+
+ node_dispatcher&
+ node_traverser ()
+ {
+ return *this;
+ }
+
+ using edge_dispatcher::dispatch;
+ using node_dispatcher::dispatch;
+
+ using node_dispatcher::iterate_and_dispatch;
+ };
+
+ inline edge_base&
+ operator>> (node_base& n, edge_base& e)
+ {
+ n.edge_traverser (e);
+ return e;
+ }
+
+ inline node_base&
+ operator>> (edge_base& e, node_base& n)
+ {
+ e.node_traverser (n);
+ return n;
+ }
+
+ //
+ //
+ template <typename X>
+ struct node: compiler::traverser_impl<X, semantics::relational::node>,
+ virtual node_base
+ {
+ };
+
+ template <typename X>
+ struct edge: compiler::traverser_impl<X, semantics::relational::edge>,
+ virtual edge_base
+ {
+ };
+
+ //
+ // Edges
+ //
+
+ struct names: edge<semantics::relational::names>
+ {
+ names ()
+ {
+ }
+
+ names (node_dispatcher& n)
+ {
+ node_traverser (n);
+ }
+
+ virtual void
+ traverse (type&);
+ };
+
+ //
+ // Nodes
+ //
+
+ struct nameable: node<semantics::relational::nameable> {};
+
+ //
+ //
+ template <typename T>
+ struct scope_template: node<T>
+ {
+ public:
+ virtual void
+ traverse (T& s)
+ {
+ names (s);
+ }
+
+ virtual void
+ names (T& s)
+ {
+ names (s, *this);
+ }
+
+ virtual void
+ names (T& s, edge_dispatcher& d)
+ {
+ iterate_and_dispatch (s.names_begin (), s.names_end (), d);
+ }
+ };
+
+ struct scope: scope_template<semantics::relational::scope> {};
+ }
+}
+
+#endif // ODB_TRAVERSAL_RELATIONAL_ELEMENTS_HXX
diff --git a/odb/traversal/relational/foreign-key.hxx b/odb/traversal/relational/foreign-key.hxx
new file mode 100644
index 0000000..dc9b87e
--- /dev/null
+++ b/odb/traversal/relational/foreign-key.hxx
@@ -0,0 +1,20 @@
+// file : odb/traversal/relational/foreign-key.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v3; see accompanying LICENSE file
+
+#ifndef ODB_TRAVERSAL_RELATIONAL_FOREIGN_KEY_HXX
+#define ODB_TRAVERSAL_RELATIONAL_FOREIGN_KEY_HXX
+
+#include <odb/semantics/relational/foreign-key.hxx>
+#include <odb/traversal/relational/key.hxx>
+
+namespace traversal
+{
+ namespace relational
+ {
+ struct foreign_key: key_template<semantics::relational::foreign_key> {};
+ }
+}
+
+#endif // ODB_TRAVERSAL_RELATIONAL_FOREIGN_KEY_HXX
diff --git a/odb/traversal/relational/index.hxx b/odb/traversal/relational/index.hxx
new file mode 100644
index 0000000..20a8bc5
--- /dev/null
+++ b/odb/traversal/relational/index.hxx
@@ -0,0 +1,20 @@
+// file : odb/traversal/relational/index.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v3; see accompanying LICENSE file
+
+#ifndef ODB_TRAVERSAL_RELATIONAL_INDEX_HXX
+#define ODB_TRAVERSAL_RELATIONAL_INDEX_HXX
+
+#include <odb/semantics/relational/index.hxx>
+#include <odb/traversal/relational/key.hxx>
+
+namespace traversal
+{
+ namespace relational
+ {
+ struct index: key_template<semantics::relational::index> {};
+ }
+}
+
+#endif // ODB_TRAVERSAL_RELATIONAL_INDEX_HXX
diff --git a/odb/traversal/relational/key.hxx b/odb/traversal/relational/key.hxx
new file mode 100644
index 0000000..ae2487d
--- /dev/null
+++ b/odb/traversal/relational/key.hxx
@@ -0,0 +1,43 @@
+// file : odb/traversal/relational/key.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v3; see accompanying LICENSE file
+
+#ifndef ODB_TRAVERSAL_RELATIONAL_KEY_HXX
+#define ODB_TRAVERSAL_RELATIONAL_KEY_HXX
+
+#include <odb/semantics/relational/key.hxx>
+#include <odb/traversal/relational/elements.hxx>
+
+namespace traversal
+{
+ namespace relational
+ {
+ template <typename T>
+ struct key_template: node<T>
+ {
+ public:
+ virtual void
+ traverse (T& k)
+ {
+ contains (k);
+ }
+
+ virtual void
+ contains (T& k)
+ {
+ contains (k, *this);
+ }
+
+ virtual void
+ contains (T& k, edge_dispatcher& d)
+ {
+ iterate_and_dispatch (k.contains_begin (), k.contains_end (), d);
+ }
+ };
+
+ struct key: key_template<semantics::relational::key> {};
+ }
+}
+
+#endif // ODB_TRAVERSAL_RELATIONAL_KEY_HXX
diff --git a/odb/traversal/relational/model.hxx b/odb/traversal/relational/model.hxx
new file mode 100644
index 0000000..6c120f6
--- /dev/null
+++ b/odb/traversal/relational/model.hxx
@@ -0,0 +1,20 @@
+// file : odb/traversal/relational/model.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v3; see accompanying LICENSE file
+
+#ifndef ODB_TRAVERSAL_RELATIONAL_MODEL_HXX
+#define ODB_TRAVERSAL_RELATIONAL_MODEL_HXX
+
+#include <odb/semantics/relational/model.hxx>
+#include <odb/traversal/relational/elements.hxx>
+
+namespace traversal
+{
+ namespace relational
+ {
+ struct model: scope_template<semantics::relational::model> {};
+ }
+}
+
+#endif // ODB_TRAVERSAL_RELATIONAL_MODEL_HXX
diff --git a/odb/traversal/relational/primary-key.hxx b/odb/traversal/relational/primary-key.hxx
new file mode 100644
index 0000000..6374e4c
--- /dev/null
+++ b/odb/traversal/relational/primary-key.hxx
@@ -0,0 +1,20 @@
+// file : odb/traversal/relational/primary-key.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v3; see accompanying LICENSE file
+
+#ifndef ODB_TRAVERSAL_RELATIONAL_PRIMARY_KEY_HXX
+#define ODB_TRAVERSAL_RELATIONAL_PRIMARY_KEY_HXX
+
+#include <odb/semantics/relational/primary-key.hxx>
+#include <odb/traversal/relational/key.hxx>
+
+namespace traversal
+{
+ namespace relational
+ {
+ struct primary_key: key_template<semantics::relational::primary_key> {};
+ }
+}
+
+#endif // ODB_TRAVERSAL_RELATIONAL_PRIMARY_KEY_HXX
diff --git a/odb/traversal/relational/table.hxx b/odb/traversal/relational/table.hxx
new file mode 100644
index 0000000..28783b1
--- /dev/null
+++ b/odb/traversal/relational/table.hxx
@@ -0,0 +1,22 @@
+// file : odb/traversal/relational/table.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v3; see accompanying LICENSE file
+
+#ifndef ODB_TRAVERSAL_RELATIONAL_TABLE_HXX
+#define ODB_TRAVERSAL_RELATIONAL_TABLE_HXX
+
+#include <odb/semantics/relational/table.hxx>
+#include <odb/traversal/relational/elements.hxx>
+
+namespace traversal
+{
+ namespace relational
+ {
+ struct table: scope_template<semantics::relational::table> {};
+ struct object_table: scope_template<semantics::relational::table> {};
+ struct container_table: scope_template<semantics::relational::table> {};
+ }
+}
+
+#endif // ODB_TRAVERSAL_RELATIONAL_TABLE_HXX