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_RESULTSET_IMPL_H 17 #define KVSTORE_RESULTSET_IMPL_H 18 19 #include <memory> 20 #include <mutex> 21 #include <shared_mutex> 22 #include "ikvstore_resultset.h" 23 #include "kv_store_result_set.h" 24 #include "kv_store_nb_delegate.h" 25 26 namespace OHOS::DistributedKv { 27 class KvStoreResultSetImpl : public KvStoreResultSetStub { 28 public: 29 explicit KvStoreResultSetImpl(DistributedDB::KvStoreResultSet *resultSet, DistributedDB::Key keyPrefix = {}); 30 ~KvStoreResultSetImpl() override; 31 32 int GetCount() override; 33 34 int GetPosition() override; 35 36 bool MoveToFirst() override; 37 38 bool MoveToLast() override; 39 40 bool MoveToNext() override; 41 42 bool MoveToPrevious() override; 43 44 bool Move(int offset) override; 45 46 bool MoveToPosition(int position) override; 47 48 bool IsFirst() override; 49 50 bool IsLast() override; 51 52 bool IsBeforeFirst() override; 53 54 bool IsAfterLast() override; 55 56 Status GetEntry(Entry &entry) override; 57 58 Status CloseResultSet(DistributedDB::KvStoreNbDelegate *kvStoreNbDelegate); 59 60 Status MigrateKvStore(DistributedDB::KvStoreNbDelegate *kvStoreNbDelegate); 61 private: 62 static constexpr int INIT_POSTION = -1; 63 64 DistributedDB::Key keyPrefix_ {}; 65 mutable std::shared_mutex mutex_ {}; 66 DistributedDB::KvStoreResultSet *kvStoreResultSet_ = nullptr; 67 }; 68 } // namespace OHOS::DistributedKv 69 #endif // KVSTORE_RESULTSET_IMPL_H 70