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_processor.hpp
Go to the documentation of this file.
1 #ifndef IRODS_QUERY_PROCESSOR_HPP
2 #define IRODS_QUERY_PROCESSOR_HPP
3 
4 #include "thread_pool.hpp"
5 #include "irods_query.hpp"
6 #include "irods_exception.hpp"
7 
8 #include <string>
9 #include <functional>
10 #include <future>
11 #include <vector>
12 #include <tuple>
13 #include <memory>
14 #include <exception>
15 
16 namespace irods
17 {
18  template <typename ConnectionType>
20  {
21  public:
22  // clang-format off
23  using error = std::tuple<int, std::string>;
24  using errors = std::vector<error>;
26  using job = std::function<void (const result_row&)>;
28  // clang-format on
29 
30  query_processor(const std::string& _query, job _job, uint32_t _limit = 0, query_type _type = query_type::GENERAL)
31  : query_{_query}
32  , job_{_job}
33  , limit_{_limit}
34  , type_{_type}
35  {
36  }
37 
38  query_processor(const query_processor&) = delete;
40  uint32_t size() { return size_; }
41 
42  class future
43  {
45 
46  std::vector<std::shared_ptr<std::promise<error>>> promises;
47 
48  void push_back(std::shared_ptr<std::promise<error>> p) {
49  promises.push_back(p);
50  }
51 
52  public:
53  auto get() {
54  errors errs{};
55  errs.reserve(promises.size());
56  for(auto&& p : promises) {
57  auto&& e = p->get_future().get();
58  if(std::get<0>(e) < 0) {
59  errs.push_back(std::move(e));
60  }
61  }
62 
63  return errs;
64  }
65  };
66 
67  auto execute(thread_pool& _thread_pool, ConnectionType& _conn)
68  {
69  future f;
70  query<ConnectionType> q{&_conn, query_, limit_, 0, type_};
71 
72  size_ = q.size();
73 
74  for (auto&& r : q) {
75  auto p = std::make_shared<std::promise<error>>();
76  f.push_back(p);
77 
78  thread_pool::post(_thread_pool, [this, p, r]() mutable {
79  try {
80  job_(r);
81  p->set_value({0, ""});
82  }
83  catch (const irods::exception& e) {
84  p->set_value({e.code(), e.what()});
85  }
86  catch (const std::exception& e) {
87  p->set_value({SYS_UNKNOWN_ERROR, e.what()});
88  }
89  catch (...) {
90  p->set_value({SYS_UNKNOWN_ERROR, "Unknown error occurred while processing job."});
91  }
92  });
93 
94  } // for row
95 
96  return f;
97  }
98 
99  private:
100  uint32_t size_;
101  std::string query_;
103  uint32_t limit_;
105  };
106 } // namespace irods
107 
108 #endif // IRODS_QUERY_PROCESSOR_HPP
109 
irods::query_processor::job_
job job_
Definition: query_processor.hpp:102
irods::query_processor::future::push_back
void push_back(std::shared_ptr< std::promise< error >> p)
Definition: query_processor.hpp:48
irods::query_processor::future::promises
std::vector< std::shared_ptr< std::promise< error > > > promises
Definition: query_processor.hpp:46
irods::query_processor::query_type
typename query< ConnectionType >::query_type query_type
Definition: query_processor.hpp:27
irods::query_processor::query_processor
query_processor(const query_processor &)=delete
irods_exception.hpp
pid_age.p
p
Definition: pid_age.py:13
irods::query_processor::errors
std::vector< error > errors
Definition: query_processor.hpp:24
irods::query_processor::query_
std::string query_
Definition: query_processor.hpp:101
irods::thread_pool::post
static void post(thread_pool &_pool, Function &&_func)
Definition: thread_pool.hpp:35
irods::query_processor::future::query_processor
friend query_processor
Definition: query_processor.hpp:44
irods_query.hpp
irods::query_processor::future::get
auto get()
Definition: query_processor.hpp:53
irods::query_processor
Definition: query_processor.hpp:20
SYS_UNKNOWN_ERROR
@ SYS_UNKNOWN_ERROR
Definition: rodsErrorTable.h:222
irods::query_processor::query_processor
query_processor(const std::string &_query, job _job, uint32_t _limit=0, query_type _type=query_type::GENERAL)
Definition: query_processor.hpp:30
irods
Definition: apiHandler.hpp:35
irods::query_processor::limit_
uint32_t limit_
Definition: query_processor.hpp:103
irods::query_processor::size
uint32_t size()
Definition: query_processor.hpp:40
terminate_irods_processes.e
e
Definition: terminate_irods_processes.py:19
irods::query_processor::type_
query_type type_
Definition: query_processor.hpp:104
irods::query_processor::result_row
typename query< ConnectionType >::value_type result_row
Definition: query_processor.hpp:25
irods::query_processor::size_
uint32_t size_
Definition: query_processor.hpp:100
irods::query_processor::execute
auto execute(thread_pool &_thread_pool, ConnectionType &_conn)
Definition: query_processor.hpp:67
irods::experimental::filesystem::client::move
auto move(rcComm_t &_comm, const path &_old_p, const path &_new_p) -> void
Definition: filesystem.cpp:881
irods::thread_pool
Definition: thread_pool.hpp:11
irods::exception
Definition: irods_exception.hpp:15
irods::query_processor::future
Definition: query_processor.hpp:43
irods::query_processor::job
std::function< void(const result_row &)> job
Definition: query_processor.hpp:26
irods::query
Definition: irods_query.hpp:25
thread_pool.hpp
irods::query_processor::operator=
query_processor & operator=(const query_processor &)=delete
irods::query_processor::error
std::tuple< int, std::string > error
Definition: query_processor.hpp:23