aboutsummaryrefslogtreecommitdiff
path: root/odb
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-01-27 12:31:52 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-01-27 12:31:52 +0200
commitef7dd01920a4a28ba3c4aad3abe69bd43beee9fa (patch)
tree3f61b7faf6db272c9182a523b43c545dd9870020 /odb
parentf8699a40bcc099564f330fd937fa6de36d49c4d8 (diff)
Make container schema override object schema
Diffstat (limited to 'odb')
-rw-r--r--odb/common.cxx11
-rw-r--r--odb/context.cxx102
-rw-r--r--odb/context.hxx11
-rw-r--r--odb/relational/source.hxx13
4 files changed, 91 insertions, 46 deletions
diff --git a/odb/common.cxx b/odb/common.cxx
index fe77b2c..6880964 100644
--- a/odb/common.cxx
+++ b/odb/common.cxx
@@ -119,6 +119,7 @@ traverse (semantics::class_& c)
if (table_prefix_.level == 0)
{
+ table_prefix_.schema = schema (c.scope ());
table_prefix_.prefix = table_name (c);
table_prefix_.prefix += "_";
table_prefix_.level = 1;
@@ -134,6 +135,7 @@ traverse (semantics::class_& c)
{
table_prefix_.level = 0;
table_prefix_.prefix.clear ();
+ table_prefix_.schema.clear ();
}
}
else
@@ -239,8 +241,13 @@ append (semantics::data_member& m, table_prefix& tp)
p = n.qualifier ();
else
{
- p = tp.prefix.qualifier ();
- p.append (n.qualifier ());
+ if (n.qualified ())
+ {
+ p = tp.schema;
+ p.append (n.qualifier ());
+ }
+ else
+ p = tp.prefix.qualifier ();
}
p.append (tp.level <= 1 ? ctx.options.table_prefix () : tp.prefix.uname ());
diff --git a/odb/context.cxx b/odb/context.cxx
index 0d471cd..48d42c7 100644
--- a/odb/context.cxx
+++ b/odb/context.cxx
@@ -561,6 +561,54 @@ composite_ (semantics::class_& c)
}
qname context::
+schema (semantics::scope& s) const
+{
+ if (s.count ("qualified-schema"))
+ return s.get<qname> ("qualified-schema");
+
+ qname r;
+
+ for (semantics::scope* ps (&s);; ps = &ps->scope_ ())
+ {
+ using semantics::namespace_;
+
+ namespace_* ns (dynamic_cast<namespace_*> (ps));
+
+ if (ns == 0)
+ continue; // Some other scope.
+
+ if (ns->extension ())
+ ns = &ns->original ();
+
+ if (ns->count ("schema"))
+ {
+ qname n (ns->get<qname> ("schema"));
+ n.append (r);
+ n.swap (r);
+
+ if (r.fully_qualified ())
+ break;
+ }
+
+ if (ns->global_scope ())
+ break;
+ }
+
+ // If we are still not fully qualified, add the schema that was
+ // specified on the command line.
+ //
+ if (!r.fully_qualified () && options.default_schema_specified ())
+ {
+ qname n (options.default_schema ());
+ n.append (r);
+ n.swap (r);
+ }
+
+ s.set ("qualified-schema", r);
+ return r;
+}
+
+qname context::
table_name (semantics::class_& c) const
{
if (c.count ("qualified-table"))
@@ -596,43 +644,12 @@ table_name (semantics::class_& c) const
}
// Unless we are fully qualified, add any schemas that were
- // specified on the namespaces.
+ // specified on the namespaces and/or with the command line
+ // option.
//
if (!r.fully_qualified ())
{
- for (semantics::scope* s (&c.scope ());; s = &s->scope_ ())
- {
- using semantics::namespace_;
-
- namespace_* ns (dynamic_cast<namespace_*> (s));
-
- if (ns == 0)
- continue; // Some other scope.
-
- if (ns->extension ())
- ns = &ns->original ();
-
- if (ns->count ("schema"))
- {
- qname n (ns->get<qname> ("schema"));
- n.append (r);
- n.swap (r);
-
- if (r.fully_qualified ())
- break;
- }
-
- if (ns->global_scope ())
- break;
- }
- }
-
- // Finally, if we are still not fully qualified, add the schema
- // that was specified on the command line.
- //
- if (!r.fully_qualified () && options.default_schema_specified ())
- {
- qname n (options.default_schema ());
+ qname n (schema (c.scope ()));
n.append (r);
n.swap (r);
}
@@ -649,7 +666,7 @@ table_name (semantics::class_& c) const
qname context::
table_name (semantics::class_& obj, data_member_path const& mp) const
{
- table_prefix tp (table_name (obj) + "_", 1);
+ table_prefix tp (schema (obj.scope ()), table_name (obj) + "_", 1);
if (mp.size () == 1)
{
@@ -683,8 +700,10 @@ table_name (semantics::data_member& m, table_prefix const& p) const
// If a custom table name was specified, then ignore the top-level
// table prefix (this corresponds to a container directly inside an
- // object) but keep the schema unless the container table is fully
- // qualified.
+ // object). If the container table is unqualifed, then we use the
+ // object schema. If it is fully qualified, then we use that name.
+ // Finally, if it is qualified by not fully qualifed, then we
+ // append the object's namespace schema.
//
if (m.count ("table"))
{
@@ -694,8 +713,13 @@ table_name (semantics::data_member& m, table_prefix const& p) const
r = n.qualifier ();
else
{
- r = p.prefix.qualifier ();
- r.append (n.qualifier ());
+ if (n.qualified ())
+ {
+ r = p.schema;
+ r.append (n.qualifier ());
+ }
+ else
+ r = p.prefix.qualifier ();
}
r.append (p.level == 1 ? gp : p.prefix.uname ());
diff --git a/odb/context.hxx b/odb/context.hxx
index c63115a..425e9de 100644
--- a/odb/context.hxx
+++ b/odb/context.hxx
@@ -458,6 +458,13 @@ public:
// Database names and types.
//
public:
+ // Schema name for a namespace.
+ //
+ qname
+ schema (semantics::scope&) const;
+
+ //
+ //
qname
table_name (semantics::class_&) const;
@@ -467,8 +474,10 @@ public:
struct table_prefix
{
table_prefix (): level (0) {}
- table_prefix (qname const& p, size_t l): prefix (p), level (l) {}
+ table_prefix (qname const& s, qname const& p, size_t l)
+ : schema (s), prefix (p), level (l) {}
+ qname schema; // Object's namespace schema.
qname prefix;
size_t level;
};
diff --git a/odb/relational/source.hxx b/odb/relational/source.hxx
index 05693bf..a75830b 100644
--- a/odb/relational/source.hxx
+++ b/odb/relational/source.hxx
@@ -120,7 +120,10 @@ namespace relational
"id",
table_name_.empty ()
? table_name_
- : table_qname (*im, table_prefix (table_name (*c) + "_", 1)),
+ : table_qname (*im,
+ table_prefix (schema (c->scope ()),
+ table_name (*c) + "_",
+ 1)),
column_qname (*im, "id", "object_id"));
}
else
@@ -416,7 +419,7 @@ namespace relational
// prefix is just the class table name.
//
qname const& ct (table_name (*c));
- table_prefix tp (ct + "_", 1);
+ table_prefix tp (schema (c->scope ()), ct + "_", 1);
t = table_qname (*im, tp);
string const& val (column_qname (*im, "value", "value"));
@@ -952,7 +955,7 @@ namespace relational
// This other container is a direct member of the class so the
// table prefix is just the class table name.
//
- table_prefix tp (table_name (*c) + "_", 1);
+ table_prefix tp (schema (c->scope ()), table_name (*c) + "_", 1);
inv_table = table_qname (*im, tp);
inv_id = column_qname (*im, "id", "object_id");
inv_fid = column_qname (*im, "value", "value");
@@ -4082,7 +4085,9 @@ namespace relational
// function would have to return a member path instead
// of just a single member.
//
- table_prefix tp (table_name (*vo->obj) + "_", 1);
+ table_prefix tp (context::schema (vo->obj->scope ()),
+ table_name (*vo->obj) + "_",
+ 1);
ct = table_qname (*im, tp);
}
else