21#include <boost/thread/future.hpp>
23#include "hazelcast/util/export.h"
24#include "hazelcast/client/connection/Connection.h"
25#include "hazelcast/client/sql/sql_page.h"
26#include "hazelcast/client/sql/sql_row_metadata.h"
67class HAZELCAST_API sql_result :
public std::enable_shared_from_this<sql_result>
74 class HAZELCAST_API page_iterator
77 page_iterator(std::shared_ptr<sql_result> result,
78 std::shared_ptr<sql_page> first_page);
80 page_iterator(
const page_iterator&) =
delete;
81 page_iterator(page_iterator&&) =
default;
82 page_iterator& operator=(
const page_iterator&) =
delete;
83 page_iterator& operator=(page_iterator&&) =
default;
93 boost::future<std::shared_ptr<sql_page>>
next();
102 std::shared_ptr<std::atomic<bool>> in_progress_;
103 std::shared_ptr<std::atomic<bool>> last_;
104 std::shared_ptr<sql_row_metadata> row_metadata_;
105 serialization::pimpl::SerializationService* serialization_;
106 std::shared_ptr<sql_result> result_;
107 std::shared_ptr<sql_page> first_page_;
113 class HAZELCAST_API page_iterator_sync
116 using difference_type = void;
117 using value_type = std::shared_ptr<sql_page>;
118 using pointer = std::shared_ptr<sql_page>;
119 using reference = std::shared_ptr<sql_page>&;
120 using iterator_category = std::input_iterator_tag;
130 std::chrono::milliseconds
timeout()
const;
132 friend HAZELCAST_API
bool operator==(
const page_iterator_sync&,
133 const page_iterator_sync&);
134 friend HAZELCAST_API
bool operator!=(
const page_iterator_sync&,
135 const page_iterator_sync&);
143 std::shared_ptr<sql_page>
operator*()
const;
166 friend class sql_result;
168 page_iterator_sync() =
default;
174 boost::future<std::shared_ptr<sql_page>> preloaded_page_;
178 std::shared_ptr<non_copyables> block_;
179 std::shared_ptr<sql_page> current_;
180 std::chrono::milliseconds timeout_;
186 class HAZELCAST_API row_iterator_sync
189 using difference_type = void;
193 using iterator_category = std::input_iterator_tag;
203 std::chrono::milliseconds
timeout()
const;
205 friend HAZELCAST_API
bool operator==(
const row_iterator_sync&,
206 const row_iterator_sync&);
207 friend HAZELCAST_API
bool operator!=(
const row_iterator_sync&,
208 const row_iterator_sync&);
239 friend class sql_result;
241 row_iterator_sync() =
default;
244 std::size_t row_idx_;
250 virtual ~sql_result();
284 boost::future<void>
close();
301 std::chrono::milliseconds timeout = std::chrono::milliseconds{ -1 });
302 page_iterator_sync pend();
303 row_iterator_sync begin(
304 std::chrono::milliseconds timeout = std::chrono::milliseconds{ -1 });
305 row_iterator_sync end();
308 friend class sql_service;
310 spi::ClientContext* client_context_;
311 sql_service* service_;
312 std::shared_ptr<connection::Connection> connection_;
313 impl::query_id query_id_;
314 int64_t update_count_;
315 std::shared_ptr<sql_row_metadata> row_metadata_;
316 std::shared_ptr<sql_page> first_page_;
318 bool iterator_requested_;
322 std::atomic<bool> closed_;
325 int32_t cursor_buffer_size_;
340 spi::ClientContext* client_context,
341 sql_service* service,
342 std::shared_ptr<connection::Connection> connection,
344 int64_t update_count,
345 std::shared_ptr<sql_row_metadata> row_metadata,
346 std::shared_ptr<sql_page> first_page,
347 int32_t cursor_buffer_size);
350 boost::future<std::shared_ptr<sql_page>> fetch_page();
353 boost::optional<T> to_object(serialization::pimpl::data data)
355 return client_context_->get_serialization_service().to_object<T>(data);
357 void check_closed()
const;
Copy is allowed for convenience but it does shallow copy so it should be avoided.
std::shared_ptr< sql_page > operator*() const
Dereferences current page.
std::chrono::milliseconds timeout() const
Retrieves the timeout.
page_iterator_sync operator++(int)=delete
Post increment operator is deleted.
void set_timeout(std::chrono::milliseconds)
Sets timeout for page fetch operation.
std::shared_ptr< sql_page > operator->() const
Dereferences current page.
Copy is allowed for convenience but it does shallow copy so it should be avoided.
bool has_next() const
Tells whether there are pages to be retrieved.
boost::future< std::shared_ptr< sql_page > > next()
Fetches the new page.
void set_timeout(std::chrono::milliseconds)
Sets timeout for page fetch operation.
row_iterator_sync operator++(int)=delete
Post increment operator is deleted because copy is discouraged.
const sql_page::sql_row & operator*() const
Returns current row.
const sql_page::sql_row * operator->() const
Returns current row.
std::chrono::milliseconds timeout() const
Retrieves the timeout.
bool row_set() const
Return whether this result has rows to iterate using the iterator() method.
const sql_row_metadata & row_metadata() const
Gets the row metadata.
page_iterator iterator()
Returns an iterator over the result pages.
int64_t update_count() const
Returns the number of rows updated by the statement or -1 if this result is a row set.
boost::future< void > close()
Release the resources associated with the query result.
A service to execute SQL statements.