aboutsummaryrefslogtreecommitdiff
path: root/odb/mysql/statement-cache.txx
blob: 0ac74a4a272eb9eea486930b686f8c331a30d2e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// file      : odb/mysql/statement-cache.txx
// copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC
// license   : GNU GPL v2; see accompanying LICENSE file

namespace odb
{
  namespace mysql
  {
    template <typename T>
    typename object_traits_impl<T, id_mysql>::statements_type&
    statement_cache::
    find_object ()
    {
      typedef
      typename object_traits_impl<T, id_mysql>::statements_type
      statements_type;

      map::iterator i (map_.find (&typeid (T)));

      if (i != map_.end ())
        return static_cast<statements_type&> (*i->second);

      details::shared_ptr<statements_type> p (
        new (details::shared) statements_type (conn_));

      map_.insert (map::value_type (&typeid (T), p));
      return *p;
    }

    template <typename T>
    view_statements<T>& statement_cache::
    find_view ()
    {
      map::iterator i (map_.find (&typeid (T)));

      if (i != map_.end ())
        return static_cast<view_statements<T>&> (*i->second);

      details::shared_ptr<view_statements<T> > p (
        new (details::shared) view_statements<T> (conn_));

      map_.insert (map::value_type (&typeid (T), p));
      return *p;
    }
  }
}