// 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 namespace odb { template typename object_traits::id_type database:: persist (const T& obj) { typedef object_traits traits; if (!transaction::has_current ()) throw not_in_transaction (); traits::persist (*this, obj); return traits::id (obj); } template typename object_traits::id_type database:: persist (T& obj) { typedef object_traits traits; if (!transaction::has_current ()) throw not_in_transaction (); traits::persist (*this, obj); return traits::id (obj); } template typename object_traits::pointer_type database:: load (const typename object_traits::id_type& id) { typedef object_traits traits; typename traits::pointer_type r (find (id)); if (traits::pointer_traits::null_ptr (r)) throw object_not_persistent (); return r; } template void database:: load (const typename object_traits::id_type& id, T& obj) { if (!find (id, obj)) throw object_not_persistent (); } template typename object_traits::pointer_type database:: find (const typename object_traits::id_type& id) { if (!transaction::has_current ()) throw not_in_transaction (); // Compiler error pointing here? Perhaps the object doesn't have the // default constructor? // return object_traits::find (*this, id); } template bool database:: find (const typename object_traits::id_type& id, T& obj) { if (!transaction::has_current ()) throw not_in_transaction (); return object_traits::find (*this, id, obj); } template void database:: update (const T& obj) { if (!transaction::has_current ()) throw not_in_transaction (); object_traits::update (*this, obj); } template void database:: erase (const typename object_traits::id_type& id) { if (!transaction::has_current ()) throw not_in_transaction (); object_traits::erase (*this, id); } template result database:: query (const odb::query& q, bool cache) { if (!transaction::has_current ()) throw not_in_transaction (); result r (object_traits::query (*this, q)); if (cache) r.cache (); return r; } }