From 7871bd9b681f449cc3938750ce70fa1ed5400dcd Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 1 Nov 2011 12:41:02 +0200 Subject: Implement support for optimistic concurrency New pragmas: optimistic, version. New test: optimistic. New database function: reload(). --- odb/relational/inline.hxx | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'odb/relational/inline.hxx') 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 -- cgit v1.1