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-2005, 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 
00073   query_id insert(const PGSTD::string &);                               //[t69]
00074 
00076   void complete();                                                      //[t71]
00077 
00079 
00086   void flush();                                                         //[t70]
00087 
00089   bool is_finished(query_id) const;                                     //[t71]
00090 
00092 
00098   result retrieve(query_id qid)                                         //[t71]
00099         { return retrieve(m_queries.find(qid)).second; }
00100 
00102 
00103   PGSTD::pair<query_id, result> retrieve();                             //[t69]
00104 
00105   bool empty() const throw () { return m_queries.empty(); }             //[t69]
00106 
00108 
00119   int retain(int retain_max=2);                                         //[t70]
00120 
00121 
00123   void resume();                                                        //[t70]
00124 
00125 private:
00126   class PQXX_PRIVATE Query
00127   {
00128   public:
00129     explicit Query(const PGSTD::string &q) : m_query(q), m_res() {}
00130 
00131     const result &get_result() const throw () { return m_res; }
00132     void set_result(const result &r) throw () { m_res = r; }
00133     const PGSTD::string &get_query() const throw () { return m_query; }
00134 
00135   private:
00136     PGSTD::string m_query;
00137     result m_res;
00138   };
00139 
00140   typedef PGSTD::map<query_id,Query> QueryMap;
00141 
00142   struct getquery:PGSTD::unary_function<QueryMap::const_iterator,PGSTD::string>
00143   {
00144     getquery(){}        // Silences bogus warning in some gcc versions
00145     PGSTD::string operator()(QueryMap::const_iterator i) const
00146         { return i->second.get_query(); }
00147   };
00148 
00150   static query_id qid_limit() throw ()
00151   {
00152 #if defined(PQXX_HAVE_LIMITS) && !defined(_MSC_VER)
00153     return PGSTD::numeric_limits<query_id>::max();
00154 #else
00155     return LONG_MAX;
00156 #endif
00157   }
00158 
00160   query_id PQXX_PRIVATE generate_id();
00161 
00162   bool have_pending() const throw ()
00163         { return m_issuedrange.second != m_issuedrange.first; }
00164 
00165   void PQXX_PRIVATE issue();
00166 
00168   void set_error_at(query_id qid) throw () { if (qid < m_error) m_error = qid; }
00169 
00170   void PQXX_PRIVATE internal_error(const PGSTD::string &err)
00171     throw (PGSTD::logic_error);
00172 
00173   bool PQXX_PRIVATE obtain_result(bool expect_none=false);
00174 
00175   void PQXX_PRIVATE obtain_dummy();
00176   void PQXX_PRIVATE get_further_available_results();
00177   void PQXX_PRIVATE check_end_results();
00178 
00180   void PQXX_PRIVATE receive_if_available();
00181 
00183   void PQXX_PRIVATE receive(QueryMap::const_iterator stop);
00184   PGSTD::pair<query_id, result> retrieve(QueryMap::iterator);
00185 
00186   QueryMap m_queries;
00187   PGSTD::pair<QueryMap::iterator,QueryMap::iterator> m_issuedrange;
00188   int m_retain;
00189   int m_num_waiting;
00190   query_id m_q_id;
00191 
00193   bool m_dummy_pending;
00194 
00196   query_id m_error;
00197 
00199   pipeline(const pipeline &);
00201   pipeline &operator=(const pipeline &);
00202 };
00203 
00204 
00205 } // namespace
00206 
00207 

Generated on Fri Jul 1 14:36:19 2005 for libpqxx by  doxygen 1.4.2