diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2012-10-15 13:17:30 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2012-10-19 11:38:24 +0200 |
commit | 1e78bdc724e95898c04a3409b0b192aa7f77780b (patch) | |
tree | d26ae47ae9956612b5973f536219f0c9b455db03 /odb/connection.cxx | |
parent | 5b0430fdf4617b396e462872d438a663b174a3a8 (diff) |
Implement early connection release
Diffstat (limited to 'odb/connection.cxx')
-rw-r--r-- | odb/connection.cxx | 55 |
1 files changed, 46 insertions, 9 deletions
diff --git a/odb/connection.cxx b/odb/connection.cxx index f479131..2686887 100644 --- a/odb/connection.cxx +++ b/odb/connection.cxx @@ -4,6 +4,8 @@ #include <odb/database.hxx> #include <odb/connection.hxx> +#include <odb/result.hxx> +#include <odb/prepared-query.hxx> #include <odb/exceptions.hxx> // prepared_* using namespace std; @@ -13,16 +15,45 @@ namespace odb connection:: ~connection () { + assert (prepared_queries_ == 0); + assert (prepared_map_.empty ()); + } + + void connection:: + clear_prepared_map () + { for (prepared_map_type::iterator i (prepared_map_.begin ()), e (prepared_map_.end ()); i != e; ++i) { if (i->second.params != 0) i->second.params_deleter (i->second.params); } + + prepared_map_.clear (); + } + + void connection:: + recycle () + { + while (prepared_queries_ != 0) + { + prepared_queries_->stmt.reset (); + prepared_queries_->list_remove (); + } } void connection:: - cache_query_ (details::shared_ptr<prepared_query_impl> pq, + invalidate_results () + { + while (results_ != 0) + { + results_->invalidate (); + results_->list_remove (); + } + } + + void connection:: + cache_query_ (prepared_query_impl* pq, const type_info& ti, void* params, const type_info* params_info, @@ -37,19 +68,25 @@ namespace odb prepared_entry_type& e (r.first->second); - e.prep_query = pq; - e.type_info = &ti; - - // Mark the statement as cached. + // Mark this prepared query as cached , get its ref count to 1 + // (prepared_query instances now reference this impl object), + // and remove it from the invalidation list. // - pq->stmt->cached (true); + pq->cached = true; + + while (pq->_ref_count () > 1) + pq->_dec_ref (); + pq->list_remove (); + + e.prep_query.reset (pq); + e.type_info = &ti; e.params = params; e.params_info = params_info; e.params_deleter = params_deleter; } - details::shared_ptr<prepared_query_impl> connection:: + prepared_query_impl* connection:: lookup_query_ (const char* name, const type_info& ti, void** params, @@ -72,7 +109,7 @@ namespace odb } if (i == prepared_map_.end ()) - return details::shared_ptr<prepared_query_impl> (); + return 0; // Make sure the types match. // @@ -87,6 +124,6 @@ namespace odb *params = i->second.params; } - return i->second.prep_query; + return i->second.prep_query.get (); } } |