Hazelcast C++ Client
Hazelcast C++ Client Library
Loading...
Searching...
No Matches
predicates.h
1/*
2 * Copyright (c) 2008-2025, Hazelcast, Inc. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#pragma once
17
18#include "hazelcast/client/serialization/serialization.h"
19
20#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
21#pragma warning(push)
22#pragma warning(disable : 4251) // for dll export
23#endif
24
25namespace hazelcast {
26namespace client {
28
29namespace query {
30struct HAZELCAST_API query_constants
31{
32 static const char* const KEY_ATTRIBUTE_NAME;
33 static const char* const THIS_ATTRIBUTE_NAME;
34};
35
41class HAZELCAST_API predicate
42{};
43
44struct HAZELCAST_API base_predicate : public predicate
45{
46 explicit base_predicate(hazelcast_client& client);
47
49};
50
51class HAZELCAST_API named_predicate : public base_predicate
52{
53protected:
54 explicit named_predicate(hazelcast_client& client,
55 const std::string& attribute_name);
56};
57
58class multi_predicate : public base_predicate
59{
60public:
61 template<typename... Args>
62 multi_predicate(hazelcast_client& client, const Args&... values)
63 : base_predicate(client)
64 {
65 out_stream.write<int32_t>(static_cast<int32_t>(sizeof...(values)));
66 out_stream.write_objects(values...);
67 }
68
69 template<typename... Args>
70 multi_predicate(const std::string attribute_name,
71 hazelcast_client& client,
72 const Args&... values)
73 : base_predicate(client)
74 {
75 out_stream.write(attribute_name);
76 out_stream.write<int32_t>(static_cast<int32_t>(sizeof...(values)));
77 out_stream.write_objects(values...);
78 }
79
80 template<typename T>
81 multi_predicate(const std::string attribute_name,
82 hazelcast_client& client,
83 const std::vector<T>& values)
84 : base_predicate(client)
85 {
86 out_stream.write(attribute_name);
87 out_stream.write<int32_t>(static_cast<int32_t>(values.size()));
88 for (const T& value : values) {
89 out_stream.write_object(value);
90 }
91 }
92};
93
94enum struct predicate_data_serializer_hook
95{
96 F_ID = -20,
97
98 SQL_PREDICATE = 0,
99
100 AND_PREDICATE = 1,
101
102 BETWEEN_PREDICATE = 2,
103
104 EQUAL_PREDICATE = 3,
105
106 GREATERLESS_PREDICATE = 4,
107
108 LIKE_PREDICATE = 5,
109
110 ILIKE_PREDICATE = 6,
111
112 IN_PREDICATE = 7,
113
114 INSTANCEOF_PREDICATE = 8,
115
116 NOTEQUAL_PREDICATE = 9,
117
118 NOT_PREDICATE = 10,
119
120 OR_PREDICATE = 11,
121
122 REGEX_PREDICATE = 12,
123
124 FALSE_PREDICATE = 13,
125
126 TRUE_PREDICATE = 14,
127
128 PAGING_PREDICATE = 15
129};
130
131class equal_predicate : public named_predicate
132{
133public:
138 template<typename T>
140 const std::string& attribute_name,
141 const T& value)
142 : named_predicate(client, attribute_name)
143 {
144 out_stream.write_object(value);
145 }
146};
147
148class not_equal_predicate : public named_predicate
149{
150public:
155 template<typename T>
157 const std::string& attribute_name,
158 const T& value)
159 : named_predicate(client, attribute_name)
160 {
161 out_stream.write_object(value);
162 }
163};
164
165class greater_less_predicate : public named_predicate
166{
167public:
175 template<typename T>
177 const std::string& attribute_name,
178 const T& value,
179 bool is_equal,
180 bool is_less)
181 : named_predicate(client, attribute_name)
182 {
183 out_stream.write_object(value);
184 out_stream.write(is_equal);
185 out_stream.write(is_less);
186 }
187};
188
189class between_predicate : public named_predicate
190{
191public:
197 template<typename FROM_TYPE, typename TO_TYPE>
199 const std::string& attribute_name,
200 const FROM_TYPE& from,
201 const TO_TYPE& to)
202 : named_predicate(client, attribute_name)
203 {
204 out_stream.write_object(to);
205 out_stream.write_object(from);
206 }
207};
208
209class HAZELCAST_API false_predicate : public base_predicate
210{
211public:
212 false_predicate(hazelcast_client& client);
213};
214
215class HAZELCAST_API true_predicate : public base_predicate
216{
217public:
218 true_predicate(hazelcast_client& client);
219};
220
221class HAZELCAST_API instance_of_predicate : public base_predicate
222{
223public:
229 const std::string& java_class_name);
230};
231
232class HAZELCAST_API sql_predicate : public base_predicate
233{
234public:
240 sql_predicate(hazelcast_client& client, const std::string& sql);
241};
242
243class HAZELCAST_API like_predicate : public named_predicate
244{
245public:
252 const std::string& attribute,
253 const std::string& expression);
254};
255
256class HAZELCAST_API ilike_predicate : public named_predicate
257{
258public:
265 const std::string& attribute,
266 const std::string& expression);
267};
268
269class HAZELCAST_API regex_predicate : public named_predicate
270{
271public:
278 const std::string& attribute,
279 const std::string& expression);
280};
281
282class in_predicate : public multi_predicate
283{
284public:
290 template<typename... Args>
292 const std::string& attribute_name,
293 const Args&... values)
294 : multi_predicate(attribute_name, client, values...)
295 {}
296
302 template<typename T>
304 const std::string& attribute_name,
305 const std::vector<T>& values)
306 : multi_predicate(attribute_name, client, values)
307 {}
308};
309
310class and_predicate : public multi_predicate
311{
312public:
313 template<typename... Args>
314 and_predicate(hazelcast_client& client, const Args&... values)
315 : multi_predicate(client, values...)
316 {}
317};
318
319class or_predicate : public multi_predicate
320{
321public:
322 template<typename... PredicateTypes>
323 or_predicate(hazelcast_client& client, const PredicateTypes&... values)
324 : multi_predicate(client, values...)
325 {}
326};
327
328class not_predicate : public base_predicate
329{
330public:
331 template<typename T>
332 not_predicate(hazelcast_client& client, const T& predicate)
333 : base_predicate(client)
334 {
335 out_stream.write_object(predicate);
336 }
337};
338} // namespace query
339
340namespace serialization {
341template<typename T>
343{
347 static constexpr int32_t get_factory_id() noexcept
348 {
349 return static_cast<int32_t>(
350 query::predicate_data_serializer_hook::F_ID);
351 }
352
357 static void write_data(const T& object, object_data_output& out)
358 {
359 out.append_bytes(object.out_stream.to_byte_array());
360 }
361
366 {
367 // Not need to read at the client side
368 BOOST_THROW_EXCEPTION(exception::hazelcast_serialization(
369 "readData", "Client should not need to use readdata method!!!"));
370 }
371};
372
373template<>
374struct hz_serializer<query::between_predicate>
375 : public BasePredicateSerializer<query::between_predicate>
376{
380 static constexpr int32_t get_class_id() noexcept
381 {
382 return static_cast<int32_t>(
383 query::predicate_data_serializer_hook::BETWEEN_PREDICATE);
384 }
385};
386
387template<>
388struct hz_serializer<query::equal_predicate>
389 : public BasePredicateSerializer<query::equal_predicate>
390{
394 static constexpr int32_t get_class_id() noexcept
395 {
396 return static_cast<int32_t>(
397 query::predicate_data_serializer_hook::EQUAL_PREDICATE);
398 }
399};
400
401template<>
402struct hz_serializer<query::not_equal_predicate>
403 : public BasePredicateSerializer<query::not_equal_predicate>
404{
408 static constexpr int32_t get_class_id() noexcept
409 {
410 return static_cast<int32_t>(
411 query::predicate_data_serializer_hook::NOTEQUAL_PREDICATE);
412 }
413};
414
415template<>
416struct hz_serializer<query::greater_less_predicate>
417 : public BasePredicateSerializer<query::greater_less_predicate>
418{
422 static constexpr int32_t get_class_id() noexcept
423 {
424 return static_cast<int32_t>(
425 query::predicate_data_serializer_hook::GREATERLESS_PREDICATE);
426 }
427};
428
429template<>
430struct hz_serializer<query::false_predicate>
431 : public BasePredicateSerializer<query::false_predicate>
432{
436 static constexpr int32_t get_class_id() noexcept
437 {
438 return static_cast<int32_t>(
439 query::predicate_data_serializer_hook::FALSE_PREDICATE);
440 }
441};
442
443template<>
444struct hz_serializer<query::true_predicate>
445 : public BasePredicateSerializer<query::true_predicate>
446{
450 static constexpr int32_t get_class_id() noexcept
451 {
452 return static_cast<int32_t>(
453 query::predicate_data_serializer_hook::TRUE_PREDICATE);
454 }
455};
456
457template<>
458struct hz_serializer<query::like_predicate>
459 : public BasePredicateSerializer<query::like_predicate>
460{
464 static constexpr int32_t get_class_id() noexcept
465 {
466 return static_cast<int32_t>(
467 query::predicate_data_serializer_hook::LIKE_PREDICATE);
468 }
469};
470
471template<>
472struct hz_serializer<query::instance_of_predicate>
473 : public BasePredicateSerializer<query::instance_of_predicate>
474{
478 static constexpr int32_t get_class_id() noexcept
479 {
480 return static_cast<int32_t>(
481 query::predicate_data_serializer_hook::INSTANCEOF_PREDICATE);
482 }
483};
484
485template<>
486struct hz_serializer<query::sql_predicate>
487 : public BasePredicateSerializer<query::sql_predicate>
488{
492 static constexpr int32_t get_class_id() noexcept
493 {
494 return static_cast<int32_t>(
495 query::predicate_data_serializer_hook::SQL_PREDICATE);
496 }
497};
498
499template<>
500struct hz_serializer<query::ilike_predicate>
501 : public BasePredicateSerializer<query::ilike_predicate>
502{
506 static constexpr int32_t get_class_id() noexcept
507 {
508 return static_cast<int32_t>(
509 query::predicate_data_serializer_hook::ILIKE_PREDICATE);
510 }
511};
512
513template<>
514struct hz_serializer<query::regex_predicate>
515 : public BasePredicateSerializer<query::regex_predicate>
516{
520 static constexpr int32_t get_class_id() noexcept
521 {
522 return static_cast<int32_t>(
523 query::predicate_data_serializer_hook::REGEX_PREDICATE);
524 }
525};
526
527template<>
528struct hz_serializer<query::in_predicate>
529 : public BasePredicateSerializer<query::in_predicate>
530{
534 static constexpr int32_t get_class_id() noexcept
535 {
536 return static_cast<int32_t>(
537 query::predicate_data_serializer_hook::IN_PREDICATE);
538 }
539};
540
541template<>
542struct hz_serializer<query::and_predicate>
543 : public BasePredicateSerializer<query::and_predicate>
544{
548 static constexpr int32_t get_class_id() noexcept
549 {
550 return static_cast<int32_t>(
551 query::predicate_data_serializer_hook::AND_PREDICATE);
552 }
553};
554
555template<>
556struct hz_serializer<query::or_predicate>
557 : public BasePredicateSerializer<query::or_predicate>
558{
562 static constexpr int32_t get_class_id() noexcept
563 {
564 return static_cast<int32_t>(
565 query::predicate_data_serializer_hook::OR_PREDICATE);
566 }
567};
568
569template<>
570struct hz_serializer<query::not_predicate>
571 : public BasePredicateSerializer<query::not_predicate>
572{
576 static constexpr int32_t get_class_id() noexcept
577 {
578 return static_cast<int32_t>(
579 query::predicate_data_serializer_hook::NOT_PREDICATE);
580 }
581};
582}; // namespace serialization
583} // namespace client
584} // namespace hazelcast
585
586#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
587#pragma warning(pop)
588#endif
between_predicate(hazelcast_client &client, const std::string &attribute_name, const FROM_TYPE &from, const TO_TYPE &to)
Definition predicates.h:198
equal_predicate(hazelcast_client &client, const std::string &attribute_name, const T &value)
Definition predicates.h:139
greater_less_predicate(hazelcast_client &client, const std::string &attribute_name, const T &value, bool is_equal, bool is_less)
Definition predicates.h:176
ilike_predicate(hazelcast_client &client, const std::string &attribute, const std::string &expression)
Definition query.cpp:60
in_predicate(hazelcast_client &client, const std::string &attribute_name, const std::vector< T > &values)
The type of Args should be able to be serialized.
Definition predicates.h:303
in_predicate(hazelcast_client &client, const std::string &attribute_name, const Args &... values)
The type of Args should be able to be serialized.
Definition predicates.h:291
instance_of_predicate(hazelcast_client &client, const std::string &java_class_name)
Definition query.cpp:39
like_predicate(hazelcast_client &client, const std::string &attribute, const std::string &expression)
Definition query.cpp:52
not_equal_predicate(hazelcast_client &client, const std::string &attribute_name, const T &value)
Definition predicates.h:156
This is a marker class for Predicate classes.
Definition predicates.h:42
regex_predicate(hazelcast_client &client, const std::string &attribute, const std::string &expression)
Definition query.cpp:68
sql_predicate(hazelcast_client &client, const std::string &sql)
Definition query.cpp:46
static constexpr int32_t get_factory_id() noexcept
Definition predicates.h:347
static void write_data(const T &object, object_data_output &out)
Defines how this class will be written.
Definition predicates.h:357
static T read_data(object_data_input &in)
Should not be called at the client side!
Definition predicates.h:365
Classes derived from this class should implement the following static methods: static int32_t get_cla...