From 6f0d40508286afc8cdd72a0b5f807d5c2a589cfc Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 4 Jun 2010 16:33:08 +0200 Subject: Initial implementation --- odb/database.txx | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 odb/database.txx (limited to 'odb/database.txx') diff --git a/odb/database.txx b/odb/database.txx new file mode 100644 index 0000000..c507030 --- /dev/null +++ b/odb/database.txx @@ -0,0 +1,73 @@ +// file : odb/database.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#include +#include +#include + +namespace odb +{ + // @@ Should I make these inline? + // + + template class P> + typename object_traits::id_type database:: + persist (P p) + { + // P should be the same or convertible to + // object_traits::shared_ptr. + // + const typename object_traits::shared_ptr& obj (p); + + session& s (transaction::current ().session ()); + return s.persist (*this, obj); + } + + template + typename object_traits::shared_ptr database:: + load (typename object_traits::id_type const& id) + { + typename object_traits::shared_ptr r (find (id)); + + if (object_traits::shared_ops::null_ptr (r)) + throw object_not_persistent (); + + return r; + } + + template + typename object_traits::shared_ptr database:: + find (typename object_traits::id_type const& id) + { + session& s (transaction::current ().session ()); + return s.find (*this, id); + } + + template class P> + void database:: + erase (P p) + { + // P should be the same or convertible to + // object_traits::shared_ptr. + // + const typename object_traits::shared_ptr& obj (p); + + session& s (transaction::current ().session ()); + return s.erase (*this, obj); + } + + template class P> + void database:: + modified (P p) + { + // P should be the same or convertible to + // object_traits::shared_ptr. + // + const typename object_traits::shared_ptr& obj (p); + + session& s (transaction::current ().session ()); + return s.modified (obj); + } +} -- cgit v1.1