From be97326d67365e16175cc599e23348feaf80e0fe Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 8 Oct 2012 16:09:07 +0200 Subject: Ground work for multi-database support All generated code now includes database id. The database-specific database class interface has been updated to include all the database operations. The database-specific tests now use this interface. --- odb/database.txx | 99 +++++++++++++++++++++++++++----------------------------- 1 file changed, 47 insertions(+), 52 deletions(-) (limited to 'odb/database.txx') diff --git a/odb/database.txx b/odb/database.txx index 7ac19d7..23ea712 100644 --- a/odb/database.txx +++ b/odb/database.txx @@ -10,13 +10,30 @@ namespace odb { template + result database:: + query (const odb::query& q, bool cache) + { + // T is always object_type. We also don't need to check for transaction + // here; object_traits::query () does this. + // + result r (query_::call (*this, q)); + + if (cache) + r.cache (); + + return r; + } + + // Implementations (i.e., the *_() functions). + // + template typename object_traits::id_type database:: - persist (T& obj) + persist_ (T& obj) { // T can be const T while object_type will always be T. // - typedef typename odb::object_traits::object_type object_type; - typedef odb::object_traits object_traits; + typedef typename object_traits::object_type object_type; + typedef object_traits_impl object_traits; object_traits::persist (*this, obj); @@ -26,19 +43,18 @@ namespace odb return object_traits::id (obj); } - template + template typename object_traits::id_type database:: persist_ (const typename object_traits::pointer_type& pobj) { // T can be const T while object_type will always be T. // - typedef typename odb::object_traits::object_type object_type; - typedef odb::object_traits object_traits; + typedef typename object_traits::object_type object_type; + typedef typename object_traits::pointer_type pointer_type; - typedef typename odb::object_traits::pointer_type pointer_type; - typedef odb::pointer_traits pointer_traits; + typedef object_traits_impl object_traits; - T& obj (pointer_traits::get_ref (pobj)); + T& obj (pointer_traits::get_ref (pobj)); object_traits::persist (*this, obj); // Get the canonical object pointer and insert it into object cache. @@ -49,81 +65,60 @@ namespace odb return object_traits::id (obj); } - template + template typename object_traits::pointer_type database:: - load (const typename object_traits::id_type& id) + load_ (const typename object_traits::id_type& id) { // T is always object_type. // typedef typename object_traits::pointer_type pointer_type; - typedef odb::pointer_traits pointer_traits; - pointer_type r (find (id)); + pointer_type r (find_ (id)); - if (pointer_traits::null_ptr (r)) + if (pointer_traits::null_ptr (r)) throw object_not_persistent (); return r; } - template + template void database:: - load (const typename object_traits::id_type& id, T& obj) + load_ (const typename object_traits::id_type& id, T& obj) { - if (!find (id, obj)) + if (!find_ (id, obj)) throw object_not_persistent (); } - template + template void database:: - reload (T& obj) + reload_ (T& obj) { - // T should be object_type (cannot be const). + // T should be object_type (cannot be const). We also don't need to + // check for transaction here; object_traits::reload () does this. // - typedef odb::object_traits object_traits; - - // We don't need to check for transaction here; - // object_traits::reload () does this. - - if (!object_traits::reload (*this, obj)) + if (!object_traits_impl::reload (*this, obj)) throw object_not_persistent (); } - template - struct database::query_ + template + struct database::query_ { + template static result - call (database& db, const odb::query& q) + call (database& db, const Q& q) { - return object_traits::query (db, q); + return object_traits_impl::query (db, q); } }; - template - struct database::query_ + template + struct database::query_ { + template static result - call (database& db, const odb::query& q) + call (database& db, const Q& q) { - return view_traits::query (db, q); + return view_traits_impl::query (db, q); } }; - - template - result database:: - query (const odb::query& q, bool cache) - { - // T is always object_type. - // - - // We don't need to check for transaction here; - // object_traits::query () does this. - - result r (query_::kind>::call (*this, q)); - - if (cache) - r.cache (); - - return r; - } } -- cgit v1.1