aboutsummaryrefslogtreecommitdiff
path: root/odb/relational/inline.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-11-01 12:41:02 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-11-01 14:30:22 +0200
commit7871bd9b681f449cc3938750ce70fa1ed5400dcd (patch)
tree3784716722430f06799016e3b7bdae7231fd9120 /odb/relational/inline.hxx
parentc11ace0f4a665ac0dfb269860ef04dce284b75f5 (diff)
Implement support for optimistic concurrency
New pragmas: optimistic, version. New test: optimistic. New database function: reload().
Diffstat (limited to 'odb/relational/inline.hxx')
-rw-r--r--odb/relational/inline.hxx37
1 files changed, 33 insertions, 4 deletions
diff --git a/odb/relational/inline.hxx b/odb/relational/inline.hxx
index 3968dce..0c37d33 100644
--- a/odb/relational/inline.hxx
+++ b/odb/relational/inline.hxx
@@ -109,6 +109,8 @@ namespace relational
semantics::data_member* id (id_member (c));
bool base_id (id ? &id->scope () != &c : false); // Comes from base.
+ semantics::data_member* optimistic (context::optimistic (c));
+
os << "// " << c.name () << endl
<< "//" << endl
<< endl;
@@ -139,10 +141,10 @@ namespace relational
if (id != 0)
{
+ // id (image_type)
+ //
if (options.generate_query () && base_id)
{
- // id (image_type)
- //
os << "inline" << endl
<< traits << "::id_type" << endl
<< traits << "::" << endl
@@ -153,6 +155,20 @@ namespace relational
<< "}";
}
+ // version (image_type)
+ //
+ if (optimistic != 0 && base_id)
+ {
+ os << "inline" << endl
+ << traits << "::version_type" << endl
+ << traits << "::" << endl
+ << "version (const image_type& i)"
+ << "{"
+ << "return object_traits< " <<
+ optimistic->scope ().fq_name () << " >::version (i);"
+ << "}";
+ }
+
// bind (id_image_type)
//
if (base_id)
@@ -170,10 +186,11 @@ namespace relational
{
os << "inline" << endl
<< "void " << traits << "::" << endl
- << "init (id_image_type& i, const id_type& id)"
+ << "init (id_image_type& i, const id_type& id" <<
+ (optimistic != 0 ? ", const version_type* v" : "") << ")"
<< "{"
<< "object_traits< " << id->scope ().fq_name () <<
- " >::init (i, id);"
+ " >::init (i, id" << (optimistic != 0 ? ", v" : "") << ");"
<< "}";
}
}
@@ -184,6 +201,18 @@ namespace relational
if (abstract)
return;
+ // erase (object_type)
+ //
+ if (id != 0 && optimistic == 0)
+ {
+ os << "inline" << endl
+ << "void " << traits << "::" << endl
+ << "erase (database& db, const object_type& obj)"
+ << "{"
+ << "erase (db, id (obj));"
+ << "}";
+ }
+
// callback ()
//
os << "inline" << endl