aboutsummaryrefslogtreecommitdiff
path: root/odb/mysql/statement-cache.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-11-06 18:00:43 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-11-06 18:00:43 +0200
commit5daaa1a6d9c8f5d3a4ad3d7009df564bc6506424 (patch)
treeb96d205208587208a4e443be192fe264d2f53d57 /odb/mysql/statement-cache.hxx
parent6fd2fb44263eb6704905cddcc607462c21c5e687 (diff)
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.
Diffstat (limited to 'odb/mysql/statement-cache.hxx')
-rw-r--r--odb/mysql/statement-cache.hxx83
1 files changed, 83 insertions, 0 deletions
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 <boris@codesynthesis.com>
+// 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 <odb/pre.hxx>
+
+#include <map>
+#include <typeinfo>
+
+#include <odb/forward.hxx>
+
+#include <odb/mysql/version.hxx>
+#include <odb/mysql/object-statements.hxx>
+
+#include <odb/details/shared-ptr.hxx>
+
+#include <odb/mysql/details/export.hxx>
+
+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 <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>,
+ type_info_comparator> map;
+
+ connection& conn_;
+ map map_;
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_MYSQL_STATEMENT_CACHE_HXX