diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-04-25 11:29:06 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-04-25 11:29:06 +0200 |
commit | dd4d4ddadaa2aa6a74ca46106d53e55505c68110 (patch) | |
tree | 5eb7cd08aee6281cd14d3ace630e486f48781b97 | |
parent | 7998e33d631f969052503f18d435f3a52d1a1da4 (diff) |
Reuse container traits from base objects
-rw-r--r-- | odb/mysql/container-statements.hxx | 42 | ||||
-rw-r--r-- | odb/mysql/container-statements.txx | 34 |
2 files changed, 62 insertions, 14 deletions
diff --git a/odb/mysql/container-statements.hxx b/odb/mysql/container-statements.hxx index a5e93a1..7124be7 100644 --- a/odb/mysql/container-statements.hxx +++ b/odb/mysql/container-statements.hxx @@ -25,7 +25,8 @@ namespace odb { class connection; - // Template argument is the generated container traits type. + // Template argument is the generated abstract container traits type. + // That is, it doesn't need to provide column counts and statements. // template <typename T> class container_statements @@ -166,7 +167,7 @@ namespace odb if (insert_one_ == 0) insert_one_.reset ( new (details::shared) insert_statement_type ( - conn_, traits::insert_one_statement, data_image_binding_)); + conn_, insert_one_text_, data_image_binding_)); return *insert_one_; } @@ -178,7 +179,7 @@ namespace odb select_all_.reset ( new (details::shared) select_statement_type ( conn_, - traits::select_all_statement, + select_all_text_, cond_image_binding_, data_image_binding_)); @@ -191,7 +192,7 @@ namespace odb if (delete_all_ == 0) delete_all_.reset ( new (details::shared) delete_statement_type ( - conn_, traits::delete_all_statement, cond_image_binding_)); + conn_, delete_all_text_, cond_image_binding_)); return *delete_all_; } @@ -200,7 +201,7 @@ namespace odb container_statements (const container_statements&); container_statements& operator= (const container_statements&); - private: + protected: connection_type& conn_; functions_type functions_; @@ -210,19 +211,44 @@ namespace odb std::size_t cond_image_version_; std::size_t cond_id_binding_version_; binding cond_image_binding_; - MYSQL_BIND cond_image_bind_[traits::cond_column_count]; + MYSQL_BIND* cond_image_bind_; data_image_type data_image_; std::size_t data_image_version_; std::size_t data_id_binding_version_; binding data_image_binding_; - MYSQL_BIND data_image_bind_[traits::data_column_count]; - my_bool data_image_truncated_[traits::data_column_count]; + MYSQL_BIND* data_image_bind_; + my_bool* data_image_truncated_; + + const char* insert_one_text_; + const char* select_all_text_; + const char* delete_all_text_; details::shared_ptr<insert_statement_type> insert_one_; details::shared_ptr<select_statement_type> select_all_; details::shared_ptr<delete_statement_type> delete_all_; }; + + // Template argument is the generated concrete container traits type. + // + template <typename T> + class container_statements_impl: public T::statements_type + { + public: + typedef T traits; + typedef typename T::statements_type base; + + container_statements_impl (connection&); + + private: + container_statements_impl (const container_statements_impl&); + container_statements_impl& operator= (const container_statements_impl&); + + private: + MYSQL_BIND cond_image_bind_array_[traits::cond_column_count]; + MYSQL_BIND data_image_bind_array_[traits::data_column_count]; + my_bool data_image_truncated_array_[traits::data_column_count]; + }; } } diff --git a/odb/mysql/container-statements.txx b/odb/mysql/container-statements.txx index ba6827c..a651bd4 100644 --- a/odb/mysql/container-statements.txx +++ b/odb/mysql/container-statements.txx @@ -22,8 +22,8 @@ namespace odb &traits::load_all, &traits::delete_all), id_binding_ (0), - cond_image_binding_ (cond_image_bind_, traits::cond_column_count), - data_image_binding_ (data_image_bind_, traits::data_column_count) + cond_image_binding_ (0, 0), // Initialized by impl. + data_image_binding_ (0, 0) // Initialized by impl. { cond_image_.version = 0; cond_image_version_ = 0; @@ -32,13 +32,35 @@ namespace odb data_image_.version = 0; data_image_version_ = 0; data_id_binding_version_ = 0; + } + + template <typename T> + container_statements_impl<T>:: + container_statements_impl (connection& conn) + : base (conn) + { + this->cond_image_bind_ = cond_image_bind_array_; + this->data_image_bind_ = data_image_bind_array_; + this->data_image_truncated_ = data_image_truncated_array_; - std::memset (cond_image_bind_, 0, sizeof (cond_image_bind_)); - std::memset (data_image_bind_, 0, sizeof (data_image_bind_)); - std::memset (data_image_truncated_, 0, sizeof (data_image_truncated_)); + this->cond_image_binding_.bind = this->cond_image_bind_; + this->cond_image_binding_.count = traits::cond_column_count; + + this->data_image_binding_.bind = this->data_image_bind_; + this->data_image_binding_.count = traits::data_column_count; + + std::memset (cond_image_bind_array_, 0, sizeof (cond_image_bind_array_)); + std::memset (data_image_bind_array_, 0, sizeof (data_image_bind_array_)); + std::memset (data_image_truncated_array_, + 0, + sizeof (data_image_truncated_array_)); for (std::size_t i (0); i < traits::data_column_count; ++i) - data_image_bind_[i].error = data_image_truncated_ + i; + data_image_bind_array_[i].error = data_image_truncated_array_ + i; + + this->insert_one_text_ = traits::insert_one_statement; + this->select_all_text_ = traits::select_all_statement; + this->delete_all_text_ = traits::delete_all_statement; } } } |