pipeline.hxx

00001 /*-------------------------------------------------------------------------
00002  *
00003  *   FILE
00004  *      pqxx/pipeline.hxx
00005  *
00006  *   DESCRIPTION
00007  *      definition of the pqxx::pipeline class.
00008  *   Throughput-optimized query manager
00009  *   DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/pipeline instead.
00010  *
00011  * Copyright (c) 2003-2015, Jeroen T. Vermeulen <jtv@xs4all.nl>
00012  *
00013  * See COPYING for copyright license.  If you did not receive a file called
00014  * COPYING with this source code, please notify the distributor of this mistake,
00015  * or contact the author.
00016  *
00017  *-------------------------------------------------------------------------
00018  */
00019 #ifndef PQXX_H_PIPELINE
00020 #define PQXX_H_PIPELINE
00021 
00022 #include "pqxx/compiler-public.hxx"
00023 #include "pqxx/compiler-internal-pre.hxx"
00024 
00025 #include <limits>
00026 #include <map>
00027 #include <string>
00028 
00029 #include "pqxx/transaction_base"
00030 
00031 
00032 /* Methods tested in eg. self-test program test001 are marked with "//[t1]"
00033  */
00034 
00035 namespace pqxx
00036 {
00037 
00039 
00055 class PQXX_LIBEXPORT pipeline : public internal::transactionfocus
00056 {
00057 public:
00058   typedef long query_id;
00059 
00060   explicit pipeline(transaction_base &,
00061       const std::string &Name=std::string());                           //[t69]
00062 
00063   ~pipeline() PQXX_NOEXCEPT;
00064 
00066 
00072   query_id insert(const std::string &);                                 //[t69]
00073 
00075 
00076   void complete();                                                      //[t71]
00077 
00079 
00088   void flush();                                                         //[t70]
00089 
00091 
00099   void cancel();
00100 
00102   bool is_finished(query_id) const;                                     //[t71]
00103 
00105 
00111   result retrieve(query_id qid)                                         //[t71]
00112         { return retrieve(m_queries.find(qid)).second; }
00113 
00115 
00116   std::pair<query_id, result> retrieve();                               //[t69]
00117 
00118   bool empty() const PQXX_NOEXCEPT { return m_queries.empty(); }        //[t69]
00119 
00121 
00132   int retain(int retain_max=2);                                         //[t70]
00133 
00134 
00136   void resume();                                                        //[t70]
00137 
00138 private:
00139   class PQXX_PRIVATE Query
00140   {
00141   public:
00142     explicit Query(const std::string &q) : m_query(q), m_res() {}
00143 
00144     const result &get_result() const PQXX_NOEXCEPT { return m_res; }
00145     void set_result(const result &r) PQXX_NOEXCEPT { m_res = r; }
00146     const std::string &get_query() const PQXX_NOEXCEPT { return m_query; }
00147 
00148   private:
00149     std::string m_query;
00150     result m_res;
00151   };
00152 
00153   typedef std::map<query_id,Query> QueryMap;
00154 
00155   struct getquery:std::unary_function<QueryMap::const_iterator,std::string>
00156   {
00157     getquery(){}        // Silences bogus warning in some gcc versions
00158     std::string operator()(QueryMap::const_iterator i) const
00159         { return i->second.get_query(); }
00160   };
00161 
00162   void attach();
00163   void detach();
00164 
00166   static query_id qid_limit() PQXX_NOEXCEPT
00167   {
00168     return std::numeric_limits<query_id>::max();
00169   }
00170 
00172   PQXX_PRIVATE query_id generate_id();
00173 
00174   bool have_pending() const PQXX_NOEXCEPT
00175         { return m_issuedrange.second != m_issuedrange.first; }
00176 
00177   PQXX_PRIVATE void issue();
00178 
00180   void set_error_at(query_id qid) PQXX_NOEXCEPT
00181         { if (qid < m_error) m_error = qid; }
00182 
00184   PQXX_NORETURN PQXX_PRIVATE void internal_error(const std::string &err);
00185 
00186   PQXX_PRIVATE bool obtain_result(bool expect_none=false);
00187 
00188   PQXX_PRIVATE void obtain_dummy();
00189   PQXX_PRIVATE void get_further_available_results();
00190   PQXX_PRIVATE void check_end_results();
00191 
00193   PQXX_PRIVATE void receive_if_available();
00194 
00196   PQXX_PRIVATE void receive(pipeline::QueryMap::const_iterator stop);
00197   std::pair<pipeline::query_id, result>
00198     retrieve(pipeline::QueryMap::iterator);
00199 
00200   QueryMap m_queries;
00201   std::pair<QueryMap::iterator,QueryMap::iterator> m_issuedrange;
00202   int m_retain;
00203   int m_num_waiting;
00204   query_id m_q_id;
00205 
00207   bool m_dummy_pending;
00208 
00210   query_id m_error;
00211 
00213   pipeline(const pipeline &);
00215   pipeline &operator=(const pipeline &);
00216 };
00217 
00218 
00219 } // namespace
00220 
00221 
00222 #include "pqxx/compiler-internal-post.hxx"
00223 
00224 #endif
00225 

Generated on 17 Mar 2017 for libpqxx by  doxygen 1.6.1