libpqxx: pipeline.hxx Source File

libpqxx 4.0.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

pipeline.hxx
1 /*-------------------------------------------------------------------------
2 *
3 * FILE
4 * pqxx/pipeline.hxx
5 *
6 * DESCRIPTION
7 * definition of the pqxx::pipeline class.
8 * Throughput-optimized query manager
9 * DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/pipeline instead.
10 *
11 * Copyright (c) 2003-2011, Jeroen T. Vermeulen <jtv@xs4all.nl>
12 *
13 * See COPYING for copyright license. If you did not receive a file called
14 * COPYING with this source code, please notify the distributor of this mistake,
15 * or contact the author.
16 *
17 *-------------------------------------------------------------------------
18 */
19 #ifndef PQXX_H_PIPELINE
20 #define PQXX_H_PIPELINE
21
22 #include "pqxx/compiler-public.hxx"
23 #include "pqxx/compiler-internal-pre.hxx"
24
25 #ifdef PQXX_HAVE_LIMITS
26 #include <limits>
27 #endif
28
29 #include <map>
30 #include <string>
31
32 #include "pqxx/transaction_base"
33
34
35 /* Methods tested in eg. self-test program test001 are marked with "//[t1]"
36 */
37
38 namespace pqxx
39 {
40
42
58 class PQXX_LIBEXPORT pipeline : public internal::transactionfocus
59 {
60 public:
61 typedef long query_id;
62
63 explicit pipeline(transaction_base &,
64 const PGSTD::string &Name=PGSTD::string()); //[t69]
65
66 ~pipeline() throw ();
67
69
75 query_id insert(const PGSTD::string &); //[t69]
76
78
79 void complete(); //[t71]
80
82
91 void flush(); //[t70]
92
94
102 void cancel();
103
105 bool is_finished(query_id) const; //[t71]
106
108
114 result retrieve(query_id qid) //[t71]
115 { return retrieve(m_queries.find(qid)).second; }
116
118
119 PGSTD::pair<query_id, result> retrieve(); //[t69]
120
121 bool empty() const throw () { return m_queries.empty(); } //[t69]
122
124
135 int retain(int retain_max=2); //[t70]
136
137
139 void resume(); //[t70]
140
141 private:
142 class PQXX_PRIVATE Query
143 {
144 public:
145 explicit Query(const PGSTD::string &q) : m_query(q), m_res() {}
146
147 const result &get_result() const throw () { return m_res; }
148 void set_result(const result &r) throw () { m_res = r; }
149 const PGSTD::string &get_query() const throw () { return m_query; }
150
151 private:
152 PGSTD::string m_query;
153 result m_res;
154 };
155
156 typedef PGSTD::map<query_id,Query> QueryMap;
157
158 struct getquery:PGSTD::unary_function<QueryMap::const_iterator,PGSTD::string>
159 {
160 getquery(){} // Silences bogus warning in some gcc versions
161 PGSTD::string operator()(QueryMap::const_iterator i) const
162 { return i->second.get_query(); }
163 };
164
165 void attach();
166 void detach();
167
169 static query_id qid_limit() throw ()
170 {
171 #if defined(PQXX_HAVE_LIMITS)
172 return PGSTD::numeric_limits<query_id>::max();
173 #else
174 return LONG_MAX;
175 #endif
176 }
177
179 query_id PQXX_PRIVATE generate_id();
180
181 bool have_pending() const throw ()
182 { return m_issuedrange.second != m_issuedrange.first; }
183
184 void PQXX_PRIVATE issue();
185
187 void set_error_at(query_id qid) throw () { if (qid < m_error) m_error = qid; }
188
189 void PQXX_PRIVATE PQXX_NORETURN internal_error(const PGSTD::string &err)
190 throw (PGSTD::logic_error);
191
192 bool PQXX_PRIVATE obtain_result(bool expect_none=false);
193
194 void PQXX_PRIVATE obtain_dummy();
195 void PQXX_PRIVATE get_further_available_results();
196 void PQXX_PRIVATE check_end_results();
197
199 void PQXX_PRIVATE receive_if_available();
200
202 void PQXX_PRIVATE receive(pipeline::QueryMap::const_iterator stop);
203 PGSTD::pair<pipeline::query_id, result>
204 retrieve(pipeline::QueryMap::iterator);
205
206 QueryMap m_queries;
207 PGSTD::pair<QueryMap::iterator,QueryMap::iterator> m_issuedrange;
208 int m_retain;
209 int m_num_waiting;
210 query_id m_q_id;
211
213 bool m_dummy_pending;
214
216 query_id m_error;
217
219 pipeline(const pipeline &);
221 pipeline &operator=(const pipeline &);
222 };
223
224
225 } // namespace
226
227
228 #include "pqxx/compiler-internal-post.hxx"
229
230 #endif
231