aboutsummaryrefslogtreecommitdiff
path: root/odb
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2014-11-14 16:24:50 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2014-11-14 16:24:50 +0200
commit4bf55482207ee5807907833829dc30af2d18770b (patch)
tree063c5f1142cc5a3d0d9c2824241801d3e5203bea /odb
parent5c836364144998dcd2d798f6bc404b0f0efddf5c (diff)
Old interface compatibility and testing fixes
Now all tests pass for both Oracle and SQL Server.
Diffstat (limited to 'odb')
-rw-r--r--odb/relational/header.hxx2
-rw-r--r--odb/relational/mssql/header.cxx29
-rw-r--r--odb/relational/mssql/source.cxx57
-rw-r--r--odb/relational/oracle/header.cxx22
-rw-r--r--odb/relational/source.cxx32
-rw-r--r--odb/relational/source.hxx11
6 files changed, 144 insertions, 9 deletions
diff --git a/odb/relational/header.hxx b/odb/relational/header.hxx
index 0af9109..7a36d0e 100644
--- a/odb/relational/header.hxx
+++ b/odb/relational/header.hxx
@@ -995,6 +995,8 @@ namespace relational
os << "typedef object_traits_impl<object_type, id_" << db <<
">::image_type image_type;"
+ << "typedef object_traits_impl<object_type, id_" << db <<
+ ">::id_image_type id_image_type;"
<< endl;
section_public_extra_pre (s);
diff --git a/odb/relational/mssql/header.cxx b/odb/relational/mssql/header.cxx
index f943a8a..40b6828 100644
--- a/odb/relational/mssql/header.cxx
+++ b/odb/relational/mssql/header.cxx
@@ -31,6 +31,11 @@ namespace relational
if (poly_derived || (abst && !poly))
return;
+ // batch
+ //
+ os << "static const std::size_t batch = 1UL;"
+ << endl;
+
// rowvesion
//
bool rv (false);
@@ -43,6 +48,30 @@ namespace relational
os << "static const bool rowversion = " << rv << ";"
<< endl;
}
+
+ virtual void
+ object_public_extra_post (type& c)
+ {
+ bool abst (abstract (c));
+
+ type* poly_root (polymorphic (c));
+ bool poly (poly_root != 0);
+ bool poly_derived (poly && poly_root != &c);
+
+ if (poly_derived || (abst && !poly))
+ return;
+
+ if (semantics::data_member* m = optimistic (c))
+ {
+ sql_type t (parse_sql_type (column_type (*m), *m));
+ if (t.type == sql_type::ROWVERSION)
+ {
+ os << "static version_type" << endl
+ << "version (const id_image_type&);"
+ << endl;
+ }
+ }
+ }
};
entry<class1> class1_entry_;
diff --git a/odb/relational/mssql/source.cxx b/odb/relational/mssql/source.cxx
index 83096ab..e40a189 100644
--- a/odb/relational/mssql/source.cxx
+++ b/odb/relational/mssql/source.cxx
@@ -905,7 +905,7 @@ namespace relational
sql_type t (parse_sql_type (column_type (m), m));
return t.type != sql_type::ROWVERSION
? "1"
- : "sts.update_statement ().version ()";
+ : "version (sts.id_image ())";
}
virtual string
@@ -933,7 +933,8 @@ namespace relational
struct class_: relational::class_, statement_columns_common
{
- class_ (base const& x): base (x) {}
+ class_ (base const& x):
+ base (x), init_version_value_member_id_image_ ("v", "version_") {}
virtual void
init_image_pre (type& c)
@@ -1110,7 +1111,9 @@ namespace relational
optimistic_version_init (semantics::data_member& m)
{
sql_type t (parse_sql_type (column_type (m), m));
- return t.type != sql_type::ROWVERSION ? "1" : "st.version ()";
+ return t.type != sql_type::ROWVERSION
+ ? "1"
+ : "version (sts.id_image ())";
}
virtual string
@@ -1119,8 +1122,54 @@ namespace relational
sql_type t (parse_sql_type (column_type (m), m));
return t.type != sql_type::ROWVERSION
? "1"
- : "sts.update_statement ().version ()";
+ : "version (sts.id_image ())";
+ }
+
+ virtual bool
+ optimistic_insert_bind_version (semantics::data_member& m)
+ {
+ sql_type t (parse_sql_type (column_type (m), m));
+ return t.type == sql_type::ROWVERSION;
}
+
+ virtual void
+ object_extra (type& c)
+ {
+ bool abst (abstract (c));
+
+ type* poly_root (polymorphic (c));
+ bool poly (poly_root != 0);
+ bool poly_derived (poly && poly_root != &c);
+
+ if (poly_derived || (abst && !poly))
+ return;
+
+ if (semantics::data_member* m = optimistic (c))
+ {
+ sql_type t (parse_sql_type (column_type (*m), *m));
+ if (t.type == sql_type::ROWVERSION)
+ {
+ string const& type (class_fq_name (c));
+ string traits ("access::object_traits_impl< " + type + ", id_" +
+ db.string () + " >");
+
+ os << traits << "::version_type" << endl
+ << traits << "::" << endl
+ << "version (const id_image_type& i)"
+ << "{"
+ << "version_type v;";
+ init_version_value_member_id_image_->traverse (*m);
+ os << "return v;"
+ << "}";
+ }
+ }
+ }
+
+ private:
+ // Go via the dynamic creation to get access to the constructor.
+ //
+ instance<relational::init_value_member>
+ init_version_value_member_id_image_;
};
entry<class_> class_entry_;
}
diff --git a/odb/relational/oracle/header.cxx b/odb/relational/oracle/header.cxx
index f87e8de..1004a4c 100644
--- a/odb/relational/oracle/header.cxx
+++ b/odb/relational/oracle/header.cxx
@@ -226,6 +226,28 @@ namespace relational
member_image_type member_image_type_;
};
entry<image_member> image_member_;
+
+ struct class1: relational::class1
+ {
+ class1 (base const& x): base (x) {}
+
+ virtual void
+ object_public_extra_pre (type& c)
+ {
+ bool abst (abstract (c));
+
+ type* poly_root (polymorphic (c));
+ bool poly (poly_root != 0);
+ bool poly_derived (poly && poly_root != &c);
+
+ if (poly_derived || (abst && !poly))
+ return;
+
+ os << "static const std::size_t batch = 1UL;"
+ << endl;
+ }
+ };
+ entry<class1> class1_entry_;
}
}
}
diff --git a/odb/relational/source.cxx b/odb/relational/source.cxx
index 6e7ff34..cb91411 100644
--- a/odb/relational/source.cxx
+++ b/odb/relational/source.cxx
@@ -125,6 +125,7 @@ traverse_object (type& c)
<< db << "::connection&" << (containers || sections ? " c" : "") <<
"," << endl
<< "image_type&" << (sections ? " im" : "") << "," << endl
+ << "id_image_type&" << (sections ? " idim" : "") << "," << endl
<< db << "::binding&" << (containers || sections ? " id" : "") <<
"," << endl
<< db << "::binding&" << (sections ? " idv" : "");
@@ -190,7 +191,7 @@ traverse_object (type& c)
<< "ODB_POTENTIALLY_UNUSED (db);"
<< endl
<< "id_type id;";
- init_id_value_member_->traverse (*id);
+ init_id_value_member_id_image_->traverse (*id);
os << "return id;"
<< "}";
}
@@ -227,7 +228,7 @@ traverse_object (type& c)
}
}
- // discriminator()
+ // discriminator(image)
//
if (poly && !poly_derived)
{
@@ -1252,6 +1253,29 @@ traverse_object (type& c)
<< "imb.version++;"
<< "}";
+ // Bind id image since that's where the returned id and/or version will
+ // be extracted.
+ //
+ if (!poly_derived)
+ {
+ bool bv (opt != 0 && optimistic_insert_bind_version (*opt));
+ if (bv || auto_id)
+ {
+ os << "{"
+ << "id_image_type& i (sts.id_image ());"
+ << "binding& b (sts.id_image_binding ());"
+ << "if (i.version != sts.id_image_version () || b.version == 0)"
+ << "{"
+ << "bind (b.bind, i);"
+ << "sts.id_image_version (i.version);"
+ << "b.version++;";
+ if (opt != 0)
+ os << "sts.optimistic_id_image_binding ().version++;";
+ os << "}"
+ << "}";
+ }
+ }
+
os << "insert_statement& st (sts.persist_statement ());"
<< "if (!st.execute ())" << endl
<< "throw object_already_persistent ();"
@@ -1265,7 +1289,7 @@ traverse_object (type& c)
os << "// From " << location_string (ma.loc, true) << endl;
if (ma.placeholder ())
- os << ma.translate ("obj", "static_cast< id_type > (st.id ())") << ";"
+ os << ma.translate ("obj", "id (sts.id_image ())") << ";"
<< endl;
else
{
@@ -1282,7 +1306,7 @@ traverse_object (type& c)
if (cast)
os << ")";
- os << " = static_cast< id_type > (st.id ());"
+ os << " = id (sts.id_image ());"
<< endl;
}
}
diff --git a/odb/relational/source.hxx b/odb/relational/source.hxx
index b53b529..3754fcc 100644
--- a/odb/relational/source.hxx
+++ b/odb/relational/source.hxx
@@ -3830,7 +3830,7 @@ namespace relational
os << "," << endl
<< " ";
- os << s.member->name () << " (c, im, id, idv";
+ os << s.member->name () << " (c, im, idim, id, idv";
extra_members ();
os << ")";
}
@@ -5319,6 +5319,7 @@ namespace relational
init_id_image_member_ ("id_", "id"),
init_version_image_member_ ("version_", "(*v)"),
init_id_value_member_ ("id"),
+ init_id_value_member_id_image_ ("id", "id_"),
init_version_value_member_ ("v"),
init_named_version_value_member_ ("v", "version_"),
init_discriminator_value_member_ ("d", "", false),
@@ -5344,6 +5345,7 @@ namespace relational
init_id_image_member_ ("id_", "id"),
init_version_image_member_ ("version_", "(*v)"),
init_id_value_member_ ("id"),
+ init_id_value_member_id_image_ ("id", "id_"),
init_version_value_member_ ("v"),
init_named_version_value_member_ ("v", "version_"),
init_discriminator_value_member_ ("d", "", false),
@@ -5502,6 +5504,12 @@ namespace relational
return "1";
}
+ virtual bool
+ optimistic_insert_bind_version (semantics::data_member&)
+ {
+ return false;
+ }
+
virtual void
traverse_object (type& c);
@@ -5752,6 +5760,7 @@ namespace relational
traversal::names init_value_member_names_;
instance<init_value_member> init_id_value_member_;
+ instance<init_value_member> init_id_value_member_id_image_;
instance<init_value_member> init_version_value_member_;
instance<init_value_member> init_named_version_value_member_;
instance<init_value_member> init_discriminator_value_member_;