pipeline.hxx
/*-------------------------------------------------------------------------
*
* FILE
* pqxx/pipeline.hxx
*
* DESCRIPTION
* definition of the pqxx::pipeline class.
* Throughput-optimized query manager
* DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/pipeline instead.
*
* Copyright (c) 2003-2011, Jeroen T. Vermeulen <jtv@xs4all.nl>
*
* See COPYING for copyright license. If you did not receive a file called
* COPYING with this source code, please notify the distributor of this mistake,
* or contact the author.
*
*-------------------------------------------------------------------------
*/
#ifndef PQXX_H_PIPELINE
#define PQXX_H_PIPELINE
#include "pqxx/compiler-public.hxx"
#include "pqxx/compiler-internal-pre.hxx"
#ifdef PQXX_HAVE_LIMITS
#include <limits>
#endif
#include <map>
#include <string>
#include "pqxx/transaction_base"
/* Methods tested in eg. self-test program test001 are marked with "//[t1]"
*/
namespace pqxx
{
class PQXX_LIBEXPORT pipeline : public internal::transactionfocus
{
public:
typedef long query_id;
explicit pipeline(transaction_base &,
const PGSTD::string &Name=PGSTD::string()); //[t69]
~pipeline() throw ();
query_id insert(const PGSTD::string &); //[t69]
void complete(); //[t71]
void flush(); //[t70]
void cancel();
bool is_finished(query_id) const; //[t71]
result retrieve(query_id qid) //[t71]
{ return retrieve(m_queries.find(qid)).second; }
PGSTD::pair<query_id, result> retrieve(); //[t69]
bool empty() const throw () { return m_queries.empty(); } //[t69]
int retain(int retain_max=2); //[t70]
void resume(); //[t70]
private:
class PQXX_PRIVATE Query
{
public:
explicit Query(const PGSTD::string &q) : m_query(q), m_res() {}
const result &get_result() const throw () { return m_res; }
void set_result(const result &r) throw () { m_res = r; }
const PGSTD::string &get_query() const throw () { return m_query; }
private:
PGSTD::string m_query;
result m_res;
};
typedef PGSTD::map<query_id,Query> QueryMap;
struct getquery:PGSTD::unary_function<QueryMap::const_iterator,PGSTD::string>
{
getquery(){} // Silences bogus warning in some gcc versions
PGSTD::string operator()(QueryMap::const_iterator i) const
{ return i->second.get_query(); }
};
void attach();
void detach();
static query_id qid_limit() throw ()
{
#if defined(PQXX_HAVE_LIMITS)
return PGSTD::numeric_limits<query_id>::max();
#else
return LONG_MAX;
#endif
}
query_id PQXX_PRIVATE generate_id();
bool have_pending() const throw ()
{ return m_issuedrange.second != m_issuedrange.first; }
void PQXX_PRIVATE issue();
void set_error_at(query_id qid) throw () { if (qid < m_error) m_error = qid; }
void PQXX_PRIVATE PQXX_NORETURN internal_error(const PGSTD::string &err)
throw (PGSTD::logic_error);
bool PQXX_PRIVATE obtain_result(bool expect_none=false);
void PQXX_PRIVATE obtain_dummy();
void PQXX_PRIVATE get_further_available_results();
void PQXX_PRIVATE check_end_results();
void PQXX_PRIVATE receive_if_available();
void PQXX_PRIVATE receive(pipeline::QueryMap::const_iterator stop);
PGSTD::pair<pipeline::query_id, result>
retrieve(pipeline::QueryMap::iterator);
QueryMap m_queries;
PGSTD::pair<QueryMap::iterator,QueryMap::iterator> m_issuedrange;
int m_retain;
int m_num_waiting;
query_id m_q_id;
bool m_dummy_pending;
query_id m_error;
pipeline(const pipeline &);
pipeline &operator=(const pipeline &);
};
} // namespace
#include "pqxx/compiler-internal-post.hxx"
#endif
pqxx::result
Result set containing data returned by a query or command.
Definition: result.hxx:81
pqxx::internal_error
Internal error in libpqxx library.
Definition: except.hxx:164
pqxx::internal::transactionfocus
Definition: transaction_base.hxx:52
pqxx::pipeline::empty
bool empty() const
Definition: pipeline.hxx:121
pqxx::pipeline::query_id
long query_id
Definition: pipeline.hxx:61
pqxx
The home of all libpqxx classes, functions, templates, etc.
Definition: basic_connection.hxx:35
pqxx::transaction_base
Definition: transaction_base.hxx:133
pqxx::pipeline
Processes several queries in FIFO manner, optimized for high throughput.
Definition: pipeline.hxx:58