aboutsummaryrefslogtreecommitdiff
path: root/odb/oracle/statement-cache.hxx
diff options
context:
space:
mode:
authorConstantin Michael <constantin@codesynthesis.com>2011-09-16 10:39:36 +0200
committerConstantin Michael <constantin@codesynthesis.com>2011-09-19 10:35:17 +0200
commit946c283a971f09a4d1f72066d17a684f62f51d88 (patch)
treee34091b61f757aae17d9066b4e425175c44601f4 /odb/oracle/statement-cache.hxx
parenta5510b8f0ef6d5aa7cce21a719de726b669aa394 (diff)
Add container-statements, object-statments, view-statements and statement cache
Diffstat (limited to 'odb/oracle/statement-cache.hxx')
-rw-r--r--odb/oracle/statement-cache.hxx85
1 files changed, 85 insertions, 0 deletions
diff --git a/odb/oracle/statement-cache.hxx b/odb/oracle/statement-cache.hxx
new file mode 100644
index 0000000..50b0744
--- /dev/null
+++ b/odb/oracle/statement-cache.hxx
@@ -0,0 +1,85 @@
+// file : odb/oracle/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_ORACLE_STATEMENT_CACHE_HXX
+#define ODB_ORACLE_STATEMENT_CACHE_HXX
+
+#include <odb/pre.hxx>
+
+#include <map>
+#include <typeinfo>
+
+#include <odb/forward.hxx>
+
+#include <odb/oracle/version.hxx>
+#include <odb/oracle/statements-base.hxx>
+#include <odb/oracle/object-statements.hxx>
+#include <odb/oracle/view-statements.hxx>
+
+#include <odb/details/shared-ptr.hxx>
+#include <odb/details/type-info.hxx>
+
+#include <odb/oracle/details/export.hxx>
+
+namespace odb
+{
+ namespace oracle
+ {
+ class connection;
+
+ class LIBODB_ORACLE_EXPORT statement_cache
+ {
+ public:
+ statement_cache (connection& conn)
+ : conn_ (conn)
+ {
+ }
+
+ template <typename T>
+ object_statements<T>&
+ find_object ()
+ {
+ 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;
+ }
+
+ template <typename T>
+ view_statements<T>&
+ 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;
+ }
+
+ private:
+ typedef std::map<const std::type_info*,
+ details::shared_ptr<statements_base>,
+ details::type_info_comparator> map;
+
+ connection& conn_;
+ map map_;
+ };
+ }
+}
+
+#include <odb/post.hxx>
+
+#endif // ODB_ORACLE_STATEMENT_CACHE_HXX