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.ixx | 228 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 148 insertions(+), 80 deletions(-) (limited to 'odb/database.ixx') diff --git a/odb/database.ixx b/odb/database.ixx index 4a00a74..aeffdec 100644 --- a/odb/database.ixx +++ b/odb/database.ixx @@ -7,11 +7,17 @@ namespace odb { inline database:: - database () - : tracer_ (0) + database (database_id id) + : id_ (id), tracer_ (0) { } + inline database_id database:: + id () const + { + return id_; + } + inline connection_ptr database:: connection () { @@ -38,6 +44,13 @@ namespace odb template inline typename object_traits::id_type database:: + persist (T& obj) + { + return persist_ (obj); + } + + template + inline typename object_traits::id_type database:: persist (T* p) { typedef typename object_traits::pointer_type object_pointer; @@ -48,7 +61,7 @@ namespace odb // const object_pointer& pobj (p); - return persist_ (pobj); + return persist_ (pobj); } template class P> @@ -63,7 +76,7 @@ namespace odb // const object_pointer& pobj (p); - return persist_ (pobj); + return persist_ (pobj); } template class P> @@ -78,7 +91,7 @@ namespace odb // const object_pointer& pobj (p); - return persist_ (pobj); + return persist_ (pobj); } template class P> @@ -101,29 +114,42 @@ namespace odb inline typename object_traits::id_type database:: persist (const typename object_traits::pointer_type& pobj) { - return persist_ (pobj); + return persist_ (pobj); } template inline typename object_traits::pointer_type database:: - find (const typename object_traits::id_type& id) + load (const typename object_traits::id_type& id) { - // T is always object_type. - // + return load_ (id); + } - // Compiler error pointing here? Perhaps the object doesn't have the - // default constructor? - // - return object_traits::find (*this, id); + template + inline void database:: + load (const typename object_traits::id_type& id, T& obj) + { + return load_ (id, obj); + } + + template + inline typename object_traits::pointer_type database:: + find (const typename object_traits::id_type& id) + { + return find_ (id); } template inline bool database:: find (const typename object_traits::id_type& id, T& obj) { - // T is always object_type. - // - return object_traits::find (*this, id, obj); + return find_ (id, obj); + } + + template + inline void database:: + reload (T& obj) + { + reload_ (obj); } template @@ -172,6 +198,13 @@ namespace odb template inline void database:: + update (T& obj) + { + update_ (obj); + } + + template + inline void database:: update (T* p) { typedef typename object_traits::pointer_type object_pointer; @@ -182,7 +215,7 @@ namespace odb // const object_pointer& pobj (p); - update_ (pobj); + update_ (pobj); } template class P> @@ -197,7 +230,7 @@ namespace odb // const object_pointer& pobj (p); - update_ (pobj); + update_ (pobj); } template class P> @@ -212,7 +245,7 @@ namespace odb // const object_pointer& pobj (p); - update_ (pobj); + update_ (pobj); } template class P> @@ -235,42 +268,21 @@ namespace odb inline void database:: update (const typename object_traits::pointer_type& pobj) { - update_ (pobj); + update_ (pobj); } template inline void database:: - update (T& obj) + erase (const typename object_traits::id_type& id) { - // 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; - - // Compiler error pointing here? Perhaps the object is readonly or - // doesn't have an object id? Such objects cannot be updated. - // - object_traits::update (*this, obj); + return erase_ (id); } template inline void database:: - update_ (const typename object_traits::pointer_type& pobj) + erase (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 odb::object_traits::pointer_type pointer_type; - typedef odb::pointer_traits pointer_traits; - - T& obj (pointer_traits::get_ref (pobj)); - - // Compiler error pointing here? Perhaps the object is readonly or - // doesn't have an object id? Such objects cannot be updated. - // - object_traits::update (*this, obj); + return erase_ (obj); } template @@ -285,7 +297,7 @@ namespace odb // const object_pointer& pobj (p); - erase_ (pobj); + erase_ (pobj); } template class P> @@ -300,7 +312,7 @@ namespace odb // const object_pointer& pobj (p); - erase_ (pobj); + erase_ (pobj); } template class P> @@ -315,7 +327,7 @@ namespace odb // const object_pointer& pobj (p); - erase_ (pobj); + erase_ (pobj); } template class P> @@ -338,37 +350,7 @@ namespace odb inline void database:: erase (const typename object_traits::pointer_type& pobj) { - erase_ (pobj); - } - - template - inline void database:: - erase_ (const typename object_traits::pointer_type& pobj) - { - typedef typename object_traits::pointer_type pointer_type; - typedef pointer_traits pointer_traits; - - erase (pointer_traits::get_ref (pobj)); - } - - template - inline void database:: - erase (const typename object_traits::id_type& id) - { - // T is always object_type. - // - object_traits::erase (*this, id); - } - - template - inline void database:: - erase (T& obj) - { - // T can be const T while object_type will always be T. - // - typedef typename object_traits::object_type object_type; - - object_traits::erase (*this, obj); + erase_ (pobj); } template @@ -404,7 +386,7 @@ namespace odb { // T is always object_type. // - return object_traits::erase_query (*this, q); + return object_traits_impl::erase_query (*this, q); } template @@ -428,6 +410,92 @@ namespace odb return query (odb::query (q), cache); } + // Implementations (i.e., the *_() functions). + // + template + inline typename object_traits::pointer_type database:: + find_ (const typename object_traits::id_type& id) + { + // T is always object_type. + // + + // Compiler error pointing here? Perhaps the object doesn't have the + // default constructor? + // + return object_traits_impl::find (*this, id); + } + + template + inline bool database:: + find_ (const typename object_traits::id_type& id, T& obj) + { + // T is always object_type. + // + return object_traits_impl::find (*this, id, obj); + } + + template + inline void database:: + update_ (T& obj) + { + // T can be const T while object_type will always be T. + // + typedef typename object_traits::object_type object_type; + + // Compiler error pointing here? Perhaps the object is readonly or + // doesn't have an object id? Such objects cannot be updated. + // + object_traits_impl::update (*this, obj); + } + + template + inline void database:: + update_ (const typename object_traits::pointer_type& pobj) + { + // T can be const T while object_type will always be T. + // + typedef typename object_traits::object_type object_type; + typedef typename object_traits::pointer_type pointer_type; + + T& obj (pointer_traits::get_ref (pobj)); + + // Compiler error pointing here? Perhaps the object is readonly or + // doesn't have an object id? Such objects cannot be updated. + // + object_traits_impl::update (*this, obj); + } + + template + inline void database:: + erase_ (const typename object_traits::id_type& id) + { + // T is always object_type. + // + object_traits_impl::erase (*this, id); + } + + template + inline void database:: + erase_ (T& obj) + { + // T can be const T while object_type will always be T. + // + typedef typename object_traits::object_type object_type; + + object_traits_impl::erase (*this, obj); + } + + template + inline void database:: + erase_ (const typename object_traits::pointer_type& pobj) + { + typedef typename object_traits::pointer_type pointer_type; + + erase_ (pointer_traits::get_ref (pobj)); + } + + // execute() + // inline unsigned long long database:: execute (const char* statement) { -- cgit v1.1