From 5ea5e53521e52a3f63de1f18734bdf2c871bf60c Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 26 Nov 2010 13:24:00 +0200 Subject: Add support for recursive object loading If an object of a type needs to be loaded recursively, then it is addded to the delayed loading list which is processed once the statements are unlocked. --- odb/mysql/header.cxx | 4 ++-- odb/mysql/source.cxx | 54 +++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 41 insertions(+), 17 deletions(-) (limited to 'odb/mysql') diff --git a/odb/mysql/header.cxx b/odb/mysql/header.cxx index 89b1fe8..1b995a9 100644 --- a/odb/mysql/header.cxx +++ b/odb/mysql/header.cxx @@ -890,9 +890,9 @@ namespace mysql << "query (database&, const query_type&);" << endl; - // Helpers. + // Implementation details. // - os << "private:" << endl + os << "public:" << endl << "static bool" << endl << "find_ (mysql::object_statements&, const id_type&);" << endl; diff --git a/odb/mysql/source.cxx b/odb/mysql/source.cxx index 6f95623..3b8a01d 100644 --- a/odb/mysql/source.cxx +++ b/odb/mysql/source.cxx @@ -2578,7 +2578,7 @@ namespace mysql << "using namespace mysql;" << endl << "connection& conn (mysql::transaction::current ().connection ());" - << "object_statements& sts (" << endl + << "object_statements< object_type >& sts (" << endl << "conn.statement_cache ().find ());" << "image_type& im (sts.image ());" << "binding& imb (sts.in_image_binding ());" @@ -2638,7 +2638,7 @@ namespace mysql << "using namespace mysql;" << endl << "connection& conn (mysql::transaction::current ().connection ());" - << "object_statements& sts (" << endl + << "object_statements< object_type >& sts (" << endl << "conn.statement_cache ().find ());" << endl; @@ -2695,7 +2695,7 @@ namespace mysql << "using namespace mysql;" << endl << "connection& conn (mysql::transaction::current ().connection ());" - << "object_statements& sts (" << endl + << "object_statements< object_type >& sts (" << endl << "conn.statement_cache ().find ());" << endl; @@ -2742,17 +2742,24 @@ namespace mysql << "using namespace mysql;" << endl << "connection& conn (mysql::transaction::current ().connection ());" - << "object_statements& sts (" << endl + << "object_statements< object_type >& sts (" << endl << "conn.statement_cache ().find ());" + << "object_statements< object_type >::auto_lock l (sts);" << endl - << "if (find_ (sts, id))" + << "if (l.locked ())" << "{" + << "if (!find_ (sts, id))" << endl + << "return pointer_type ();" + << "}" << "pointer_type p (" << endl << "access::object_factory< object_type, pointer_type >::create ());" << "pointer_traits< pointer_type >::guard_type pg (p);" << "pointer_cache_traits< pointer_type >::insert_guard ig (" << endl << "pointer_cache_traits< pointer_type >::insert (db, id, p));" << "object_type& obj (pointer_traits< pointer_type >::get_ref (p));" + << endl + << "if (l.locked ())" + << "{" << "init (obj, sts.image (), db);"; if (containers) @@ -2764,11 +2771,16 @@ namespace mysql os << endl; } + os << "sts.load_delayed ();" + << "l.unlock ();" + << "}" + << "else" << endl + << "sts.delay_load (id, obj, ig.position ());" + << endl; + os << "ig.release ();" << "pg.release ();" << "return p;" - << "}" - << "return pointer_type ();" << "}"; } @@ -2778,13 +2790,20 @@ namespace mysql << "using namespace mysql;" << endl << "connection& conn (mysql::transaction::current ().connection ());" - << "object_statements& sts (" << endl + << "object_statements< object_type >& sts (" << endl << "conn.statement_cache ().find ());" + << "object_statements< object_type >::auto_lock l (sts);" << endl - << "if (find_ (sts, id))" + << "if (l.locked ())" << "{" + << "if (!find_ (sts, id))" << endl + << "return false;" + << "}" << "reference_cache_traits< object_type >::insert_guard ig (" << endl << "reference_cache_traits< object_type >::insert (db, id, obj));" + << endl + << "if (l.locked ())" + << "{" << "init (obj, sts.image (), db);"; if (containers) @@ -2796,14 +2815,19 @@ namespace mysql os << endl; } + os << "sts.load_delayed ();" + << "l.unlock ();" + << "}" + << "else" << endl + << "sts.delay_load (id, obj, ig.position ());" + << endl; + os << "ig.release ();" << "return true;" - << "}" - << "return false;" << "}"; os << "bool " << traits << "::" << endl - << "find_ (mysql::object_statements& sts, " << + << "find_ (mysql::object_statements< object_type >& sts, " << "const id_type& id)" << "{" << "using namespace mysql;" @@ -2879,7 +2903,7 @@ namespace mysql << endl << "connection& conn (mysql::transaction::current ().connection ());" << endl - << "object_statements& sts (" << endl + << "object_statements< object_type >& sts (" << endl << "conn.statement_cache ().find ());" << "details::shared_ptr st;" << endl @@ -2901,7 +2925,7 @@ namespace mysql << endl << "connection& conn (mysql::transaction::current ().connection ());" << endl - << "object_statements& sts (" << endl + << "object_statements< object_type >& sts (" << endl << "conn.statement_cache ().find ());" << "details::shared_ptr st;" << endl @@ -2916,7 +2940,7 @@ namespace mysql << traits << "::" << endl << "query_ (database&," << endl << "const query_type& q," << endl - << "mysql::object_statements& sts," + << "mysql::object_statements< object_type >& sts," << "details::shared_ptr& st)" << "{" << "using namespace mysql;" -- cgit v1.1