irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

query_builder.hpp
Go to the documentation of this file.
1 #ifndef IRODS_QUERY_BUILDER_HPP
2 #define IRODS_QUERY_BUILDER_HPP
3 
4 #include "irods_query.hpp"
5 #include "rodsErrorTable.h"
6 
7 #include <vector>
8 
9 namespace irods {
10 namespace experimental {
11 
12  enum class query_type
13  {
14  general,
15  specific
16  };
17 
19  {
20  public:
21  auto type(query_type _v) noexcept -> query_builder&
22  {
23  type_ = _v;
24  return *this;
25  }
26 
27  auto zone_hint(const std::string& _v) -> query_builder&
28  {
29  zone_hint_ = _v;
30  return *this;
31  }
32 
33  auto row_limit(std::uintmax_t _v) noexcept -> query_builder&
34  {
35  limit_ = _v;
36  return *this;
37  }
38 
39  auto row_offset(std::uintmax_t _v) noexcept -> query_builder&
40  {
41  offset_ = _v;
42  return *this;
43  }
44 
45  auto bind_arguments(const std::vector<std::string>& _args) -> query_builder&
46  {
47  args_ = &_args;
48  return *this;
49  }
50 
51  auto clear() -> query_builder&
52  {
53  args_ = nullptr;
54  zone_hint_.clear();
55  limit_ = 0;
56  offset_ = 0;
57  type_ = query_type::general;
58 
59  return *this;
60  }
61 
62  template <typename ConnectionType>
63  auto build(ConnectionType& _conn, const std::string& _query) -> irods::query<ConnectionType>
64  {
65  if (_query.empty()) {
66  THROW(USER_INPUT_STRING_ERR, "query string is empty");
67  }
68 
69  using T = typename query<ConnectionType>::query_type;
70 
71  return {&_conn,
72  _query,
73  args_,
74  zone_hint_,
75  limit_,
76  offset_,
77  type_ == query_type::general ? T::GENERAL : T::SPECIFIC};
78  }
79 
80  private:
81  const std::vector<std::string>* args_{};
82  std::string zone_hint_;
83  std::uintmax_t limit_ = 0;
84  std::uintmax_t offset_ = 0;
85  query_type type_ = query_type::general;
86  }; // class query_builder
87 
88 } // namespace experimental
89 } // namespace irods
90 
91 #endif // IRODS_QUERY_BUILDER_HPP
92 
irods::experimental::query_builder::row_offset
auto row_offset(std::uintmax_t _v) noexcept -> query_builder &
Definition: query_builder.hpp:39
THROW
#define THROW(_code, _msg)
Definition: irods_exception.hpp:68
irods::experimental::query_builder::offset_
std::uintmax_t offset_
Definition: query_builder.hpp:84
irods::experimental::query_type::general
@ general
irods::experimental::query_builder
Definition: query_builder.hpp:19
irods_query.hpp
irods::experimental::query_builder::type
auto type(query_type _v) noexcept -> query_builder &
Definition: query_builder.hpp:21
irods
Definition: apiHandler.hpp:35
irods::experimental::query_builder::row_limit
auto row_limit(std::uintmax_t _v) noexcept -> query_builder &
Definition: query_builder.hpp:33
irods::experimental::query_builder::clear
auto clear() -> query_builder &
Definition: query_builder.hpp:51
irods::experimental::query_builder::build
auto build(ConnectionType &_conn, const std::string &_query) -> irods::query< ConnectionType >
Definition: query_builder.hpp:63
irods::experimental::query_type
query_type
Definition: query_builder.hpp:13
irods::experimental::query_builder::limit_
std::uintmax_t limit_
Definition: query_builder.hpp:83
irods::experimental::query_builder::zone_hint
auto zone_hint(const std::string &_v) -> query_builder &
Definition: query_builder.hpp:27
irods::experimental::query_builder::type_
query_type type_
Definition: query_builder.hpp:85
rodsErrorTable.h
irods::experimental::query_builder::bind_arguments
auto bind_arguments(const std::vector< std::string > &_args) -> query_builder &
Definition: query_builder.hpp:45
irods::experimental::query_builder::zone_hint_
std::string zone_hint_
Definition: query_builder.hpp:82
irods::experimental::query_builder::args_
const std::vector< std::string > * args_
Definition: query_builder.hpp:81
irods::query< ConnectionType >
USER_INPUT_STRING_ERR
@ USER_INPUT_STRING_ERR
Definition: rodsErrorTable.h:281