Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

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-2004, 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/libcompiler.h"
00020 
00021 #include <map>
00022 #include <string>
00023 
00024 #include "pqxx/transaction_base"
00025 
00026 
00027 /* Methods tested in eg. self-test program test001 are marked with "//[t1]"
00028  */
00029 
00030 namespace pqxx
00031 {
00032 
00034 
00057 class PQXX_LIBEXPORT pipeline : public internal::transactionfocus
00058 {
00059 public:
00060   typedef long query_id;
00061 
00062   explicit pipeline(transaction_base &, const PGSTD::string &PName=""); //[t69]
00063 
00064   ~pipeline() throw ();
00065 
00067 
00072   query_id insert(const PGSTD::string &);                               //[t69]
00073 
00075   void complete();                                                      //[t71]
00076 
00078 
00084   void flush();                                                         //[t70]
00085 
00087   bool is_finished(query_id) const;                                     //[t71]
00088 
00090 
00093   result retrieve(query_id qid)                                         //[t71]
00094         { return retrieve(m_queries.find(qid)).second; }
00095 
00097   PGSTD::pair<query_id, result> retrieve();                             //[t69]
00098 
00099   bool empty() const throw () { return m_queries.empty(); }             //[t69]
00100 
00101   int retain(int retain_max=2);                                         //[t70]
00102 
00103 
00105   void resume();                                                        //[t70]
00106 
00107 private:
00109   void invariant() const;
00110 
00111   class Query
00112   {
00113   public:
00114     explicit Query(const PGSTD::string &q) : m_query(q), m_res() {}
00115 
00116     const result &get_result() const throw () { return m_res; }
00117     void set_result(const result &r) throw () { m_res = r; }
00118     const PGSTD::string &get_query() const throw () { return m_query; }
00119 
00120   private:
00121     PGSTD::string m_query;
00122     result m_res;
00123   };
00124 
00125   typedef PGSTD::map<query_id,Query> QueryMap;
00126 
00128   static query_id qid_limit() throw ()
00129   {
00130 #ifdef _MSC_VER
00131     return LONG_MAX;
00132 #else
00133     return PGSTD::numeric_limits<query_id>::max();
00134 #endif
00135   }
00136 
00138   query_id generate_id();
00139     
00140   bool have_pending() const throw () 
00141         { return m_issuedrange.second != m_issuedrange.first; }
00142 
00143   void issue();
00144 
00146   void set_error_at(query_id qid) throw () { if (qid < m_error) m_error = qid; }
00147 
00148   void internal_error(const PGSTD::string &err) throw (PGSTD::logic_error);
00149 
00150   bool obtain_result(bool expect_none=false);
00151 
00152   void obtain_dummy();
00153   void get_further_available_results();
00154   void check_end_results();
00155 
00157   void receive_if_available();
00158 
00160   void receive(QueryMap::const_iterator stop);
00161   PGSTD::pair<query_id, result> retrieve(QueryMap::iterator);
00162 
00163   QueryMap m_queries;
00164   PGSTD::pair<QueryMap::iterator,QueryMap::iterator> m_issuedrange;
00165   int m_retain;
00166   int m_num_waiting;
00167   query_id m_q_id;
00168 
00170   bool m_dummy_pending;
00171 
00173   query_id m_error;
00174 
00176   pipeline(const pipeline &);
00178   pipeline &operator=(const pipeline &);
00179 };
00180 
00181 
00182 } // namespace
00183 
00184 

Generated on Mon Nov 1 19:13:35 2004 for libpqxx by  doxygen 1.3.9.1