From b64c3b462f99ef7337eb4bc7fa6bb258d619d8b3 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 27 Oct 2011 15:16:49 +0200 Subject: Add support for persistent classes without object ids New pragma id (object). New test: common/no-id. --- odb/pgsql/object-result.txx | 115 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 102 insertions(+), 13 deletions(-) (limited to 'odb/pgsql/object-result.txx') diff --git a/odb/pgsql/object-result.txx b/odb/pgsql/object-result.txx index b10afe4..57a70d7 100644 --- a/odb/pgsql/object-result.txx +++ b/odb/pgsql/object-result.txx @@ -11,17 +11,21 @@ namespace odb { namespace pgsql { + // + // object_result_impl + // + template - result_impl:: - ~result_impl () + object_result_impl:: + ~object_result_impl () { } template - result_impl:: - result_impl (const query&, - details::shared_ptr statement, - object_statements& statements) + object_result_impl:: + object_result_impl (const query&, + details::shared_ptr statement, + object_statements& statements) : base_type (statements.connection ().database ()), statement_ (statement), statements_ (statements) @@ -29,7 +33,7 @@ namespace odb } template - void result_impl:: + void object_result_impl:: load (object_type& obj) { load_image (); @@ -66,8 +70,8 @@ namespace odb } template - typename result_impl::id_type - result_impl:: + typename object_result_impl::id_type + object_result_impl:: load_id () { load_image (); @@ -75,7 +79,7 @@ namespace odb } template - void result_impl:: + void object_result_impl:: next () { this->current (pointer_type ()); @@ -85,7 +89,7 @@ namespace odb } template - void result_impl:: + void object_result_impl:: load_image () { // The image can grow between calls to load() as a result of other @@ -120,13 +124,98 @@ namespace odb } template - void result_impl:: + void object_result_impl:: + cache () + { + } + + template + std::size_t object_result_impl:: + size () + { + return statement_->result_size (); + } + + // + // object_result_impl_no_id + // + + template + object_result_impl_no_id:: + ~object_result_impl_no_id () + { + } + + template + object_result_impl_no_id:: + object_result_impl_no_id (const query&, + details::shared_ptr statement, + object_statements_no_id& statements) + : base_type (statements.connection ().database ()), + statement_ (statement), + statements_ (statements) + { + } + + template + void object_result_impl_no_id:: + load (object_type& obj) + { + // The image can grow between calls to load() as a result of other + // statements execution. + // + typename object_traits::image_type& im (statements_.image ()); + + if (im.version != statements_.select_image_version ()) + { + binding& b (statements_.select_image_binding ()); + object_traits::bind (b.bind, im, statement_select); + statements_.select_image_version (im.version); + b.version++; + } + + select_statement::result r (statement_->load ()); + + if (r == select_statement::truncated) + { + if (object_traits::grow (im, statements_.select_image_truncated ())) + im.version++; + + if (im.version != statements_.select_image_version ()) + { + binding& b (statements_.select_image_binding ()); + object_traits::bind (b.bind, im, statement_select); + statements_.select_image_version (im.version); + b.version++; + statement_->reload (); + } + } + + odb::database& db (this->database ()); + + object_traits::callback (db, obj, callback_event::pre_load); + object_traits::init (obj, im, db); + object_traits::callback (db, obj, callback_event::post_load); + } + + template + void object_result_impl_no_id:: + next () + { + this->current (pointer_type ()); + + if (!statement_->next ()) + this->end_ = true; + } + + template + void object_result_impl_no_id:: cache () { } template - std::size_t result_impl:: + std::size_t object_result_impl_no_id:: size () { return statement_->result_size (); -- cgit v1.1