From 6400b736456af65176c9c1959022f1eb49fcde32 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 20 Jul 2010 11:02:07 +0200 Subject: Get rid of the session mechanism for now Add low-level API instead. --- odb/database.txx | 84 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 31 deletions(-) (limited to 'odb/database.txx') diff --git a/odb/database.txx b/odb/database.txx index c507030..12edc85 100644 --- a/odb/database.txx +++ b/odb/database.txx @@ -4,7 +4,6 @@ // license : GNU GPL v2; see accompanying LICENSE file #include -#include #include namespace odb @@ -12,62 +11,85 @@ namespace odb // @@ Should I make these inline? // - template class P> + template typename object_traits::id_type database:: - persist (P p) + persist (T& obj) { - // P should be the same or convertible to - // object_traits::shared_ptr. - // - const typename object_traits::shared_ptr& obj (p); + typedef object_traits traits; + + if (!transaction::has_current ()) + throw not_in_transaction (); - session& s (transaction::current ().session ()); - return s.persist (*this, obj); + traits::insert (*this, obj); + return traits::id (obj); } template - typename object_traits::shared_ptr database:: + typename object_traits::pointer_type database:: load (typename object_traits::id_type const& id) { - typename object_traits::shared_ptr r (find (id)); + typedef object_traits traits; + + typename traits::pointer_type r (find (id)); - if (object_traits::shared_ops::null_ptr (r)) + if (traits::pointer_ops::null_ptr (r)) throw object_not_persistent (); return r; } template - typename object_traits::shared_ptr database:: + void database:: + load (typename object_traits::id_type const& id, T& obj) + { + if (!find (id, obj)) + throw object_not_persistent (); + } + + template + typename object_traits::pointer_type database:: find (typename object_traits::id_type const& id) { - session& s (transaction::current ().session ()); - return s.find (*this, id); + if (!transaction::has_current ()) + throw not_in_transaction (); + + return object_traits::find (*this, id); + } + + template + bool database:: + find (typename object_traits::id_type const& id, T& obj) + { + if (!transaction::has_current ()) + throw not_in_transaction (); + + return object_traits::find (*this, id, obj); } - template class P> + template void database:: - erase (P p) + store (T& obj) { - // P should be the same or convertible to - // object_traits::shared_ptr. - // - const typename object_traits::shared_ptr& obj (p); + if (!transaction::has_current ()) + throw not_in_transaction (); - session& s (transaction::current ().session ()); - return s.erase (*this, obj); + object_traits::update (*this, obj); } - template class P> + template + void database:: + erase (const T& obj) + { + erase (object_traits::id (obj)); + } + + template void database:: - modified (P p) + erase (typename object_traits::id_type const& id) { - // P should be the same or convertible to - // object_traits::shared_ptr. - // - const typename object_traits::shared_ptr& obj (p); + if (!transaction::has_current ()) + throw not_in_transaction (); - session& s (transaction::current ().session ()); - return s.modified (obj); + object_traits::erase (*this, id); } } -- cgit v1.1