aboutsummaryrefslogtreecommitdiff
path: root/odb/relational/source.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'odb/relational/source.cxx')
-rw-r--r--odb/relational/source.cxx137
1 files changed, 78 insertions, 59 deletions
diff --git a/odb/relational/source.cxx b/odb/relational/source.cxx
index 20c431a..e00626a 100644
--- a/odb/relational/source.cxx
+++ b/odb/relational/source.cxx
@@ -1169,14 +1169,13 @@ traverse_object (type& c)
os << ", bool top, bool dyn";
os << ")"
- << "{"
- << "ODB_POTENTIALLY_UNUSED (db);";
+ << "{";
if (poly)
- os << "ODB_POTENTIALLY_UNUSED (top);";
+ os << "ODB_POTENTIALLY_UNUSED (top);"
+ << endl;
- os << endl
- << "using namespace " << db << ";"
+ os << "using namespace " << db << ";"
<< endl;
if (poly)
@@ -1201,7 +1200,7 @@ traverse_object (type& c)
<< endl;
os << db << "::connection& conn (" << endl
- << db << "::transaction::current ().connection ());"
+ << db << "::transaction::current ().connection (db));"
<< "statements_type& sts (" << endl
<< "conn.statement_cache ().find_object<object_type> ());";
@@ -1441,13 +1440,11 @@ traverse_object (type& c)
<< "std::size_t n," << endl
<< "multiple_exceptions& mex)"
<< "{"
- << "ODB_POTENTIALLY_UNUSED (db);"
- << endl
<< "using namespace " << db << ";"
<< endl;
os << db << "::connection& conn (" << endl
- << db << "::transaction::current ().connection ());"
+ << db << "::transaction::current ().connection (db));"
<< "statements_type& sts (" << endl
<< "conn.statement_cache ().find_object<object_type> ());";
@@ -1464,13 +1461,25 @@ traverse_object (type& c)
<< "{"
<< "const object_type& obj (*objs[i]);"
<< "callback (db, obj, callback_event::pre_persist);"
- //@@ assumption: generate_grow is false
+ //@@ assumption: generate_grow is false or it only affects select (like
+ // in pgsql) so all we have to do is to increment image
+ // version if it grew.
//@@ assumption: insert_send_auto_id is false
- << "init (sts.image (i), obj, statement_insert" <<
- (versioned ? ", svm" : "") << ");"
+ << "image_type& im (sts.image (i));";
+
+ if (generate_grow)
+ os << "if (";
+
+ os << "init (im, obj, statement_insert" << (versioned ? ", svm" : "") << ")";
+
+ if (generate_grow)
+ os << " && i == 0)" << endl
+ << "im.version++";
+
+ os << ";"
<< "}";
- //@@ assumption: generate_grow is false
+ //@@ assumption: generate_grow: as above
os << "binding& imb (sts.insert_image_binding ());"
<< "if (imb.version == 0)"
<< "{"
@@ -1486,7 +1495,7 @@ traverse_object (type& c)
if (bv || auto_id)
{
os << "binding& idb (sts.id_image_binding ());"
- //@@ assumption: generate_grow is false
+ //@@ assumption: generate_grow: as above
<< "if (idb.version == 0)"
<< "{"
<< "bind (idb.bind, sts.id_image ());"
@@ -1692,7 +1701,7 @@ traverse_object (type& c)
sts = true;
os << db << "::transaction& tr (" << db <<
"::transaction::current ());"
- << db << "::connection& conn (tr.connection ());"
+ << db << "::connection& conn (tr.connection (db));"
<< "statements_type& sts (" << endl
<< "conn.statement_cache ().find_object<object_type> ());"
<< endl;
@@ -1787,7 +1796,7 @@ traverse_object (type& c)
{
os << db << "::transaction& tr (" << db <<
"::transaction::current ());"
- << db << "::connection& conn (tr.connection ());"
+ << db << "::connection& conn (tr.connection (db));"
<< "statements_type& sts (" << endl
<< "conn.statement_cache ().find_object<object_type> ());"
<< endl;
@@ -1877,7 +1886,7 @@ traverse_object (type& c)
if (!sts)
os << db << "::transaction& tr (" << db <<
"::transaction::current ());"
- << db << "::connection& conn (tr.connection ());"
+ << db << "::connection& conn (tr.connection (db));"
<< "statements_type& sts (" << endl
<< "conn.statement_cache ().find_object<object_type> ());"
<< endl;
@@ -1976,7 +1985,7 @@ traverse_object (type& c)
if (!sts)
os << db << "::transaction& tr (" << db <<
"::transaction::current ());"
- << db << "::connection& conn (tr.connection ());"
+ << db << "::connection& conn (tr.connection (db));"
<< "statements_type& sts (" << endl
<< "conn.statement_cache ().find_object<object_type> ());"
<< endl;
@@ -2194,13 +2203,11 @@ traverse_object (type& c)
<< "std::size_t n," << endl
<< "multiple_exceptions& mex)"
<< "{"
- << "ODB_POTENTIALLY_UNUSED (db);"
- << endl
<< "using namespace " << db << ";"
<< "using " << db << "::update_statement;"
<< endl
<< db << "::connection& conn (" << endl
- << db << "::transaction::current ().connection ());"
+ << db << "::transaction::current ().connection (db));"
<< "statements_type& sts (" << endl
<< "conn.statement_cache ().find_object<object_type> ());";
@@ -2217,9 +2224,24 @@ traverse_object (type& c)
if (opt != 0)
os << "const version_type& v (version (obj));";
- os << "init (sts.id_image (i), id (obj)" << (opt != 0 ? ", &v" : "") << ");"
- //@@ assumption: generate_grow false
- << "init (sts.image (i), obj, statement_update);"
+ os << "init (sts.id_image (i), id (obj)" << (opt != 0 ? ", &v" : "") << ");";
+
+ //@@ assumption: generate_grow is false or it only affects select (like
+ // in pgsql) so all we have to do is to increment image
+ // version if it grew.
+
+ os << "image_type& im (sts.image (i));";
+
+ if (generate_grow)
+ os << "if (";
+
+ os << "init (im, obj, statement_update" << (versioned ? ", svm" : "") << ")";
+
+ if (generate_grow)
+ os << " && i == 0)" << endl
+ << "im.version++";
+
+ os << ";"
<< "}";
// Update bindings.
@@ -2228,7 +2250,7 @@ traverse_object (type& c)
<< "binding& imb (sts.update_image_binding ());"
<< endl;
- //@@ assumption: generate_grow false
+ //@@ assumption: generate_grow: as above
//
os << "bool u (false);" // Avoid incrementing version twice.
<< "if (imb.version == 0)"
@@ -2239,7 +2261,7 @@ traverse_object (type& c)
<< "u = true;"
<< "}";
- //@@ assumption: generate_grow false
+ //@@ assumption: generate_grow: as above
//
os << "if (idb.version == 0)"
<< "{"
@@ -2321,16 +2343,15 @@ traverse_object (type& c)
os << ")"
<< "{"
- << "using namespace " << db << ";"
- << endl
- << "ODB_POTENTIALLY_UNUSED (db);";
+ << "using namespace " << db << ";";
if (poly)
- os << "ODB_POTENTIALLY_UNUSED (top);";
+ os << endl
+ << "ODB_POTENTIALLY_UNUSED (top);";
os << endl
<< db << "::connection& conn (" << endl
- << db << "::transaction::current ().connection ());"
+ << db << "::transaction::current ().connection (db));"
<< "statements_type& sts (" << endl
<< "conn.statement_cache ().find_object<object_type> ());"
<< endl;
@@ -2449,10 +2470,8 @@ traverse_object (type& c)
<< "{"
<< "using namespace " << db << ";"
<< endl
- << "ODB_POTENTIALLY_UNUSED (db);"
- << endl
<< db << "::connection& conn (" << endl
- << db << "::transaction::current ().connection ());"
+ << db << "::transaction::current ().connection (db));"
<< "statements_type& sts (" << endl
<< "conn.statement_cache ().find_object<object_type> ());"
<< endl
@@ -2460,7 +2479,8 @@ traverse_object (type& c)
<< "init (sts.id_image (i), *ids[i]);"
<< endl
<< "binding& idb (sts.id_image_binding ());"
- //@@ assumption: generate_grow false
+ //@@ assumption: generate_grow is false or it only affects select (like
+ // in pgsql).
<< "if (idb.version == 0)"
<< "{"
<< "bind (idb.bind, sts.id_image ());"
@@ -2542,7 +2562,7 @@ traverse_object (type& c)
os << "using namespace " << db << ";"
<< endl
<< db << "::connection& conn (" << endl
- << db << "::transaction::current ().connection ());"
+ << db << "::transaction::current ().connection (db));"
<< "statements_type& sts (" << endl
<< "conn.statement_cache ().find_object<object_type> ());";
@@ -2830,10 +2850,8 @@ traverse_object (type& c)
{
os << "using namespace " << db << ";"
<< endl
- << "ODB_POTENTIALLY_UNUSED (db);"
- << endl
<< db << "::connection& conn (" << endl
- << db << "::transaction::current ().connection ());"
+ << db << "::transaction::current ().connection (db));"
<< "statements_type& sts (" << endl
<< "conn.statement_cache ().find_object<object_type> ());"
<< endl
@@ -2846,7 +2864,8 @@ traverse_object (type& c)
<< "}";
os << "binding& idb (sts.id_image_binding ());"
- //@@ assumption: generate_grow false
+ //@@ assumption: generate_grow is false or it only affects select
+ // (like in pgsql).
<< "if (idb.version == 0)"
<< "{"
<< "bind (idb.bind, sts.id_image ());"
@@ -2917,7 +2936,7 @@ traverse_object (type& c)
os << "}";
os << db << "::connection& conn (" << endl
- << db << "::transaction::current ().connection ());"
+ << db << "::transaction::current ().connection (db));"
<< "statements_type& sts (" << endl
<< "conn.statement_cache ().find_object<object_type> ());";
@@ -3110,7 +3129,7 @@ traverse_object (type& c)
if (!abst)
{
os << db << "::connection& conn (" << endl
- << db << "::transaction::current ().connection ());"
+ << db << "::transaction::current ().connection (db));"
<< "statements_type& sts (" << endl
<< "conn.statement_cache ().find_object<object_type> ());";
@@ -3217,7 +3236,7 @@ traverse_object (type& c)
if (!abst)
{
os << db << "::connection& conn (" << endl
- << db << "::transaction::current ().connection ());"
+ << db << "::transaction::current ().connection (db));"
<< "statements_type& sts (" << endl
<< "conn.statement_cache ().find_object<object_type> ());";
@@ -3909,7 +3928,7 @@ traverse_object (type& c)
<< endl
<< "object_type& obj (static_cast<object_type&> (r));"
<< db << "::connection& conn (" << endl
- << db << "::transaction::current ().connection ());"
+ << db << "::transaction::current ().connection (db));"
<< "statements_type& sts (" << endl
<< "conn.statement_cache ().find_object<object_type> ());"
<< endl
@@ -4135,7 +4154,7 @@ traverse_object (type& c)
//
os << "result< " << traits << "::object_type >" << endl
<< traits << "::" << endl
- << "query (database&, const query_base_type& q)"
+ << "query (database& db, const query_base_type& q)"
<< "{"
<< "using namespace " << db << ";"
<< "using odb::details::shared;"
@@ -4143,7 +4162,7 @@ traverse_object (type& c)
<< endl;
os << db << "::connection& conn (" << endl
- << db << "::transaction::current ().connection ());"
+ << db << "::transaction::current ().connection (db));"
<< endl
<< "statements_type& sts (" << endl
<< "conn.statement_cache ().find_object<object_type> ());";
@@ -4224,12 +4243,12 @@ traverse_object (type& c)
// erase_query
//
os << "unsigned long long " << traits << "::" << endl
- << "erase_query (database&, const query_base_type& q)"
+ << "erase_query (database& db, const query_base_type& q)"
<< "{"
<< "using namespace " << db << ";"
<< endl
<< db << "::connection& conn (" << endl
- << db << "::transaction::current ().connection ());"
+ << db << "::transaction::current ().connection (db));"
<< endl
<< "std::string text (erase_query_statement);"
<< "if (!q.empty ())"
@@ -4363,16 +4382,15 @@ traverse_object (type& c)
<< "static_cast<select_statement*> (pq.stmt.get ())));"
<< endl;
- os << db << "::connection& conn (" << endl
- << db << "::transaction::current ().connection ());"
+ os << db << "::transaction& tr (" << db << "::transaction::current ());"
<< endl
<< "// The connection used by the current transaction and the" << endl
<< "// one used to prepare this statement must be the same." << endl
<< "//" << endl
- << "assert (&conn == &st->connection ());"
+ << "assert (q.verify_connection (tr));"
<< endl
<< "statements_type& sts (" << endl
- << "conn.statement_cache ().find_object<object_type> ());";
+ << "st->connection ().statement_cache ().find_object<object_type> ());";
if (versioned)
os << "const schema_version_migration& svm (" <<
@@ -5265,9 +5283,11 @@ traverse_view (type& c)
<< "throw session_required ();"
<< endl;
+ // Note: db must be not NULL in order to load pointers.
+ //
if (has_a (c, test_pointer))
os << db << "::connection& conn (" << endl
- << db << "::transaction::current ().connection ());"
+ << db << "::transaction::current ().connection (*db));"
<< endl;
names (c, init_view_pointer_member_pre_names_);
@@ -5514,7 +5534,7 @@ traverse_view (type& c)
{
os << "result< " << traits << "::view_type >" << endl
<< traits << "::" << endl
- << "query (database&, const query_base_type& q)"
+ << "query (database& db, const query_base_type& q)"
<< "{"
<< "using namespace " << db << ";"
<< "using odb::details::shared;"
@@ -5522,7 +5542,7 @@ traverse_view (type& c)
<< endl;
os << db << "::connection& conn (" << endl
- << db << "::transaction::current ().connection ());"
+ << db << "::transaction::current ().connection (db));"
<< "statements_type& sts (" << endl
<< "conn.statement_cache ().find_view<view_type> ());";
@@ -5662,16 +5682,15 @@ traverse_view (type& c)
<< "static_cast<select_statement*> (pq.stmt.get ())));"
<< endl;
- os << db << "::connection& conn (" << endl
- << db << "::transaction::current ().connection ());"
+ os << db << "::transaction& tr (" << db << "::transaction::current ());"
<< endl
<< "// The connection used by the current transaction and the" << endl
<< "// one used to prepare this statement must be the same." << endl
<< "//" << endl
- << "assert (&conn == &st->connection ());"
+ << "assert (q.verify_connection (tr));"
<< endl
<< "statements_type& sts (" << endl
- << "conn.statement_cache ().find_view<view_type> ());";
+ << "st->connection ().statement_cache ().find_view<view_type> ());";
if (versioned)
os << "const schema_version_migration& svm (" <<