aboutsummaryrefslogtreecommitdiff
path: root/odb/pgsql/statement-cache.hxx
diff options
context:
space:
mode:
authorConstantin Michael <constantin@codesynthesis.com>2011-05-27 15:23:10 +0200
committerConstantin Michael <constantin@codesynthesis.com>2011-05-27 15:23:10 +0200
commit88f6ae3ce895a85f47178531cfed3632e5722160 (patch)
tree0b09d1a7ec0939e25c52c65f166cfc105db98ce8 /odb/pgsql/statement-cache.hxx
parentb2a4611002813c7a89849aefc498eee7221708e3 (diff)
Add statement-cache and enable relevant functionality in connection
Diffstat (limited to 'odb/pgsql/statement-cache.hxx')
-rw-r--r--odb/pgsql/statement-cache.hxx67
1 files changed, 67 insertions, 0 deletions
diff --git a/odb/pgsql/statement-cache.hxx b/odb/pgsql/statement-cache.hxx
new file mode 100644
index 0000000..8164cd8
--- /dev/null
+++ b/odb/pgsql/statement-cache.hxx
@@ -0,0 +1,67 @@
+// file : odb/pgsql/statement-cache.hxx
+// author : Constantin Michael <constantin@codesynthesis.com>
+// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef ODB_PGSQL_STATEMENT_CACHE_HXX
+#define ODB_PGSQL_STATEMENT_CACHE_HXX
+
+#include <odb/pre.hxx>
+
+#include <map>
+#include <typeinfo>
+
+#include <odb/forward.hxx>
+
+#include <odb/pgsql/version.hxx>
+#include <odb/pgsql/object-statements.hxx>
+
+#include <odb/details/shared-ptr.hxx>
+#include <odb/details/type-info.hxx>
+
+#include <odb/pgsql/details/export.hxx>
+
+namespace odb
+{
+ namespace pgsql
+ {
+ class connection;
+
+ class LIBODB_PGSQL_EXPORT statement_cache
+ {
+ public:
+ statement_cache (connection& conn)
+ : conn_ (conn)
+ {
+ }
+
+ template <typename T>
+ object_statements<T>&
+ find ()
+ {
+ map::iterator i (map_.find (&typeid (T)));
+
+ if (i != map_.end ())
+ return static_cast<object_statements<T>&> (*i->second);
+
+ details::shared_ptr<object_statements<T> > p (
+ new (details::shared) object_statements<T> (conn_));
+
+ map_.insert (map::value_type (&typeid (T), p));
+ return *p;
+ }
+
+ private:
+ typedef std::map<const std::type_info*,
+ details::shared_ptr<object_statements_base>,
+ details::type_info_comparator> map;
+
+ connection& conn_;
+ map map_;
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_PGSQL_STATEMENT_CACHE_HXX