From 485ae35a88fe2500574797d7342cfa7585e9e191 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 4 Sep 2013 13:40:31 +0200 Subject: View versioning support --- odb/pgsql/no-id-object-result.hxx | 2 +- odb/pgsql/polymorphic-object-result.hxx | 2 +- odb/pgsql/polymorphic-object-result.txx | 4 +- odb/pgsql/polymorphic-object-statements.txx | 2 +- odb/pgsql/simple-object-result.hxx | 2 +- odb/pgsql/simple-object-statements.txx | 2 +- odb/pgsql/traits-calls.hxx | 81 +++++++++++++++++++++++++++-- odb/pgsql/view-result.hxx | 5 +- odb/pgsql/view-result.txx | 12 +++-- 9 files changed, 94 insertions(+), 18 deletions(-) diff --git a/odb/pgsql/no-id-object-result.hxx b/odb/pgsql/no-id-object-result.hxx index 83f3ce9..1fbdf75 100644 --- a/odb/pgsql/no-id-object-result.hxx +++ b/odb/pgsql/no-id-object-result.hxx @@ -64,7 +64,7 @@ namespace odb private: details::shared_ptr statement_; statements_type& statements_; - traits_calls tc_; + object_traits_calls tc_; std::size_t count_; }; } diff --git a/odb/pgsql/polymorphic-object-result.hxx b/odb/pgsql/polymorphic-object-result.hxx index acbfd43..db40e2e 100644 --- a/odb/pgsql/polymorphic-object-result.hxx +++ b/odb/pgsql/polymorphic-object-result.hxx @@ -81,7 +81,7 @@ namespace odb private: details::shared_ptr statement_; statements_type& statements_; - traits_calls tc_; + object_traits_calls tc_; std::size_t count_; }; } diff --git a/odb/pgsql/polymorphic-object-result.txx b/odb/pgsql/polymorphic-object-result.txx index d2504eb..c92a278 100644 --- a/odb/pgsql/polymorphic-object-result.txx +++ b/odb/pgsql/polymorphic-object-result.txx @@ -209,7 +209,7 @@ namespace odb if (traits::check_version (sts.select_image_versions (), im)) { binding& b (sts.select_image_binding (traits::depth)); - traits_calls tc (svm); + object_traits_calls tc (svm); tc.bind (b.bind, 0, 0, im, statement_select); traits::update_version ( sts.select_image_versions (), im, sts.select_image_bindings ()); @@ -236,7 +236,7 @@ namespace odb if (im.version != sts.select_image_version ()) { binding& b (sts.select_image_binding ()); - traits_calls tc (svm); + object_traits_calls tc (svm); tc.bind (b.bind, im, statement_select); sts.select_image_version (im.version); b.version++; diff --git a/odb/pgsql/polymorphic-object-statements.txx b/odb/pgsql/polymorphic-object-statements.txx index 694c3e9..f6b223b 100644 --- a/odb/pgsql/polymorphic-object-statements.txx +++ b/odb/pgsql/polymorphic-object-statements.txx @@ -138,7 +138,7 @@ namespace odb // The same code as in object_statements::load_delayed_(). // - traits_calls tc (svm); + object_traits_calls tc (svm); if (!tc.find_ (sts, &id)) throw object_not_persistent (); diff --git a/odb/pgsql/simple-object-result.hxx b/odb/pgsql/simple-object-result.hxx index e6a558b..add9db9 100644 --- a/odb/pgsql/simple-object-result.hxx +++ b/odb/pgsql/simple-object-result.hxx @@ -73,7 +73,7 @@ namespace odb private: details::shared_ptr statement_; statements_type& statements_; - traits_calls tc_; + object_traits_calls tc_; std::size_t count_; }; } diff --git a/odb/pgsql/simple-object-statements.txx b/odb/pgsql/simple-object-statements.txx index ae96008..9eb671b 100644 --- a/odb/pgsql/simple-object-statements.txx +++ b/odb/pgsql/simple-object-statements.txx @@ -114,7 +114,7 @@ namespace odb if (l.loader == 0) { - traits_calls tc (svm); + object_traits_calls tc (svm); if (!tc.find_ (static_cast (*this), &l.id)) throw object_not_persistent (); diff --git a/odb/pgsql/traits-calls.hxx b/odb/pgsql/traits-calls.hxx index ee91e62..5313596 100644 --- a/odb/pgsql/traits-calls.hxx +++ b/odb/pgsql/traits-calls.hxx @@ -20,18 +20,22 @@ namespace odb { namespace pgsql { + // + // object_traits_calls + // + template ::versioned> - struct traits_calls; + struct object_traits_calls; template - struct traits_calls + struct object_traits_calls { typedef object_traits_impl traits; typedef typename traits::image_type image_type; typedef pgsql::bind bind_type; - traits_calls (const schema_version_migration*) {} + object_traits_calls (const schema_version_migration*) {} const schema_version_migration* version () const {return 0;} @@ -80,13 +84,13 @@ namespace odb }; template - struct traits_calls + struct object_traits_calls { typedef object_traits_impl traits; typedef typename traits::image_type image_type; typedef pgsql::bind bind_type; - traits_calls (const schema_version_migration* svm): svm_ (*svm) {} + object_traits_calls (const schema_version_migration* svm): svm_ (*svm) {} const schema_version_migration* version () const {return &svm_;} @@ -136,6 +140,73 @@ namespace odb private: const schema_version_migration& svm_; }; + + // + // view_traits_calls + // + + template ::versioned> + struct view_traits_calls; + + template + struct view_traits_calls + { + typedef view_traits_impl traits; + typedef typename traits::image_type image_type; + typedef pgsql::bind bind_type; + + view_traits_calls (const schema_version_migration*) {} + + static bool + grow (image_type& i, bool* t) + { + return traits::grow (i, t); + } + + static void + bind (bind_type* b, image_type& i) + { + traits::bind (b, i); + } + + static void + init (T& o, const image_type& i, odb::database* db) + { + traits::init (o, i, db); + } + }; + + template + struct view_traits_calls + { + typedef view_traits_impl traits; + typedef typename traits::image_type image_type; + typedef pgsql::bind bind_type; + + view_traits_calls (const schema_version_migration* svm): svm_ (*svm) {} + + bool + grow (image_type& i, bool* t) const + { + return traits::grow (i, t, svm_); + } + + void + bind (bind_type* b, image_type& i) const + { + traits::bind (b, i, svm_); + } + + void + init (T& o, const image_type& i, odb::database* db) const + { + traits::init (o, i, db, svm_); + } + + private: + const schema_version_migration& svm_; + }; } } diff --git a/odb/pgsql/view-result.hxx b/odb/pgsql/view-result.hxx index 086be0e..2ca6195 100644 --- a/odb/pgsql/view-result.hxx +++ b/odb/pgsql/view-result.hxx @@ -9,6 +9,7 @@ #include // std::size_t +#include #include #include @@ -40,7 +41,8 @@ namespace odb view_result_impl (const query_base&, details::shared_ptr, - statements_type&); + statements_type&, + const schema_version_migration*); virtual void load (view_type&); @@ -62,6 +64,7 @@ namespace odb private: details::shared_ptr statement_; statements_type& statements_; + view_traits_calls tc_; std::size_t count_; }; } diff --git a/odb/pgsql/view-result.txx b/odb/pgsql/view-result.txx index cf29d00..9f126b9 100644 --- a/odb/pgsql/view-result.txx +++ b/odb/pgsql/view-result.txx @@ -35,10 +35,12 @@ namespace odb view_result_impl:: view_result_impl (const query_base&, details::shared_ptr statement, - statements_type& statements) + statements_type& statements, + const schema_version_migration* svm) : base_type (statements.connection ()), statement_ (statement), statements_ (statements), + tc_ (svm), count_ (0) { } @@ -55,7 +57,7 @@ namespace odb if (im.version != statements_.image_version ()) { binding& b (statements_.image_binding ()); - view_traits::bind (b.bind, im); + tc_.bind (b.bind, im); statements_.image_version (im.version); b.version++; } @@ -64,13 +66,13 @@ namespace odb if (r == select_statement::truncated) { - if (view_traits::grow (im, statements_.image_truncated ())) + if (tc_.grow (im, statements_.image_truncated ())) im.version++; if (im.version != statements_.image_version ()) { binding& b (statements_.image_binding ()); - view_traits::bind (b.bind, im); + tc_.bind (b.bind, im); statements_.image_version (im.version); b.version++; statement_->reload (); @@ -78,7 +80,7 @@ namespace odb } view_traits::callback (this->db_, view, callback_event::pre_load); - view_traits::init (view, im, &this->db_); + tc_.init (view, im, &this->db_); view_traits::callback (this->db_, view, callback_event::post_load); } -- cgit v1.1