Line data Source code
1 : /**
2 : Copyright (c) 2019-2022 Roman Katuntsev <sbkarr@stappler.org>
3 : Copyright (c) 2023-2024 Stappler LLC <admin@stappler.dev>
4 :
5 : Permission is hereby granted, free of charge, to any person obtaining a copy
6 : of this software and associated documentation files (the "Software"), to deal
7 : in the Software without restriction, including without limitation the rights
8 : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 : copies of the Software, and to permit persons to whom the Software is
10 : furnished to do so, subject to the following conditions:
11 :
12 : The above copyright notice and this permission notice shall be included in
13 : all copies or substantial portions of the Software.
14 :
15 : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 : THE SOFTWARE.
22 : **/
23 :
24 : #ifndef STAPPLER_DB_SPDBCONTINUETOKEN_H_
25 : #define STAPPLER_DB_SPDBCONTINUETOKEN_H_
26 :
27 : #include "SPDbQuery.h"
28 :
29 : namespace STAPPLER_VERSIONIZED stappler::db {
30 :
31 : class ContinueToken {
32 : public:
33 : enum Flags {
34 : None = 0,
35 : Initial = 1,
36 : Reverse = 2,
37 : Inverted = 4,
38 : };
39 :
40 2500 : ContinueToken() = default;
41 : ContinueToken(const StringView &f, size_t count, bool reverse);
42 : ContinueToken(const StringView &);
43 :
44 25 : ContinueToken(const ContinueToken &) = default;
45 2425 : ContinueToken(ContinueToken &&) = default;
46 :
47 375 : ContinueToken &operator=(const ContinueToken &) = default;
48 : ContinueToken &operator=(ContinueToken &&) = default;
49 :
50 3775 : explicit operator bool () const { return !field.empty() && count > 0; }
51 :
52 : bool hasPrev() const;
53 : bool hasNext() const;
54 : bool isInit() const;
55 :
56 : String encode() const;
57 : Value perform(const Scheme &, const Transaction &, Query &);
58 : Value perform(const Scheme &, const Transaction &, Query &, Ordering ord);
59 :
60 : Value performOrdered(const Scheme &, const Transaction &, Query &);
61 :
62 : void refresh(const Scheme &, const Transaction &, Query &);
63 :
64 : String encodeNext() const;
65 : String encodePrev() const;
66 :
67 : size_t getStart() const;
68 : size_t getEnd() const;
69 : size_t getTotal() const;
70 : size_t getCount() const;
71 : size_t getFetched() const;
72 : StringView getField() const;
73 :
74 : size_t getNumResults() const;
75 :
76 : bool hasFlag(Flags) const;
77 : void setFlag(Flags);
78 : void unsetFlag(Flags);
79 :
80 : const Value &getFirstVec() const;
81 : const Value &getLastVec() const;
82 :
83 : protected:
84 : bool hasPrevImpl() const;
85 : bool hasNextImpl() const;
86 :
87 : String encodeNextImpl() const;
88 : String encodePrevImpl() const;
89 :
90 : bool _init = false;
91 : size_t _numResults = 0;
92 : String field;
93 :
94 : Value initVec;
95 :
96 : Value firstVec;
97 : Value lastVec;
98 :
99 : size_t count = 0;
100 : size_t fetched = 0;
101 : size_t total = 0;
102 :
103 : Flags flags = None;
104 : };
105 :
106 : SP_DEFINE_ENUM_AS_MASK(ContinueToken::Flags)
107 :
108 : }
109 :
110 : #endif /* STAPPLER_DB_SPDBCONTINUETOKEN_H_ */
|