pipeline.hxx

Go to the documentation of this file.
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-2006, 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 #include "pqxx/compiler-public.hxx"
00020 #include "pqxx/compiler-internal-pre.hxx"
00021 
00022 #ifdef PQXX_HAVE_LIMITS
00023 #include <limits>
00024 #endif
00025 
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 
00062 class PQXX_LIBEXPORT pipeline : public internal::transactionfocus
00063 {
00064 public:
00065   typedef long query_id;
00066 
00067   explicit pipeline(transaction_base &,
00068       const PGSTD::string &Name=PGSTD::string());                       //[t69]
00069 
00070   ~pipeline() throw ();
00071 
00073 
00079   query_id insert(const PGSTD::string &);                               //[t69]
00080 
00082   void complete();                                                      //[t71]
00083 
00085 
00092   void flush();                                                         //[t70]
00093 
00095   bool is_finished(query_id) const;                                     //[t71]
00096 
00098 
00104   result retrieve(query_id qid)                                         //[t71]
00105         { return retrieve(m_queries.find(qid)).second; }
00106 
00108 
00109   PGSTD::pair<query_id, result> retrieve();                             //[t69]
00110 
00111   bool empty() const throw () { return m_queries.empty(); }             //[t69]
00112 
00114 
00125   int retain(int retain_max=2);                                         //[t70]
00126 
00127 
00129   void resume();                                                        //[t70]
00130 
00131 private:
00132   class PQXX_PRIVATE Query
00133   {
00134   public:
00135     explicit Query(const PGSTD::string &q) : m_query(q), m_res() {}
00136 
00137     const result &get_result() const throw () { return m_res; }
00138     void set_result(const result &r) throw () { m_res = r; }
00139     const PGSTD::string &get_query() const throw () { return m_query; }
00140 
00141   private:
00142     PGSTD::string m_query;
00143     result m_res;
00144   };
00145 
00146   typedef PGSTD::map<query_id,Query> QueryMap;
00147 
00148   struct getquery:PGSTD::unary_function<QueryMap::const_iterator,PGSTD::string>
00149   {
00150     getquery(){}        // Silences bogus warning in some gcc versions
00151     PGSTD::string operator()(QueryMap::const_iterator i) const
00152         { return i->second.get_query(); }
00153   };
00154 
00156   static query_id qid_limit() throw ()
00157   {
00158 #if defined(PQXX_HAVE_LIMITS)
00159     return PGSTD::numeric_limits<query_id>::max();
00160 #else
00161     return LONG_MAX;
00162 #endif
00163   }
00164 
00166   query_id PQXX_PRIVATE generate_id();
00167 
00168   bool have_pending() const throw ()
00169         { return m_issuedrange.second != m_issuedrange.first; }
00170 
00171   void PQXX_PRIVATE issue();
00172 
00174   void set_error_at(query_id qid) throw () { if (qid < m_error) m_error = qid; }
00175 
00176   void PQXX_PRIVATE internal_error(const PGSTD::string &err)
00177     throw (PGSTD::logic_error);
00178 
00179   bool PQXX_PRIVATE obtain_result(bool expect_none=false);
00180 
00181   void PQXX_PRIVATE obtain_dummy();
00182   void PQXX_PRIVATE get_further_available_results();
00183   void PQXX_PRIVATE check_end_results();
00184 
00186   void PQXX_PRIVATE receive_if_available();
00187 
00189   void PQXX_PRIVATE receive(pipeline::QueryMap::const_iterator stop);
00190   PGSTD::pair<pipeline::query_id, result> retrieve(pipeline::QueryMap::iterator);
00191 
00192   QueryMap m_queries;
00193   PGSTD::pair<QueryMap::iterator,QueryMap::iterator> m_issuedrange;
00194   int m_retain;
00195   int m_num_waiting;
00196   query_id m_q_id;
00197 
00199   bool m_dummy_pending;
00200 
00202   query_id m_error;
00203 
00205   pipeline(const pipeline &);
00207   pipeline &operator=(const pipeline &);
00208 };
00209 
00210 
00211 } // namespace
00212 
00213 
00214 #include "pqxx/compiler-internal-post.hxx"

Generated on Thu Feb 1 17:12:08 2007 for libpqxx by  doxygen 1.5.1