From a28444da4ca6adb016f719e032174ccb54e1692e Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 21 Sep 2011 13:00:33 +0200 Subject: Rework const object handling Now objects are always loaded as non-const and the object cache in session treats all objects as non-const. --- odb/database.txx | 57 ++++++++++++++++++++------------------------------------ 1 file changed, 20 insertions(+), 37 deletions(-) (limited to 'odb/database.txx') diff --git a/odb/database.txx b/odb/database.txx index 8117997..82afd64 100644 --- a/odb/database.txx +++ b/odb/database.txx @@ -63,6 +63,8 @@ namespace odb typename object_traits::pointer_type database:: 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; @@ -86,12 +88,10 @@ namespace odb typename object_traits::pointer_type database:: find (const typename object_traits::id_type& id) { - // T can be const T while object_type will always be T. + // T is always object_type. // - typedef typename odb::object_traits::object_type object_type; - typedef odb::object_traits object_traits; - - typedef typename odb::object_traits::pointer_type pointer_type; + typedef odb::object_traits object_traits; + typedef typename object_traits::pointer_type pointer_type; typedef odb::pointer_traits pointer_traits; // First check the session. @@ -117,15 +117,12 @@ namespace odb bool database:: find (const typename object_traits::id_type& id, T& obj) { - // T can be const T while object_type will always be T. + // T is always object_type. // - typedef typename odb::object_traits::object_type object_type; - typedef odb::object_traits object_traits; - if (!transaction::has_current ()) throw not_in_transaction (); - return object_traits::find (*this, id, obj); + return object_traits::find (*this, id, obj); } template @@ -171,12 +168,10 @@ namespace odb void database:: erase (const typename object_traits::id_type& id) { - // T can be const T while object_type will always be T. + // T is always object_type. // - typedef typename odb::object_traits::object_type object_type; - typedef odb::object_traits object_traits; - - typedef typename odb::object_traits::pointer_type pointer_type; + typedef odb::object_traits object_traits; + typedef typename object_traits::pointer_type pointer_type; if (!transaction::has_current ()) throw not_in_transaction (); @@ -193,8 +188,7 @@ namespace odb // typedef typename odb::object_traits::object_type object_type; typedef odb::object_traits object_traits; - - typedef typename odb::object_traits::pointer_type pointer_type; + typedef typename object_traits::pointer_type pointer_type; if (!transaction::has_current ()) throw not_in_transaction (); @@ -209,53 +203,42 @@ namespace odb template unsigned long long database:: - erase_query (const odb::query::object_type>& q) + erase_query (const odb::query& q) { - // T can be const T while object_type will always be T. + // T is always object_type. // - typedef typename odb::object_traits::object_type object_type; - typedef odb::object_traits object_traits; - if (!transaction::has_current ()) throw not_in_transaction (); - return object_traits::erase_query (*this, q); + return object_traits::erase_query (*this, q); } template struct database::query_ { - // 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; - static result - call (database& db, const odb::query& q) + call (database& db, const odb::query& q) { - return object_traits::template query (db, q); + return object_traits::query (db, q); } }; template struct database::query_ { - // Const views are not supported. - // - typedef odb::view_traits view_traits; - static result call (database& db, const odb::query& q) { - return view_traits::query (db, q); + return view_traits::query (db, q); } }; template result database:: - query (const odb::query::result>& q, - bool cache) + query (const odb::query& q, bool cache) { + // T is always object_type. + // if (!transaction::has_current ()) throw not_in_transaction (); -- cgit v1.1