From 0745f84e2d5c7133f6ee6608487089d69d7ad519 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 6 May 2013 12:05:39 +0200 Subject: Add support for object sections Sections are an optimization mechanism that allows the partitioning of data members of a persistent class into groups that can be separately loaded and/or updated. --- odb/pgsql/section-statements.hxx | 203 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 odb/pgsql/section-statements.hxx (limited to 'odb/pgsql/section-statements.hxx') diff --git a/odb/pgsql/section-statements.hxx b/odb/pgsql/section-statements.hxx new file mode 100644 index 0000000..b2f5c7b --- /dev/null +++ b/odb/pgsql/section-statements.hxx @@ -0,0 +1,203 @@ +// file : odb/pgsql/section-statements.hxx +// copyright : Copyright (c) 2005-2013 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_SECTION_STATEMENTS_HXX +#define ODB_PGSQL_SECTION_STATEMENTS_HXX + +#include + +#include // std::size_t + +#include +#include + +#include +#include +#include +#include // Oid +#include + +namespace odb +{ + namespace pgsql + { + class connection; + + // Template argument is the section traits type. + // + template + class section_statements + { + public: + typedef ST traits; + + typedef typename traits::image_type image_type; + + typedef pgsql::select_statement select_statement_type; + typedef pgsql::update_statement update_statement_type; + + typedef pgsql::connection connection_type; + + section_statements (connection_type&, + image_type&, + binding& id, + binding& idv, + native_binding& idn, + const Oid* idt); + + connection_type& + connection () {return conn_;} + + image_type& + image () {return image_;} + + const binding& + id_binding () {return id_binding_;} + + // Id and optimistic concurrency version (if any). + // + const binding& + idv_binding () {return idv_binding_;} + + // Select binding. + // + std::size_t + select_image_version () const { return select_image_version_;} + + void + select_image_version (std::size_t v) {select_image_version_ = v;} + + binding& + select_image_binding () {return select_image_binding_;} + + bool* + select_image_truncated () {return select_image_truncated_;} + + // Update binding. + // + std::size_t + update_image_version () const { return update_image_version_;} + + void + update_image_version (std::size_t v) {update_image_version_ = v;} + + std::size_t + update_id_binding_version () const { return update_id_binding_version_;} + + void + update_id_binding_version (std::size_t v) {update_id_binding_version_ = v;} + + binding& + update_image_binding () {return update_image_binding_;} + + // + // Statements. + // + + select_statement_type& + select_statement () + { + if (select_ == 0) + select_.reset ( + new (details::shared) select_statement_type ( + conn_, + traits::select_name, + traits::select_statement, + id_types_, + id_column_count, + id_binding_, + id_native_binding_, + select_image_binding_, + false)); + + return *select_; + } + + update_statement_type& + update_statement () + { + if (update_ == 0) + update_.reset ( + new (details::shared) update_statement_type ( + conn_, + traits::update_name, + traits::update_statement, + traits::update_types, + update_column_count + id_column_count + + managed_optimistic_update_column_count, + update_image_binding_, + update_image_native_binding_, + false)); + + return *update_; + } + + public: + static const std::size_t id_column_count = traits::id_column_count; + static const std::size_t managed_optimistic_load_column_count = + traits::managed_optimistic_load_column_count; + static const std::size_t managed_optimistic_update_column_count = + traits::managed_optimistic_update_column_count; + static const std::size_t select_column_count = traits::load_column_count; + static const std::size_t update_column_count = + traits::update_column_count; + + private: + section_statements (const section_statements&); + section_statements& operator= (const section_statements&); + + protected: + connection_type& conn_; + + // These come from object_statements. + // + image_type& image_; + binding& id_binding_; + binding& idv_binding_; + native_binding& id_native_binding_; + const Oid* id_types_; + + // Select binding. + // + std::size_t select_image_version_; + + static const std::size_t select_bind_count = + select_column_count != 0 || managed_optimistic_load_column_count != 0 + ? select_column_count + managed_optimistic_load_column_count + : 1; + + binding select_image_binding_; + bind select_image_bind_[select_bind_count]; + bool select_image_truncated_[select_bind_count]; + + // Update binding. + // + std::size_t update_image_version_; + std::size_t update_id_binding_version_; + + static const std::size_t update_bind_count = + update_column_count != 0 || managed_optimistic_update_column_count != 0 + ? update_column_count + id_column_count + + managed_optimistic_update_column_count + : 1; + + binding update_image_binding_; + bind update_image_bind_[update_bind_count]; + + native_binding update_image_native_binding_; + char* update_image_values_[update_bind_count]; + int update_image_lengths_[update_bind_count]; + int update_image_formats_[update_bind_count]; + + details::shared_ptr select_; + details::shared_ptr update_; + }; + } +} + +#include + +#include + +#endif // ODB_PGSQL_SECTION_STATEMENTS_HXX -- cgit v1.1