aboutsummaryrefslogtreecommitdiff
path: root/odb/database.txx
diff options
context:
space:
mode:
Diffstat (limited to 'odb/database.txx')
-rw-r--r--odb/database.txx99
1 files changed, 47 insertions, 52 deletions
diff --git a/odb/database.txx b/odb/database.txx
index 7ac19d7..23ea712 100644
--- a/odb/database.txx
+++ b/odb/database.txx
@@ -10,13 +10,30 @@
namespace odb
{
template <typename T>
+ result<T> database::
+ query (const odb::query<T>& q, bool cache)
+ {
+ // T is always object_type. We also don't need to check for transaction
+ // here; object_traits::query () does this.
+ //
+ result<T> r (query_<T, id_default>::call (*this, q));
+
+ if (cache)
+ r.cache ();
+
+ return r;
+ }
+
+ // Implementations (i.e., the *_() functions).
+ //
+ template <typename T, database_id DB>
typename object_traits<T>::id_type database::
- persist (T& obj)
+ persist_ (T& obj)
{
// T can be const T while object_type will always be T.
//
- typedef typename odb::object_traits<T>::object_type object_type;
- typedef odb::object_traits<object_type> object_traits;
+ typedef typename object_traits<T>::object_type object_type;
+ typedef object_traits_impl<object_type, DB> object_traits;
object_traits::persist (*this, obj);
@@ -26,19 +43,18 @@ namespace odb
return object_traits::id (obj);
}
- template <typename T>
+ template <typename T, database_id DB>
typename object_traits<T>::id_type database::
persist_ (const typename object_traits<T>::pointer_type& pobj)
{
// T can be const T while object_type will always be T.
//
- typedef typename odb::object_traits<T>::object_type object_type;
- typedef odb::object_traits<object_type> object_traits;
+ typedef typename object_traits<T>::object_type object_type;
+ typedef typename object_traits<T>::pointer_type pointer_type;
- typedef typename odb::object_traits<T>::pointer_type pointer_type;
- typedef odb::pointer_traits<pointer_type> pointer_traits;
+ typedef object_traits_impl<object_type, DB> object_traits;
- T& obj (pointer_traits::get_ref (pobj));
+ T& obj (pointer_traits<pointer_type>::get_ref (pobj));
object_traits::persist (*this, obj);
// Get the canonical object pointer and insert it into object cache.
@@ -49,81 +65,60 @@ namespace odb
return object_traits::id (obj);
}
- template <typename T>
+ template <typename T, database_id DB>
typename object_traits<T>::pointer_type database::
- load (const typename object_traits<T>::id_type& id)
+ load_ (const typename object_traits<T>::id_type& id)
{
// T is always object_type.
//
typedef typename object_traits<T>::pointer_type pointer_type;
- typedef odb::pointer_traits<pointer_type> pointer_traits;
- pointer_type r (find<T> (id));
+ pointer_type r (find_<T, DB> (id));
- if (pointer_traits::null_ptr (r))
+ if (pointer_traits<pointer_type>::null_ptr (r))
throw object_not_persistent ();
return r;
}
- template <typename T>
+ template <typename T, database_id DB>
void database::
- load (const typename object_traits<T>::id_type& id, T& obj)
+ load_ (const typename object_traits<T>::id_type& id, T& obj)
{
- if (!find<T> (id, obj))
+ if (!find_<T, DB> (id, obj))
throw object_not_persistent ();
}
- template <typename T>
+ template <typename T, database_id DB>
void database::
- reload (T& obj)
+ reload_ (T& obj)
{
- // T should be object_type (cannot be const).
+ // T should be object_type (cannot be const). We also don't need to
+ // check for transaction here; object_traits::reload () does this.
//
- typedef odb::object_traits<T> object_traits;
-
- // We don't need to check for transaction here;
- // object_traits::reload () does this.
-
- if (!object_traits::reload (*this, obj))
+ if (!object_traits_impl<T, DB>::reload (*this, obj))
throw object_not_persistent ();
}
- template <typename T>
- struct database::query_<T, class_object>
+ template <typename T, database_id DB>
+ struct database::query_<T, DB, class_object>
{
+ template <typename Q>
static result<T>
- call (database& db, const odb::query<T>& q)
+ call (database& db, const Q& q)
{
- return object_traits<T>::query (db, q);
+ return object_traits_impl<T, DB>::query (db, q);
}
};
- template <typename T>
- struct database::query_<T, class_view>
+ template <typename T, database_id DB>
+ struct database::query_<T, DB, class_view>
{
+ template <typename Q>
static result<T>
- call (database& db, const odb::query<T>& q)
+ call (database& db, const Q& q)
{
- return view_traits<T>::query (db, q);
+ return view_traits_impl<T, DB>::query (db, q);
}
};
-
- template <typename T>
- result<T> database::
- query (const odb::query<T>& q, bool cache)
- {
- // T is always object_type.
- //
-
- // We don't need to check for transaction here;
- // object_traits::query () does this.
-
- result<T> r (query_<T, class_traits<T>::kind>::call (*this, q));
-
- if (cache)
- r.cache ();
-
- return r;
- }
}