1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef KVSTORE_RESULT_SET_H
17 #define KVSTORE_RESULT_SET_H
18 
19 #include "types.h"
20 
21 namespace OHOS {
22 namespace DistributedKv {
23 class KvStoreResultSet {
24 public:
25     inline static constexpr int INVALID_COUNT = -ALREADY_CLOSED;
26     inline static constexpr int INVALID_POSITION = -ALREADY_CLOSED;
27 
28     /**
29      * @brief Destructor.
30      */
~KvStoreResultSet()31     API_EXPORT virtual ~KvStoreResultSet() {}
32 
33     /**
34      * @brief Get the count of rows in the result set.
35      * @return the count of rows.
36     */
37     virtual int GetCount() const = 0;
38 
39     /**
40      * @brief Get the current read position of the result set.
41      * @return The position value.
42     */
43     virtual int GetPosition() const = 0;
44 
45     /**
46      * @brief Move the read position to first row.
47      * @return Return false If the result set is empty.
48     */
49     virtual bool MoveToFirst() = 0;
50 
51     /**
52      * @brief Move the read position to the last row.
53      * @return Return false if the result set is empty.
54     */
55     virtual bool MoveToLast() = 0;
56 
57     /**
58      * @brief Move the read position to the next row.
59      * @return Return false if the result set is empty
60      *         or the read position is already past the last entry in the result set.
61     */
62     virtual bool MoveToNext() = 0;
63 
64     /**
65      * @brief Move the read position to the previous row.
66      * @return Return false if result set is empty
67      *         or the read position is already before the first entry in the result set.
68     */
69     virtual bool MoveToPrevious() = 0;
70 
71     /**
72      * @brief Move the read position by a relative amount from the current position.
73      * @param offset Relative amount.
74      * @return Return true for success, false for failure.
75     */
76     virtual bool Move(int offset) = 0;
77 
78     /**
79      * @brief Move the read position to an absolute position value.
80      * @param position The absolute position.
81      * @return Return true for success, false for failure.
82     */
83     virtual bool MoveToPosition(int position) = 0;
84 
85     /**
86      * @brief Returns whether the read position is pointing to the first row.
87      * @return Return true for success, false for failure.
88     */
89     virtual bool IsFirst() const = 0;
90 
91     /**
92      * @brief Returns whether the read position is pointing to the last row.
93      * @return Return true for success, false for failure.
94     */
95     virtual bool IsLast() const = 0;
96 
97     /**
98      * @brief Returns whether the read position is before the first row.
99      * @return Return true for success, false for failure.
100     */
101     virtual bool IsBeforeFirst() const = 0;
102 
103     /**
104      * @brief Returns whether the read position is after the last row.
105      * @return Return true for success, false for failure.
106     */
107     virtual bool IsAfterLast() const = 0;
108 
109     /**
110      * @brief Get a key-value entry.
111      * @return Return SUCCESS for success, others for failure.
112     */
113     virtual Status GetEntry(Entry &entry) const = 0;
114 
115     /**
116      * @brief Close.
117      * @return Return SUCCESS for success, others for failure.
118     */
119     virtual Status Close() = 0;
120 };
121 }  // namespace DistributedKv
122 }  // namespace OHOS
123 #endif  // KVSTORE_RESULT_SET_H
124