From 2895ad78dbdb43e57fc34558b4530b4e105fc72d Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 1 Feb 2024 18:10:29 +0300 Subject: Turn libodb-mssql repository into package for muti-package repository --- .../odb/mssql/simple-object-statements.txx | 173 +++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 libodb-mssql/odb/mssql/simple-object-statements.txx (limited to 'libodb-mssql/odb/mssql/simple-object-statements.txx') diff --git a/libodb-mssql/odb/mssql/simple-object-statements.txx b/libodb-mssql/odb/mssql/simple-object-statements.txx new file mode 100644 index 0000000..06a0651 --- /dev/null +++ b/libodb-mssql/odb/mssql/simple-object-statements.txx @@ -0,0 +1,173 @@ +// file : odb/mssql/simple-object-statements.txx +// license : ODB NCUEL; see accompanying LICENSE file + +#include // std::memset + +#include +#include + +#include +#include + +namespace odb +{ + namespace mssql + { + // + // optimistic_data + // + + template + optimistic_data:: + optimistic_data (bind* b, std::size_t skip, SQLUSMALLINT* status) + : id_image_binding_ ( + b, + object_traits::id_column_count + + object_traits::managed_optimistic_column_count, + object_traits::batch, + skip, + status) + { + } + + // + // object_statements + // + + template + object_statements:: + ~object_statements () + { + } + + template + object_statements:: + object_statements (connection_type& conn) + : object_statements_base (conn), + select_image_binding_ (select_image_bind_, select_column_count), + insert_image_binding_ (insert_image_bind_, + insert_column_count, + object_traits::batch, + sizeof (images), + status_), + update_image_binding_ (update_image_bind_, + update_column_count + id_column_count + + managed_optimistic_column_count, + // No support for bulk update and ROWVERSION. + // + (object_traits::rowversion + ? 1 + : object_traits::batch), + sizeof (images), + status_), + id_image_binding_ (update_image_bind_ + update_column_count, + id_column_count, + object_traits::batch, + sizeof (images), + status_), + od_ (update_image_bind_ + update_column_count, + sizeof (images), + status_) + { + // Only versions in the first element used. + // + images_[0].obj.version = 0; + images_[0].id.version = 0; + + select_image_version_ = 0; + insert_image_version_ = 0; + update_image_version_ = 0; + update_id_image_version_ = 0; + id_image_version_ = 0; + + // SELECT statements only use the first element (no batches). + // + select_image_binding_.change_callback = + images_[0].obj.change_callback (); + + std::memset (insert_image_bind_, 0, sizeof (insert_image_bind_)); + std::memset (update_image_bind_, 0, sizeof (update_image_bind_)); + std::memset (select_image_bind_, 0, sizeof (select_image_bind_)); + } + + template + template + void object_statements:: + load_delayed_ (const schema_version_migration* svm) + { + database& db (connection ().database ()); + + delayed_loads dls; + swap_guard sg (*this, dls); + + while (!dls.empty ()) + { + delayed_load l (dls.back ()); + typename pointer_cache_traits::insert_guard ig (l.pos); + dls.pop_back (); + + if (l.loader == 0) + { + object_traits_calls tc (svm); + + if (!tc.find_ (static_cast (*this), &l.id)) + throw object_not_persistent (); + + // Our find_() version delays result freeing. + // + auto_result ar (*find_); + + object_traits::callback (db, *l.obj, callback_event::pre_load); + + // Our calls to init/load below can result in additional delayed + // loads being added to the delayed_ vector. We need to process + // those before we call the post callback. + // + tc.init (*l.obj, image (), &db); + find_->stream_result (); + ar.free (); + + // Load containers, etc. + // + tc.load_ (static_cast (*this), *l.obj, false); + + if (!delayed_.empty ()) + load_delayed_ (svm); + + // Temporarily unlock the statement for the post_load call so that + // it can load objects of this type recursively. This is safe to do + // because we have completely loaded the current object. Also the + // delayed_ list is clear before the unlock and should be clear on + // re-lock (since a callback can only call public API functions + // which will make sure all the delayed loads are processed before + // returning). + // + { + auto_unlock u (*this); + object_traits::callback (db, *l.obj, callback_event::post_load); + } + } + else + l.loader (db, l.id, *l.obj, svm); + + pointer_cache_traits::load (ig.position ()); + ig.release (); + } + } + + template + void object_statements:: + clear_delayed_ () + { + // Remove the objects from the session cache. + // + for (typename delayed_loads::iterator i (delayed_.begin ()), + e (delayed_.end ()); i != e; ++i) + { + pointer_cache_traits::erase (i->pos); + } + + delayed_.clear (); + } + } +} -- cgit v1.1