1 /*
2 * Copyright (c) 2023 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 #include "grd_document/grd_document_api.h"
17
18 #include "check_common.h"
19 #include "grd_api_manager.h"
20 #include "grd_base/grd_error.h"
21 #include "grd_resultset_inner.h"
22 #include "grd_type_inner.h"
23 #include "rd_log_print.h"
24 using namespace DocumentDB;
25
26 static GRD_APIInfo GRD_DocApiInfo;
27
GRD_CreateCollection(GRD_DB * db,const char * collectionName,const char * optionStr,uint32_t flags)28 GRD_API int32_t GRD_CreateCollection(GRD_DB *db, const char *collectionName, const char *optionStr, uint32_t flags)
29 {
30 if (GRD_DocApiInfo.CreateCollectionApi == nullptr) {
31 GRD_DocApiInfo = GetApiInfoInstance();
32 }
33 if (GRD_DocApiInfo.CreateCollectionApi == nullptr) {
34 GLOGE("Fail to dlysm RD api symbol");
35 return GRD_INNER_ERR;
36 }
37 return GRD_DocApiInfo.CreateCollectionApi(db, collectionName, optionStr, flags);
38 }
39
GRD_DropCollection(GRD_DB * db,const char * collectionName,uint32_t flags)40 GRD_API int32_t GRD_DropCollection(GRD_DB *db, const char *collectionName, uint32_t flags)
41 {
42 if (GRD_DocApiInfo.DropCollectionApi == nullptr) {
43 GRD_DocApiInfo = GetApiInfoInstance();
44 }
45 if (GRD_DocApiInfo.DropCollectionApi == nullptr) {
46 GLOGE("Fail to dlysm RD api symbol");
47 return GRD_INNER_ERR;
48 }
49 return GRD_DocApiInfo.DropCollectionApi(db, collectionName, flags);
50 }
51
GRD_UpdateDoc(GRD_DB * db,const char * collectionName,const char * filter,const char * update,uint32_t flags)52 GRD_API int32_t GRD_UpdateDoc(GRD_DB *db, const char *collectionName, const char *filter, const char *update,
53 uint32_t flags)
54 {
55 if (GRD_DocApiInfo.UpdateDocApi == nullptr) {
56 GRD_DocApiInfo = GetApiInfoInstance();
57 }
58 if (GRD_DocApiInfo.UpdateDocApi == nullptr) {
59 GLOGE("Fail to dlysm RD api symbol");
60 return GRD_INNER_ERR;
61 }
62 return GRD_DocApiInfo.UpdateDocApi(db, collectionName, filter, update, flags);
63 }
64
GRD_UpsertDoc(GRD_DB * db,const char * collectionName,const char * filter,const char * document,uint32_t flags)65 GRD_API int32_t GRD_UpsertDoc(GRD_DB *db, const char *collectionName, const char *filter, const char *document,
66 uint32_t flags)
67 {
68 if (GRD_DocApiInfo.UpsertDocApi == nullptr) {
69 GRD_DocApiInfo = GetApiInfoInstance();
70 }
71 if (GRD_DocApiInfo.UpsertDocApi == nullptr) {
72 GLOGE("Fail to dlysm RD api symbol");
73 return GRD_INNER_ERR;
74 }
75 return GRD_DocApiInfo.UpsertDocApi(db, collectionName, filter, document, flags);
76 }
77
GRD_InsertDoc(GRD_DB * db,const char * collectionName,const char * document,uint32_t flags)78 GRD_API int32_t GRD_InsertDoc(GRD_DB *db, const char *collectionName, const char *document, uint32_t flags)
79 {
80 if (GRD_DocApiInfo.InsertDocApi == nullptr) {
81 GRD_DocApiInfo = GetApiInfoInstance();
82 }
83 if (GRD_DocApiInfo.InsertDocApi == nullptr) {
84 GLOGE("Fail to dlysm RD api symbol");
85 return GRD_INNER_ERR;
86 }
87 return GRD_DocApiInfo.InsertDocApi(db, collectionName, document, flags);
88 }
89
GRD_DeleteDoc(GRD_DB * db,const char * collectionName,const char * filter,uint32_t flags)90 GRD_API int32_t GRD_DeleteDoc(GRD_DB *db, const char *collectionName, const char *filter, uint32_t flags)
91 {
92 if (GRD_DocApiInfo.DeleteDocApi == nullptr) {
93 GRD_DocApiInfo = GetApiInfoInstance();
94 }
95 if (GRD_DocApiInfo.DeleteDocApi == nullptr) {
96 GLOGE("Fail to dlysm RD api symbol");
97 return GRD_INNER_ERR;
98 }
99 return GRD_DocApiInfo.DeleteDocApi(db, collectionName, filter, flags);
100 }
101
GRD_FindDoc(GRD_DB * db,const char * collectionName,Query query,uint32_t flags,GRD_ResultSet ** resultSet)102 GRD_API int32_t GRD_FindDoc(GRD_DB *db, const char *collectionName, Query query, uint32_t flags,
103 GRD_ResultSet **resultSet)
104 {
105 if (GRD_DocApiInfo.FindDocApi == nullptr) {
106 GRD_DocApiInfo = GetApiInfoInstance();
107 }
108 if (GRD_DocApiInfo.FindDocApi == nullptr) {
109 GLOGE("Fail to dlysm RD api symbol");
110 return GRD_INNER_ERR;
111 }
112 return GRD_DocApiInfo.FindDocApi(db, collectionName, query, flags, resultSet);
113 }
114