From be5909a7fc240c007bb0128353d493af947a8749 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 22 Mar 2011 16:22:06 +0200 Subject: Add object and container statement caches --- odb/sqlite/container-statements.hxx | 179 ++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 odb/sqlite/container-statements.hxx (limited to 'odb/sqlite/container-statements.hxx') diff --git a/odb/sqlite/container-statements.hxx b/odb/sqlite/container-statements.hxx new file mode 100644 index 0000000..a114990 --- /dev/null +++ b/odb/sqlite/container-statements.hxx @@ -0,0 +1,179 @@ +// file : odb/sqlite/container-statements.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_SQLITE_CONTAINER_STATEMENTS_HXX +#define ODB_SQLITE_CONTAINER_STATEMENTS_HXX + +#include + +#include +#include + +#include +#include +#include +#include + +namespace odb +{ + namespace sqlite + { + class connection; + + // Template argument is the generated container traits type. + // + template + class container_statements + { + public: + typedef T traits; + + typedef typename traits::id_image_type id_image_type; + typedef typename traits::data_image_type data_image_type; + typedef typename traits::cond_image_type cond_image_type; + + typedef typename traits::functions_type functions_type; + + typedef sqlite::insert_statement insert_statement_type; + typedef sqlite::select_statement select_statement_type; + typedef sqlite::delete_statement delete_statement_type; + + typedef sqlite::connection connection_type; + + container_statements (connection_type&); + + connection_type& + connection () + { + return conn_; + } + + // Functions. + // + functions_type& + functions () + { + return functions_; + } + + // Id image (external). + // + id_image_type& + id_image () + { + return *id_image_; + } + + void + id_image (id_image_type& i) + { + id_image_ = &i; + } + + // Condition image. + // + cond_image_type& + cond_image () + { + return cond_image_; + } + + binding& + cond_image_binding () + { + return cond_image_binding_; + } + + // Data image. + // + data_image_type& + data_image () + { + return data_image_; + } + + binding& + data_image_binding () + { + return data_image_binding_; + } + + bool* + data_image_truncated () + { + return data_image_truncation_; + } + + // + // Statements. + // + + insert_statement_type& + insert_one_statement () + { + if (insert_one_ == 0) + insert_one_.reset ( + new (details::shared) insert_statement_type ( + conn_, traits::insert_one_statement, data_image_binding_)); + + return *insert_one_; + } + + select_statement_type& + select_all_statement () + { + if (select_all_ == 0) + select_all_.reset ( + new (details::shared) select_statement_type ( + conn_, + traits::select_all_statement, + cond_image_binding_, + data_image_binding_)); + + return *select_all_; + } + + delete_statement_type& + delete_all_statement () + { + if (delete_all_ == 0) + delete_all_.reset ( + new (details::shared) delete_statement_type ( + conn_, traits::delete_all_statement, cond_image_binding_)); + + return *delete_all_; + } + + private: + container_statements (const container_statements&); + container_statements& operator= (const container_statements&); + + private: + connection_type& conn_; + functions_type functions_; + + id_image_type* id_image_; + + cond_image_type cond_image_; + binding cond_image_binding_; + bind cond_image_bind_[traits::cond_column_count]; + + data_image_type data_image_; + binding data_image_binding_; + bind data_image_bind_[traits::data_column_count]; + bool data_image_truncated_[traits::data_column_count]; + + details::shared_ptr insert_one_; + details::shared_ptr select_all_; + details::shared_ptr delete_all_; + }; + } +} + +#include + +#include + +#endif // ODB_SQLITE_CONTAINER_STATEMENTS_HXX -- cgit v1.1