diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2012-10-15 13:17:31 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2012-10-15 13:17:31 +0200 |
commit | 93cb54135cd7b214ded868d0277f2f4d5eca0e2c (patch) | |
tree | ffa41df34bace2691d383e013fdb3d3b0a9c1ccf | |
parent | 0051807a6c28dd0ebb425d05511fbf9127483ee1 (diff) |
Implement early connection release
-rw-r--r-- | odb/oracle/connection-factory.cxx | 3 | ||||
-rw-r--r-- | odb/oracle/connection.cxx | 3 | ||||
-rw-r--r-- | odb/oracle/connection.hxx | 3 | ||||
-rw-r--r-- | odb/oracle/no-id-object-result.hxx | 3 | ||||
-rw-r--r-- | odb/oracle/no-id-object-result.txx | 25 | ||||
-rw-r--r-- | odb/oracle/polymorphic-object-result.hxx | 3 | ||||
-rw-r--r-- | odb/oracle/polymorphic-object-result.txx | 29 | ||||
-rw-r--r-- | odb/oracle/prepared-query.hxx | 2 | ||||
-rw-r--r-- | odb/oracle/simple-object-result.hxx | 3 | ||||
-rw-r--r-- | odb/oracle/simple-object-result.txx | 24 | ||||
-rw-r--r-- | odb/oracle/transaction-impl.cxx | 16 | ||||
-rw-r--r-- | odb/oracle/view-result.hxx | 3 | ||||
-rw-r--r-- | odb/oracle/view-result.txx | 23 |
13 files changed, 113 insertions, 27 deletions
diff --git a/odb/oracle/connection-factory.cxx b/odb/oracle/connection-factory.cxx index 6b442a8..2190a69 100644 --- a/odb/oracle/connection-factory.cxx +++ b/odb/oracle/connection-factory.cxx @@ -133,7 +133,10 @@ namespace odb in_use_--; if (keep) + { connections_.push_back (pooled_connection_ptr (inc_ref (c))); + connections_.back ()->recycle (); + } if (waiters_ != 0) cond_.signal (); diff --git a/odb/oracle/connection.cxx b/odb/oracle/connection.cxx index 1194de9..98bc218 100644 --- a/odb/oracle/connection.cxx +++ b/odb/oracle/connection.cxx @@ -139,7 +139,8 @@ namespace odb { // Deallocate prepared statements before we close the connection. // - prepared_map_.clear (); + recycle (); + clear_prepared_map (); statement_cache_.reset (); } diff --git a/odb/oracle/connection.hxx b/odb/oracle/connection.hxx index 38be958..5293b66 100644 --- a/odb/oracle/connection.hxx +++ b/odb/oracle/connection.hxx @@ -138,6 +138,9 @@ namespace odb connection& operator= (const connection&); private: + friend class transaction_impl; // invalidate_results() + + private: database_type& db_; // It is important that the error_ member is declared before the diff --git a/odb/oracle/no-id-object-result.hxx b/odb/oracle/no-id-object-result.hxx index 499c1b6..0a062ca 100644 --- a/odb/oracle/no-id-object-result.hxx +++ b/odb/oracle/no-id-object-result.hxx @@ -54,6 +54,9 @@ namespace odb virtual std::size_t size (); + virtual void + invalidate (); + using base_type::current; private: diff --git a/odb/oracle/no-id-object-result.txx b/odb/oracle/no-id-object-result.txx index 405d139..56f4252 100644 --- a/odb/oracle/no-id-object-result.txx +++ b/odb/oracle/no-id-object-result.txx @@ -15,18 +15,31 @@ namespace odb no_id_object_result_impl<T>:: ~no_id_object_result_impl () { + invalidate (); + } + + template <typename T> + void no_id_object_result_impl<T>:: + invalidate () + { change_callback_type& cc (statements_.image ().change_callback_); if (cc.context == this) { - cc.context = 0; cc.callback = 0; + cc.context = 0; } delete image_copy_; + image_copy_ = 0; if (!this->end_) + { statement_->free_result (); + this->end_ = true; + } + + statement_.reset (); } template <typename T> @@ -34,7 +47,7 @@ namespace odb no_id_object_result_impl (const query_base&, details::shared_ptr<select_statement> statement, statements_type& statements) - : base_type (statements.connection ().database ()), + : base_type (statements.connection ()), statement_ (statement), statements_ (statements), use_copy_ (false), @@ -46,13 +59,11 @@ namespace odb void no_id_object_result_impl<T>:: load (object_type& obj) { - odb::database& db (this->database ()); - - object_traits::callback (db, obj, callback_event::pre_load); + object_traits::callback (this->db_, obj, callback_event::pre_load); object_traits::init (obj, use_copy_ ? *image_copy_ : statements_.image (), - &db); + &this->db_); // If we are using a copy, make sure the callback information for // LOB data also comes from the copy. @@ -61,7 +72,7 @@ namespace odb use_copy_ ? &statements_.image () : 0, use_copy_ ? image_copy_ : 0); - object_traits::callback (db, obj, callback_event::post_load); + object_traits::callback (this->db_, obj, callback_event::post_load); } template <typename T> diff --git a/odb/oracle/polymorphic-object-result.hxx b/odb/oracle/polymorphic-object-result.hxx index 5092aa7..284f663 100644 --- a/odb/oracle/polymorphic-object-result.hxx +++ b/odb/oracle/polymorphic-object-result.hxx @@ -68,6 +68,9 @@ namespace odb virtual std::size_t size (); + virtual void + invalidate (); + using base_type::current; private: diff --git a/odb/oracle/polymorphic-object-result.txx b/odb/oracle/polymorphic-object-result.txx index 9db06cc..7635403 100644 --- a/odb/oracle/polymorphic-object-result.txx +++ b/odb/oracle/polymorphic-object-result.txx @@ -17,6 +17,13 @@ namespace odb polymorphic_object_result_impl<T>:: ~polymorphic_object_result_impl () { + invalidate (); + } + + template <typename T> + void polymorphic_object_result_impl<T>:: + invalidate () + { change_callback_type& cc ( statements_.root_statements ().image ().change_callback_); @@ -27,10 +34,18 @@ namespace odb } if (image_copy_ != 0) + { object_traits::free_image (image_copy_); + image_copy_ = 0; + } if (!this->end_) + { statement_->free_result (); + this->end_ = true; + } + + statement_.reset (); } template <typename T> @@ -38,7 +53,7 @@ namespace odb polymorphic_object_result_impl (const query_base&, details::shared_ptr<select_statement> st, statements_type& sts) - : base_type (sts.connection ().database ()), + : base_type (sts.connection ()), statement_ (st), statements_ (sts), use_copy_ (false), @@ -58,7 +73,6 @@ namespace odb assert (!rsts.locked ()); typename statements_type::auto_lock l (rsts); - odb::database& db (this->database ()); image_type& i (use_copy_ ? *image_copy_ : statements_.image ()); typename root_traits::image_type& ri ( use_copy_ ? object_traits::root_image (i) : rsts.image ()); @@ -95,7 +109,8 @@ namespace odb // Insert it as a root pointer (for non-unique pointers, rp should // still be valid and for unique pointers this is a no-op). // - ig.reset (object_traits::pointer_cache_traits::insert (db, id, rp)); + ig.reset ( + object_traits::pointer_cache_traits::insert (this->db_, id, rp)); pobj = &pointer_traits::get_ref (p); current (p); @@ -116,9 +131,9 @@ namespace odb } callback_event ce (callback_event::pre_load); - pi.dispatch (info_type::call_callback, db, pobj, &ce); + pi.dispatch (info_type::call_callback, this->db_, pobj, &ce); - object_traits::init (*pobj, i, &db); + object_traits::init (*pobj, i, &this->db_); // If we are using a copy, make sure the callback information for // LOB data also comes from the copy. @@ -149,14 +164,14 @@ namespace odb if (&pi != &object_traits::info) { std::size_t d (object_traits::depth); - pi.dispatch (info_type::call_load, db, pobj, &d); + pi.dispatch (info_type::call_load, this->db_, pobj, &d); }; rsts.load_delayed (); l.unlock (); ce = callback_event::post_load; - pi.dispatch (info_type::call_callback, db, pobj, &ce); + pi.dispatch (info_type::call_callback, this->db_, pobj, &ce); ig.release (); } diff --git a/odb/oracle/prepared-query.hxx b/odb/oracle/prepared-query.hxx index 784509c..1747449 100644 --- a/odb/oracle/prepared-query.hxx +++ b/odb/oracle/prepared-query.hxx @@ -23,6 +23,8 @@ namespace odb virtual ~prepared_query_impl (); + prepared_query_impl (odb::connection& c): odb::prepared_query_impl (c) {} + oracle::query_base query; }; } diff --git a/odb/oracle/simple-object-result.hxx b/odb/oracle/simple-object-result.hxx index cde1a18..1162803 100644 --- a/odb/oracle/simple-object-result.hxx +++ b/odb/oracle/simple-object-result.hxx @@ -58,6 +58,9 @@ namespace odb virtual std::size_t size (); + virtual void + invalidate (); + using base_type::current; private: diff --git a/odb/oracle/simple-object-result.txx b/odb/oracle/simple-object-result.txx index b36eb3b..345de38 100644 --- a/odb/oracle/simple-object-result.txx +++ b/odb/oracle/simple-object-result.txx @@ -17,18 +17,31 @@ namespace odb object_result_impl<T>:: ~object_result_impl () { + invalidate (); + } + + template <typename T> + void object_result_impl<T>:: + invalidate () + { change_callback_type& cc (statements_.image ().change_callback_); if (cc.context == this) { - cc.context = 0; cc.callback = 0; + cc.context = 0; } delete image_copy_; + image_copy_ = 0; if (!this->end_) + { statement_->free_result (); + this->end_ = true; + } + + statement_.reset (); } template <typename T> @@ -36,7 +49,7 @@ namespace odb object_result_impl (const query_base&, details::shared_ptr<select_statement> statement, statements_type& statements) - : base_type (statements.connection ().database ()), + : base_type (statements.connection ()), statement_ (statement), statements_ (statements), use_copy_ (false), @@ -53,13 +66,12 @@ namespace odb assert (!statements_.locked ()); typename statements_type::auto_lock l (statements_); - odb::database& db (this->database ()); - object_traits::callback (db, obj, callback_event::pre_load); + object_traits::callback (this->db_, obj, callback_event::pre_load); typename object_traits::image_type& i ( use_copy_ ? *image_copy_ : statements_.image ()); - object_traits::init (obj, i, &db); + object_traits::init (obj, i, &this->db_); // If we are using a copy, make sure the callback information for // LOB data also comes from the copy. @@ -85,7 +97,7 @@ namespace odb object_traits::load_ (statements_, obj); statements_.load_delayed (); l.unlock (); - object_traits::callback (db, obj, callback_event::post_load); + object_traits::callback (this->db_, obj, callback_event::post_load); } template <typename T> diff --git a/odb/oracle/transaction-impl.cxx b/odb/oracle/transaction-impl.cxx index 4d42b34..e11c281 100644 --- a/odb/oracle/transaction-impl.cxx +++ b/odb/oracle/transaction-impl.cxx @@ -111,6 +111,10 @@ namespace odb void transaction_impl:: commit () { + // Invalidate query results. + // + connection_->invalidate_results (); + { odb::tracer* t; if ((t = connection_->tracer ()) || (t = database_.tracer ())) @@ -123,11 +127,19 @@ namespace odb if (s == OCI_ERROR || s == OCI_INVALID_HANDLE) translate_error (*connection_, s); + + // Release the connection. + // + connection_.reset (); } void transaction_impl:: rollback () { + // Invalidate query results. + // + connection_->invalidate_results (); + { odb::tracer* t; if ((t = connection_->tracer ()) || (t = database_.tracer ())) @@ -140,6 +152,10 @@ namespace odb if (s == OCI_ERROR || s == OCI_INVALID_HANDLE) translate_error (*connection_, s); + + // Release the connection. + // + connection_.reset (); } } } diff --git a/odb/oracle/view-result.hxx b/odb/oracle/view-result.hxx index ccbf57b..1f34f57 100644 --- a/odb/oracle/view-result.hxx +++ b/odb/oracle/view-result.hxx @@ -54,6 +54,9 @@ namespace odb virtual std::size_t size (); + virtual void + invalidate (); + using base_type::current; private: diff --git a/odb/oracle/view-result.txx b/odb/oracle/view-result.txx index 248ef76..8dbe8d0 100644 --- a/odb/oracle/view-result.txx +++ b/odb/oracle/view-result.txx @@ -15,6 +15,13 @@ namespace odb view_result_impl<T>:: ~view_result_impl () { + invalidate (); + } + + template <typename T> + void view_result_impl<T>:: + invalidate () + { change_callback_type& cc (statements_.image ().change_callback_); if (cc.context == this) @@ -24,9 +31,15 @@ namespace odb } delete image_copy_; + image_copy_ = 0; if (!this->end_) + { statement_->free_result (); + this->end_ = true; + } + + statement_.reset (); } template <typename T> @@ -34,7 +47,7 @@ namespace odb view_result_impl (const query_base&, details::shared_ptr<select_statement> statement, statements_type& statements) - : base_type (statements.connection ().database ()), + : base_type (statements.connection ()), statement_ (statement), statements_ (statements), use_copy_ (false), @@ -46,13 +59,11 @@ namespace odb void view_result_impl<T>:: load (view_type& view) { - odb::database& db (this->database ()); - - view_traits::callback (db, view, callback_event::pre_load); + view_traits::callback (this->db_, view, callback_event::pre_load); view_traits::init (view, use_copy_ ? *image_copy_ : statements_.image (), - &db); + &this->db_); // If we are using a copy, make sure the callback information for // LOB data also comes from the copy. @@ -61,7 +72,7 @@ namespace odb use_copy_ ? &statements_.image () : 0, use_copy_ ? image_copy_ : 0); - view_traits::callback (db, view, callback_event::post_load); + view_traits::callback (this->db_, view, callback_event::post_load); } template <typename T> |