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 HIVIEW_ADAPTER_DBSTORE_INCLUDE_DOC_STORE_H 17 #define HIVIEW_ADAPTER_DBSTORE_INCLUDE_DOC_STORE_H 18 19 #include <functional> 20 #include <memory> 21 #include <mutex> 22 #include <vector> 23 24 #include "data_query.h" 25 #include "types.h" 26 #include "visibility.h" 27 28 namespace OHOS { 29 namespace HiviewDFX { 30 namespace { 31 const char* COLLECTION = "collection"; 32 } 33 class DocDB; 34 class DocStore { 35 public: DocStore()36 DOCSTORE_API DocStore() {} 37 ~DocStore()38 DOCSTORE_API ~DocStore() {} 39 40 DOCSTORE_API int Put(const Entry &entry, const char* coll = COLLECTION); 41 42 DOCSTORE_API int PutBatch(const std::vector<Entry> &entries); 43 44 DOCSTORE_API int Merge(const Entry &entry, const char* coll = COLLECTION); 45 46 DOCSTORE_API int Delete(const DataQuery &query, const char* coll = COLLECTION); 47 48 DOCSTORE_API int GetNum(); 49 50 DOCSTORE_API int GetEntriesWithQuery(const DataQuery &query, std::vector<Entry> &entries, 51 const char* coll = COLLECTION) const; 52 53 DOCSTORE_API int GetEntryDuringQuery(const DataQuery &query, 54 std::function<int (int, const Entry&)> callback, const char* coll = COLLECTION) const; 55 private: 56 friend class StoreManager; 57 std::shared_ptr<DocDB> dbPtr; 58 std::mutex dbStoreMutex; 59 }; // DocStore 60 } // HiviewDFX 61 } // OHOS 62 #endif // HIVIEW_ADAPTER_DBSTORE_INCLUDE_DOC_STORE_H