From 88f6ae3ce895a85f47178531cfed3632e5722160 Mon Sep 17 00:00:00 2001 From: Constantin Michael Date: Fri, 27 May 2011 15:23:10 +0200 Subject: Add statement-cache and enable relevant functionality in connection --- odb/pgsql/statement-cache.hxx | 67 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 odb/pgsql/statement-cache.hxx (limited to 'odb/pgsql/statement-cache.hxx') 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 +// 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 + +#include +#include + +#include + +#include +#include + +#include +#include + +#include + +namespace odb +{ + namespace pgsql + { + class connection; + + class LIBODB_PGSQL_EXPORT statement_cache + { + public: + statement_cache (connection& conn) + : conn_ (conn) + { + } + + template + object_statements& + find () + { + map::iterator i (map_.find (&typeid (T))); + + if (i != map_.end ()) + return static_cast&> (*i->second); + + details::shared_ptr > p ( + new (details::shared) object_statements (conn_)); + + map_.insert (map::value_type (&typeid (T), p)); + return *p; + } + + private: + typedef std::map, + details::type_info_comparator> map; + + connection& conn_; + map map_; + }; + } +} + +#include + +#endif // ODB_PGSQL_STATEMENT_CACHE_HXX -- cgit v1.1