diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2010-06-04 16:33:08 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2010-06-04 16:33:08 +0200 |
commit | 6f0d40508286afc8cdd72a0b5f807d5c2a589cfc (patch) | |
tree | f22a38560560664cae731c37537c2bb04bffdc2a /odb/database.txx | |
parent | e0f3efd9df3e7eefa06777717f23905022d1949e (diff) |
Initial implementation
Diffstat (limited to 'odb/database.txx')
-rw-r--r-- | odb/database.txx | 73 |
1 files changed, 73 insertions, 0 deletions
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 <boris@codesynthesis.com> +// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#include <odb/exceptions.hxx> +#include <odb/session.hxx> +#include <odb/transaction.hxx> + +namespace odb +{ + // @@ Should I make these inline? + // + + template <typename T, template <typename> class P> + typename object_traits<T>::id_type database:: + persist (P<T> p) + { + // P<T> should be the same or convertible to + // object_traits<T>::shared_ptr. + // + const typename object_traits<T>::shared_ptr& obj (p); + + session& s (transaction::current ().session ()); + return s.persist<T> (*this, obj); + } + + template <typename T> + typename object_traits<T>::shared_ptr database:: + load (typename object_traits<T>::id_type const& id) + { + typename object_traits<T>::shared_ptr r (find<T> (id)); + + if (object_traits<T>::shared_ops::null_ptr (r)) + throw object_not_persistent (); + + return r; + } + + template <typename T> + typename object_traits<T>::shared_ptr database:: + find (typename object_traits<T>::id_type const& id) + { + session& s (transaction::current ().session ()); + return s.find<T> (*this, id); + } + + template <typename T, template <typename> class P> + void database:: + erase (P<T> p) + { + // P<T> should be the same or convertible to + // object_traits<T>::shared_ptr. + // + const typename object_traits<T>::shared_ptr& obj (p); + + session& s (transaction::current ().session ()); + return s.erase (*this, obj); + } + + template <typename T, template <typename> class P> + void database:: + modified (P<T> p) + { + // P<T> should be the same or convertible to + // object_traits<T>::shared_ptr. + // + const typename object_traits<T>::shared_ptr& obj (p); + + session& s (transaction::current ().session ()); + return s.modified (obj); + } +} |