From 5daaa1a6d9c8f5d3a4ad3d7009df564bc6506424 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 6 Nov 2010 18:00:43 +0200 Subject: Add support for container persistence Generalize statements that were used for persisting objects to work for both objects and containers. Implement a cache for container statements. --- odb/mysql/statement-cache.hxx | 83 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 odb/mysql/statement-cache.hxx (limited to 'odb/mysql/statement-cache.hxx') diff --git a/odb/mysql/statement-cache.hxx b/odb/mysql/statement-cache.hxx new file mode 100644 index 0000000..480f30d --- /dev/null +++ b/odb/mysql/statement-cache.hxx @@ -0,0 +1,83 @@ +// file : odb/mysql/statement-cache.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_MYSQL_STATEMENT_CACHE_HXX +#define ODB_MYSQL_STATEMENT_CACHE_HXX + +#include + +#include +#include + +#include + +#include +#include + +#include + +#include + +namespace odb +{ + namespace mysql + { + class connection; + + struct LIBODB_MYSQL_EXPORT type_info_comparator + { + bool + operator() (const std::type_info* x, const std::type_info* y) const + { + // XL C++ on AIX has buggy type_info::before() in that + // it returns true for two different type_info objects + // that happened to be for the same type. + // +#if defined(__xlC__) && defined(_AIX) + return *x != *y && x->before (*y); +#else + return x->before (*y); +#endif + } + }; + + class LIBODB_MYSQL_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, + type_info_comparator> map; + + connection& conn_; + map map_; + }; + } +} + +#include + +#endif // ODB_MYSQL_STATEMENT_CACHE_HXX -- cgit v1.1