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 SQLITE_SINGLE_VER_FORWARD_CURSOR_H 17 #define SQLITE_SINGLE_VER_FORWARD_CURSOR_H 18 19 #include <mutex> 20 21 #include "macro_utils.h" 22 #include "ikvdb_raw_cursor.h" 23 #include "sqlite_single_ver_storage_executor.h" 24 #include "sqlite_single_ver_natural_store.h" 25 26 namespace DistributedDB { 27 class SQLiteSingleVerForwardCursor : public IKvDBRawCursor { 28 public: 29 SQLiteSingleVerForwardCursor(SQLiteSingleVerNaturalStore *kvDB, const Key &keyPrefix); 30 SQLiteSingleVerForwardCursor(SQLiteSingleVerNaturalStore *kvDB, const QueryObject &queryObj); 31 ~SQLiteSingleVerForwardCursor() override; 32 33 // Delete the copy and assign constructors 34 DISABLE_COPY_ASSIGN_MOVE(SQLiteSingleVerForwardCursor); 35 36 // Open the raw cursor. 37 int Open() override; 38 39 // Close the raw cursor before invoking operator delete. 40 void Close() override; 41 42 // Reload all data. 43 int Reload() override; 44 45 // Get total entries count. 46 int GetCount() const override; 47 48 // Get next entry, return errCode if it fails. 49 int GetNext(Entry &entry, bool isCopy) const override; 50 51 private: 52 SQLiteSingleVerNaturalStore *kvDB_; 53 Key keyPrefix_; 54 QueryObject queryObj_; 55 mutable SQLiteSingleVerStorageExecutor *handle_; 56 int count_; 57 mutable bool isOpen_; 58 bool isQueryMode_; 59 mutable std::mutex isOpenMutex_; 60 }; 61 } // namespace DistributedDB 62 63 #endif // SQLITE_SINGLE_VER_FORWARD_CURSOR_H 64