diff options
Diffstat (limited to 'odb/oracle/container-statements.hxx')
-rw-r--r-- | odb/oracle/container-statements.hxx | 269 |
1 files changed, 167 insertions, 102 deletions
diff --git a/odb/oracle/container-statements.hxx b/odb/oracle/container-statements.hxx index 9ebcd46..62729a6 100644 --- a/odb/oracle/container-statements.hxx +++ b/odb/oracle/container-statements.hxx @@ -34,8 +34,6 @@ namespace odb typedef T traits; 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 oracle::insert_statement insert_statement_type; @@ -44,7 +42,7 @@ namespace odb typedef oracle::connection connection_type; - container_statements (connection_type&); + container_statements (connection_type&, binding& id_binding); connection_type& connection () @@ -65,169 +63,222 @@ namespace odb const binding& id_binding () { - return *id_binding_; + return id_binding_; } - void - id_binding (const binding& b) + // Data image. The image is split into the id (that comes as a + // binding) and index/key plus value which are in data_image_type. + // The select binding is a subset of the full binding (no id). + // + data_image_type& + data_image () { - id_binding_ = &b; + return data_image_; } - // Condition image. - // - cond_image_type& - cond_image () + bind* + data_bind () { - return cond_image_; + return insert_image_binding_.bind; } - std::size_t - cond_image_version () const + bool + data_binding_test_version () const { - return cond_image_version_; + return data_id_binding_version_ != id_binding_.version || + data_image_version_ != data_image_.version || + insert_image_binding_.version == 0; } void - cond_image_version (std::size_t v) + data_binding_update_version () { - cond_image_version_ = v; + data_id_binding_version_ = id_binding_.version; + data_image_version_ = data_image_.version; + insert_image_binding_.version++; + select_image_binding_.version++; } - std::size_t - cond_id_binding_version () const + // + // Statements. + // + + insert_statement_type& + insert_statement () { - return cond_id_binding_version_; + if (insert_ == 0) + insert_.reset ( + new (details::shared) insert_statement_type ( + conn_, insert_text_, insert_image_binding_, false)); + + return *insert_; } - void - cond_id_binding_version (std::size_t v) + select_statement_type& + select_statement () { - cond_id_binding_version_ = v; + if (select_ == 0) + select_.reset ( + new (details::shared) select_statement_type ( + conn_, + select_text_, + id_binding_, + select_image_binding_, + 4096)); // Hardcode a 4kB LOB prefetch size. + + return *select_; } - binding& - cond_image_binding () + delete_statement_type& + delete_statement () { - return cond_image_binding_; + if (delete_ == 0) + delete_.reset ( + new (details::shared) delete_statement_type ( + conn_, delete_text_, id_binding_)); + + return *delete_; } - // Data image. + private: + container_statements (const container_statements&); + container_statements& operator= (const container_statements&); + + protected: + connection_type& conn_; + binding& id_binding_; + + functions_type functions_; + + data_image_type data_image_; + std::size_t data_image_version_; + std::size_t data_id_binding_version_; + + binding insert_image_binding_; + binding select_image_binding_; + + const char* insert_text_; + const char* select_text_; + const char* delete_text_; + + details::shared_ptr<insert_statement_type> insert_; + details::shared_ptr<select_statement_type> select_; + details::shared_ptr<delete_statement_type> delete_; + }; + + template <typename T> + class smart_container_statements: public container_statements<T> + { + public: + typedef T traits; + typedef typename traits::cond_image_type cond_image_type; + + typedef oracle::update_statement update_statement_type; + typedef oracle::delete_statement delete_statement_type; + + typedef oracle::connection connection_type; + + smart_container_statements (connection_type&, binding& id_binding); + + // Condition image. The image is split into the id (that comes as + // a binding) and index/key/value which is in cond_image_type. // - data_image_type& - data_image () + cond_image_type& + cond_image () { - return data_image_; + return cond_image_; } - std::size_t - data_image_version () const + bind* + cond_bind () { - return data_image_version_; + return cond_image_binding_.bind; } - void - data_image_version (std::size_t v) + bool + cond_binding_test_version () const { - data_image_version_ = v; + return cond_id_binding_version_ != this->id_binding_.version || + cond_image_version_ != cond_image_.version || + cond_image_binding_.version == 0; } - std::size_t - data_id_binding_version () const + void + cond_binding_update_version () { - return data_id_binding_version_; + cond_id_binding_version_ = this->id_binding_.version; + cond_image_version_ = cond_image_.version; + cond_image_binding_.version++; } - void - data_id_binding_version (std::size_t v) + // Update image. The image is split as follows: value comes + // from the data image, id comes as binding, and index/key + // comes from the condition image. + // + bind* + update_bind () { - data_id_binding_version_ = v; + return update_image_binding_.bind; } - binding& - data_image_binding () + bool + update_binding_test_version () const { - return data_image_binding_; + return update_id_binding_version_ != this->id_binding_.version || + update_cond_image_version_ != cond_image_.version || + update_data_image_version_ != this->data_image_.version || + update_image_binding_.version == 0; } - binding& - select_image_binding () + void + update_binding_update_version () { - return select_image_binding_; + update_id_binding_version_ = this->id_binding_.version; + update_cond_image_version_ = cond_image_.version; + update_data_image_version_ = this->data_image_.version; + update_image_binding_.version++; } // // Statements. // - insert_statement_type& - insert_one_statement () - { - // Containers never use auto ids so hardcode the insert_statement - // constructors returning argument as false. - // - if (insert_one_ == 0) - insert_one_.reset ( - new (details::shared) insert_statement_type ( - conn_, insert_one_text_, data_image_binding_, false)); - - return *insert_one_; - } - - select_statement_type& - select_all_statement () + delete_statement_type& + delete_statement () { - if (select_all_ == 0) - select_all_.reset ( - new (details::shared) select_statement_type ( - conn_, - select_all_text_, - cond_image_binding_, - select_image_binding_, - 4096)); // Hardcode a 4kB LOB prefetch size. + if (this->delete_ == 0) + this->delete_.reset ( + new (details::shared) delete_statement_type ( + this->conn_, this->delete_text_, this->cond_image_binding_)); - return *select_all_; + return *this->delete_; } - delete_statement_type& - delete_all_statement () + update_statement_type& + update_statement () { - if (delete_all_ == 0) - delete_all_.reset ( - new (details::shared) delete_statement_type ( - conn_, delete_all_text_, cond_image_binding_)); + if (update_ == 0) + update_.reset ( + new (details::shared) update_statement_type ( + this->conn_, update_text_, update_image_binding_)); - return *delete_all_; + return *update_; } - private: - container_statements (const container_statements&); - container_statements& operator= (const container_statements&); - protected: - connection_type& conn_; - functions_type functions_; - - const binding* id_binding_; - cond_image_type cond_image_; std::size_t cond_image_version_; std::size_t cond_id_binding_version_; binding cond_image_binding_; - data_image_type data_image_; - std::size_t data_image_version_; - std::size_t data_id_binding_version_; - binding data_image_binding_; - binding select_image_binding_; // Skips the id from data_image_binding. + std::size_t update_id_binding_version_; + std::size_t update_cond_image_version_; + std::size_t update_data_image_version_; + binding update_image_binding_; - const char* insert_one_text_; - const char* select_all_text_; - const char* delete_all_text_; + const char* update_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_; + details::shared_ptr<update_statement_type> update_; }; // Template argument is the generated concrete container traits type. @@ -240,16 +291,30 @@ namespace odb typedef typename T::statements_type base; typedef oracle::connection connection_type; - container_statements_impl (connection_type&); + container_statements_impl (connection_type&, binding&); private: container_statements_impl (const container_statements_impl&); container_statements_impl& operator= (const container_statements_impl&); private: - bind cond_image_bind_[traits::cond_column_count]; bind data_image_bind_[traits::data_column_count]; }; + + template <typename T> + class smart_container_statements_impl: public container_statements_impl<T> + { + public: + typedef T traits; + typedef oracle::connection connection_type; + + smart_container_statements_impl (connection_type&, binding&); + + private: + bind cond_image_bind_[traits::cond_column_count]; + bind update_image_bind_[traits::value_column_count + + traits::cond_column_count]; + }; } } |