Apache Ignite C++ Client
Loading...
Searching...
No Matches
record_view.h
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#pragma once
19
20#include <ignite/client/detail/type_mapping_utils.h>
21#include <ignite/client/table/ignite_tuple.h>
22#include <ignite/client/transaction/transaction.h>
23#include <ignite/client/type_mapping.h>
24
25#include "ignite/common/detail/config.h"
26#include <ignite/common/ignite_result.h>
27
28#include <memory>
29#include <type_traits>
30#include <utility>
31#include <vector>
32
33namespace ignite {
34
35class table;
36
37namespace detail {
38class table_impl;
39}
40
41template<typename T>
42class record_view;
43
47template<>
48class record_view<ignite_tuple> {
49 friend class table;
50
51public:
52 typedef ignite_tuple value_type;
53
54 // Deleted
55 record_view(const record_view &) = delete;
56 record_view &operator=(const record_view &) = delete;
57
58 // Default
59 record_view() = default;
60 record_view(record_view &&) noexcept = default;
61 record_view &operator=(record_view &&) noexcept = default;
62
72 IGNITE_API void get_async(
73 transaction *tx, const value_type &key, ignite_callback<std::optional<value_type>> callback);
74
83 [[nodiscard]] IGNITE_API std::optional<value_type> get(transaction *tx, const value_type &key) {
84 return sync<std::optional<value_type>>(
85 [this, tx, &key](auto callback) { get_async(tx, key, std::move(callback)); });
86 }
87
100 IGNITE_API void get_all_async(transaction *tx, std::vector<value_type> keys,
101 ignite_callback<std::vector<std::optional<value_type>>> callback);
102
114 [[nodiscard]] IGNITE_API std::vector<std::optional<value_type>> get_all(
115 transaction *tx, std::vector<value_type> keys) {
116 return sync<std::vector<std::optional<value_type>>>([this, tx, keys = std::move(keys)](auto callback) mutable {
117 get_all_async(tx, std::move(keys), std::move(callback));
118 });
119 }
120
129 IGNITE_API void upsert_async(transaction *tx, const value_type &record, ignite_callback<void> callback);
130
138 IGNITE_API void upsert(transaction *tx, const value_type &record) {
139 sync<void>([this, tx, &record](auto callback) { upsert_async(tx, record, std::move(callback)); });
140 }
141
151 IGNITE_API void upsert_all_async(transaction *tx, std::vector<value_type> records, ignite_callback<void> callback);
152
160 IGNITE_API void upsert_all(transaction *tx, std::vector<value_type> records) {
161 sync<void>([this, tx, records = std::move(records)](
162 auto callback) mutable { upsert_all_async(tx, std::move(records), std::move(callback)); });
163 }
164
174 IGNITE_API void get_and_upsert_async(
175 transaction *tx, const value_type &record, ignite_callback<std::optional<value_type>> callback);
176
185 [[nodiscard]] IGNITE_API std::optional<value_type> get_and_upsert(transaction *tx, const value_type &record) {
186 return sync<std::optional<value_type>>(
187 [this, tx, &record](auto callback) { get_and_upsert_async(tx, record, std::move(callback)); });
188 }
189
200 IGNITE_API void insert_async(transaction *tx, const value_type &record, ignite_callback<bool> callback);
201
209 IGNITE_API bool insert(transaction *tx, const value_type &record) {
210 return sync<bool>([this, tx, &record](auto callback) { insert_async(tx, record, std::move(callback)); });
211 }
212
222 IGNITE_API void insert_all_async(
223 transaction *tx, std::vector<value_type> records, ignite_callback<std::vector<value_type>> callback);
224
233 IGNITE_API std::vector<value_type> insert_all(transaction *tx, std::vector<value_type> records) {
234 return sync<std::vector<value_type>>([this, tx, records = std::move(records)](auto callback) mutable {
235 insert_all_async(tx, std::move(records), std::move(callback));
236 });
237 }
238
249 IGNITE_API void replace_async(transaction *tx, const value_type &record, ignite_callback<bool> callback);
250
261 IGNITE_API bool replace(transaction *tx, const value_type &record) {
262 return sync<bool>([this, tx, &record](auto callback) { replace_async(tx, record, std::move(callback)); });
263 }
264
276 IGNITE_API void replace_async(
277 transaction *tx, const value_type &record, const value_type &new_record, ignite_callback<bool> callback);
278
289 IGNITE_API bool replace(transaction *tx, const value_type &record, const value_type &new_record) {
290 return sync<bool>([this, tx, &record, &new_record](
291 auto callback) { replace_async(tx, record, new_record, std::move(callback)); });
292 }
293
304 IGNITE_API void get_and_replace_async(
305 transaction *tx, const value_type &record, ignite_callback<std::optional<value_type>> callback);
306
317 [[nodiscard]] IGNITE_API std::optional<value_type> get_and_replace(transaction *tx, const value_type &record) {
318 return sync<std::optional<value_type>>(
319 [this, tx, &record](auto callback) { get_and_replace_async(tx, record, std::move(callback)); });
320 }
321
331 IGNITE_API void remove_async(transaction *tx, const value_type &key, ignite_callback<bool> callback);
332
341 IGNITE_API bool remove(transaction *tx, const value_type &record) {
342 return sync<bool>([this, tx, &record](auto callback) { remove_async(tx, record, std::move(callback)); });
343 }
344
355 IGNITE_API void remove_exact_async(transaction *tx, const value_type &record, ignite_callback<bool> callback);
356
367 IGNITE_API bool remove_exact(transaction *tx, const value_type &record) {
368 return sync<bool>([this, tx, &record](auto callback) { remove_exact_async(tx, record, std::move(callback)); });
369 }
370
380 IGNITE_API void get_and_remove_async(
381 transaction *tx, const value_type &key, ignite_callback<std::optional<value_type>> callback);
382
391 IGNITE_API std::optional<value_type> get_and_remove(transaction *tx, const value_type &key) {
392 return sync<std::optional<value_type>>(
393 [this, tx, &key](auto callback) { get_and_remove_async(tx, key, std::move(callback)); });
394 }
395
406 IGNITE_API void remove_all_async(
407 transaction *tx, std::vector<value_type> keys, ignite_callback<std::vector<value_type>> callback);
408
418 IGNITE_API std::vector<value_type> remove_all(transaction *tx, std::vector<value_type> keys) {
419 return sync<std::vector<value_type>>([this, tx, keys = std::move(keys)](auto callback) mutable {
420 remove_all_async(tx, std::move(keys), std::move(callback));
421 });
422 }
423
434 IGNITE_API void remove_all_exact_async(
435 transaction *tx, std::vector<value_type> records, ignite_callback<std::vector<value_type>> callback);
436
446 IGNITE_API std::vector<value_type> remove_all_exact(transaction *tx, std::vector<value_type> records) {
447 return sync<std::vector<value_type>>([this, tx, records = std::move(records)](auto callback) mutable {
448 remove_all_exact_async(tx, std::move(records), std::move(callback));
449 });
450 }
451
452private:
458 explicit record_view(std::shared_ptr<detail::table_impl> impl)
459 : m_impl(std::move(impl)) {}
460
462 std::shared_ptr<detail::table_impl> m_impl;
463};
464
468template<typename T>
469class record_view {
470 friend class table;
471
472public:
473 typedef typename std::decay<T>::type value_type;
474
475 // Deleted
476 record_view(const record_view &) = delete;
477 record_view &operator=(const record_view &) = delete;
478
479 // Default
480 record_view() = default;
481 record_view(record_view &&) noexcept = default;
482 record_view &operator=(record_view &&) noexcept = default;
483
493 void get_async(transaction *tx, const value_type &key, ignite_callback<std::optional<value_type>> callback) {
494 m_delegate.get_async(tx, convert_to_tuple(key),
495 [callback = std::move(callback)](auto res) { callback(convert_result<value_type>(std::move(res))); });
496 }
497
506 [[nodiscard]] std::optional<value_type> get(transaction *tx, const value_type &key) {
507 return sync<std::optional<value_type>>(
508 [this, tx, &key](auto callback) { get_async(tx, key, std::move(callback)); });
509 }
510
523 void get_all_async(transaction *tx, std::vector<value_type> keys,
524 ignite_callback<std::vector<std::optional<value_type>>> callback) {
525 m_delegate.get_all_async(tx, values_to_tuples<value_type>(std::move(keys)),
526 [callback = std::move(callback)](auto res) { callback(convert_result<value_type>(std::move(res))); });
527 }
528
540 [[nodiscard]] std::vector<std::optional<value_type>> get_all(transaction *tx, std::vector<value_type> keys) {
541 return sync<std::vector<std::optional<value_type>>>([this, tx, keys = std::move(keys)](auto callback) mutable {
542 get_all_async(tx, std::move(keys), std::move(callback));
543 });
544 }
545
554 void upsert_async(transaction *tx, const value_type &record, ignite_callback<void> callback) {
555 m_delegate.upsert_async(tx, convert_to_tuple(record), std::move(callback));
556 }
557
565 void upsert(transaction *tx, const value_type &record) {
566 sync<void>([this, tx, &record](auto callback) { upsert_async(tx, record, std::move(callback)); });
567 }
568
578 void upsert_all_async(transaction *tx, std::vector<value_type> records, ignite_callback<void> callback) {
579 m_delegate.upsert_all_async(tx, values_to_tuples<value_type>(std::move(records)), std::move(callback));
580 }
581
589 void upsert_all(transaction *tx, std::vector<value_type> records) {
590 sync<void>([this, tx, records = std::move(records)](
591 auto callback) mutable { upsert_all_async(tx, std::move(records), std::move(callback)); });
592 }
593
604 transaction *tx, const value_type &record, ignite_callback<std::optional<value_type>> callback) {
605 m_delegate.get_and_upsert_async(tx, convert_to_tuple(record),
606 [callback = std::move(callback)](auto res) { callback(convert_result<value_type>(std::move(res))); });
607 }
608
617 [[nodiscard]] std::optional<value_type> get_and_upsert(transaction *tx, const value_type &record) {
618 return sync<std::optional<value_type>>(
619 [this, tx, &record](auto callback) { get_and_upsert_async(tx, record, std::move(callback)); });
620 }
621
632 void insert_async(transaction *tx, const value_type &record, ignite_callback<bool> callback) {
633 m_delegate.insert_async(tx, convert_to_tuple(record), std::move(callback));
634 }
635
643 bool insert(transaction *tx, const value_type &record) {
644 return sync<bool>([this, tx, &record](auto callback) { insert_async(tx, record, std::move(callback)); });
645 }
646
657 transaction *tx, std::vector<value_type> records, ignite_callback<std::vector<value_type>> callback) {
658 m_delegate.insert_all_async(tx, values_to_tuples<value_type>(std::move(records)),
659 [callback = std::move(callback)](auto res) { callback(convert_result<value_type>(std::move(res))); });
660 }
661
670 std::vector<value_type> insert_all(transaction *tx, std::vector<value_type> records) {
671 return sync<std::vector<value_type>>([this, tx, records = std::move(records)](auto callback) mutable {
672 insert_all_async(tx, std::move(records), std::move(callback));
673 });
674 }
675
686 void replace_async(transaction *tx, const value_type &record, ignite_callback<bool> callback) {
687 m_delegate.replace_async(tx, convert_to_tuple(record), std::move(callback));
688 }
689
700 bool replace(transaction *tx, const value_type &record) {
701 return sync<bool>([this, tx, &record](auto callback) { replace_async(tx, record, std::move(callback)); });
702 }
703
716 transaction *tx, const value_type &record, const value_type &new_record, ignite_callback<bool> callback) {
717 m_delegate.replace_async(tx, convert_to_tuple(record), convert_to_tuple(new_record), std::move(callback));
718 }
719
730 bool replace(transaction *tx, const value_type &record, const value_type &new_record) {
731 return sync<bool>([this, tx, &record, &new_record](
732 auto callback) { replace_async(tx, record, new_record, std::move(callback)); });
733 }
734
746 transaction *tx, const value_type &record, ignite_callback<std::optional<value_type>> callback) {
747 m_delegate.get_and_replace_async(tx, convert_to_tuple(record),
748 [callback = std::move(callback)](auto res) { callback(convert_result<value_type>(std::move(res))); });
749 }
750
761 [[nodiscard]] std::optional<value_type> get_and_replace(transaction *tx, const value_type &record) {
762 return sync<std::optional<value_type>>(
763 [this, tx, &record](auto callback) { get_and_replace_async(tx, record, std::move(callback)); });
764 }
765
775 void remove_async(transaction *tx, const value_type &key, ignite_callback<bool> callback) {
776 m_delegate.remove_async(tx, convert_to_tuple(key), std::move(callback));
777 }
778
787 bool remove(transaction *tx, const value_type &record) {
788 return sync<bool>([this, tx, &record](auto callback) { remove_async(tx, record, std::move(callback)); });
789 }
790
801 void remove_exact_async(transaction *tx, const value_type &record, ignite_callback<bool> callback) {
802 m_delegate.remove_exact_async(tx, convert_to_tuple(record), std::move(callback));
803 }
804
815 bool remove_exact(transaction *tx, const value_type &record) {
816 return sync<bool>([this, tx, &record](auto callback) { remove_exact_async(tx, record, std::move(callback)); });
817 }
818
829 transaction *tx, const value_type &key, ignite_callback<std::optional<value_type>> callback) {
830 m_delegate.get_and_remove_async(tx, convert_to_tuple(key),
831 [callback = std::move(callback)](auto res) { callback(convert_result<value_type>(std::move(res))); });
832 }
833
842 std::optional<value_type> get_and_remove(transaction *tx, const value_type &key) {
843 return sync<std::optional<value_type>>(
844 [this, tx, &key](auto callback) { get_and_remove_async(tx, key, std::move(callback)); });
845 }
846
858 transaction *tx, std::vector<value_type> keys, ignite_callback<std::vector<value_type>> callback) {
859 m_delegate.remove_all_async(tx, values_to_tuples<value_type>(std::move(keys)),
860 [callback = std::move(callback)](auto res) { callback(convert_result<value_type>(std::move(res))); });
861 }
862
872 std::vector<value_type> remove_all(transaction *tx, std::vector<value_type> keys) {
873 return sync<std::vector<value_type>>([this, tx, keys = std::move(keys)](auto callback) mutable {
874 remove_all_async(tx, std::move(keys), std::move(callback));
875 });
876 }
877
889 transaction *tx, std::vector<value_type> records, ignite_callback<std::vector<value_type>> callback) {
890 m_delegate.remove_all_exact_async(tx, values_to_tuples<value_type>(std::move(records)),
891 [callback = std::move(callback)](auto res) { callback(convert_result<value_type>(std::move(res))); });
892 }
893
903 std::vector<value_type> remove_all_exact(transaction *tx, std::vector<value_type> records) {
904 return sync<std::vector<value_type>>([this, tx, records = std::move(records)](auto callback) mutable {
905 remove_all_exact_async(tx, std::move(records), std::move(callback));
906 });
907 }
908
909private:
915 explicit record_view(record_view<ignite_tuple> delegate)
916 : m_delegate(std::move(delegate)) {}
917
919 record_view<ignite_tuple> m_delegate;
920};
921
922} // namespace ignite
Definition ignite_tuple.h:40
IGNITE_API std::optional< value_type > get_and_remove(transaction *tx, const value_type &key)
Definition record_view.h:391
IGNITE_API std::vector< std::optional< value_type > > get_all(transaction *tx, std::vector< value_type > keys)
Definition record_view.h:114
IGNITE_API bool replace(transaction *tx, const value_type &record)
Definition record_view.h:261
IGNITE_API std::vector< value_type > insert_all(transaction *tx, std::vector< value_type > records)
Definition record_view.h:233
IGNITE_API void upsert(transaction *tx, const value_type &record)
Definition record_view.h:138
IGNITE_API std::vector< value_type > remove_all_exact(transaction *tx, std::vector< value_type > records)
Definition record_view.h:446
IGNITE_API std::optional< value_type > get_and_replace(transaction *tx, const value_type &record)
Definition record_view.h:317
IGNITE_API bool replace(transaction *tx, const value_type &record, const value_type &new_record)
Definition record_view.h:289
IGNITE_API bool insert(transaction *tx, const value_type &record)
Definition record_view.h:209
IGNITE_API bool remove(transaction *tx, const value_type &record)
Definition record_view.h:341
IGNITE_API bool remove_exact(transaction *tx, const value_type &record)
Definition record_view.h:367
IGNITE_API std::vector< value_type > remove_all(transaction *tx, std::vector< value_type > keys)
Definition record_view.h:418
IGNITE_API std::optional< value_type > get_and_upsert(transaction *tx, const value_type &record)
Definition record_view.h:185
IGNITE_API void upsert_all(transaction *tx, std::vector< value_type > records)
Definition record_view.h:160
IGNITE_API std::optional< value_type > get(transaction *tx, const value_type &key)
Definition record_view.h:83
Definition record_view.h:469
std::vector< value_type > remove_all(transaction *tx, std::vector< value_type > keys)
Definition record_view.h:872
void get_and_replace_async(transaction *tx, const value_type &record, ignite_callback< std::optional< value_type > > callback)
Definition record_view.h:745
std::vector< value_type > remove_all_exact(transaction *tx, std::vector< value_type > records)
Definition record_view.h:903
void remove_all_async(transaction *tx, std::vector< value_type > keys, ignite_callback< std::vector< value_type > > callback)
Definition record_view.h:857
void replace_async(transaction *tx, const value_type &record, ignite_callback< bool > callback)
Definition record_view.h:686
std::vector< value_type > insert_all(transaction *tx, std::vector< value_type > records)
Definition record_view.h:670
bool replace(transaction *tx, const value_type &record)
Definition record_view.h:700
std::optional< value_type > get_and_replace(transaction *tx, const value_type &record)
Definition record_view.h:761
void remove_all_exact_async(transaction *tx, std::vector< value_type > records, ignite_callback< std::vector< value_type > > callback)
Definition record_view.h:888
void get_and_remove_async(transaction *tx, const value_type &key, ignite_callback< std::optional< value_type > > callback)
Definition record_view.h:828
bool insert(transaction *tx, const value_type &record)
Definition record_view.h:643
void upsert_all(transaction *tx, std::vector< value_type > records)
Definition record_view.h:589
void get_async(transaction *tx, const value_type &key, ignite_callback< std::optional< value_type > > callback)
Definition record_view.h:493
void replace_async(transaction *tx, const value_type &record, const value_type &new_record, ignite_callback< bool > callback)
Definition record_view.h:715
bool replace(transaction *tx, const value_type &record, const value_type &new_record)
Definition record_view.h:730
std::vector< std::optional< value_type > > get_all(transaction *tx, std::vector< value_type > keys)
Definition record_view.h:540
bool remove(transaction *tx, const value_type &record)
Definition record_view.h:787
std::optional< value_type > get(transaction *tx, const value_type &key)
Definition record_view.h:506
void upsert_async(transaction *tx, const value_type &record, ignite_callback< void > callback)
Definition record_view.h:554
void upsert_all_async(transaction *tx, std::vector< value_type > records, ignite_callback< void > callback)
Definition record_view.h:578
void get_and_upsert_async(transaction *tx, const value_type &record, ignite_callback< std::optional< value_type > > callback)
Definition record_view.h:603
void get_all_async(transaction *tx, std::vector< value_type > keys, ignite_callback< std::vector< std::optional< value_type > > > callback)
Definition record_view.h:523
void upsert(transaction *tx, const value_type &record)
Definition record_view.h:565
std::optional< value_type > get_and_remove(transaction *tx, const value_type &key)
Definition record_view.h:842
bool remove_exact(transaction *tx, const value_type &record)
Definition record_view.h:815
void remove_exact_async(transaction *tx, const value_type &record, ignite_callback< bool > callback)
Definition record_view.h:801
void insert_all_async(transaction *tx, std::vector< value_type > records, ignite_callback< std::vector< value_type > > callback)
Definition record_view.h:656
void insert_async(transaction *tx, const value_type &record, ignite_callback< bool > callback)
Definition record_view.h:632
void remove_async(transaction *tx, const value_type &key, ignite_callback< bool > callback)
Definition record_view.h:775
std::optional< value_type > get_and_upsert(transaction *tx, const value_type &record)
Definition record_view.h:617
Definition table.h:41
Definition transaction.h:35