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 #include "grd_base/grd_db_api.h"
16
17 #include "check_common.h"
18 #include "doc_errno.h"
19 #include "document_store_manager.h"
20 #include "grd_api_manager.h"
21 #include "grd_base/grd_error.h"
22 #include "grd_type_inner.h"
23 #include "rd_log_print.h"
24
25 using namespace DocumentDB;
26 static GRD_APIInfo GRD_DBApiInfo;
27
GRD_DBOpen(const char * dbPath,const char * configStr,uint32_t flags,GRD_DB ** db)28 GRD_API int32_t GRD_DBOpen(const char *dbPath, const char *configStr, uint32_t flags, GRD_DB **db)
29 {
30 if (GRD_DBApiInfo.DBOpenApi == nullptr) {
31 InitApiInfo(configStr);
32 GRD_DBApiInfo = GetApiInfoInstance();
33 }
34 if (GRD_DBApiInfo.DBOpenApi == nullptr) {
35 GLOGE("Fail to dlysm RD api symbol");
36 return GRD_INNER_ERR;
37 }
38 return GRD_DBApiInfo.DBOpenApi(dbPath, configStr, flags, db);
39 }
40
GRD_DBClose(GRD_DB * db,uint32_t flags)41 GRD_API int32_t GRD_DBClose(GRD_DB *db, uint32_t flags)
42 {
43 if (GRD_DBApiInfo.DBCloseApi == nullptr) {
44 GRD_DBApiInfo = GetApiInfoInstance();
45 }
46 if (GRD_DBApiInfo.DBCloseApi == nullptr) {
47 GLOGE("Fail to dlysm RD api symbol");
48 return GRD_INNER_ERR;
49 }
50 return GRD_DBApiInfo.DBCloseApi(db, flags);
51 }
52
GRD_DBBackup(GRD_DB * db,const char * backupDbFile,uint8_t * encryptedKey,uint32_t encryptedKeyLen)53 GRD_API int32_t GRD_DBBackup(GRD_DB *db, const char *backupDbFile, uint8_t *encryptedKey, uint32_t encryptedKeyLen)
54 {
55 if (GRD_DBApiInfo.DBBackupApi == nullptr) {
56 GRD_DBApiInfo = GetApiInfoInstance();
57 }
58 if (GRD_DBApiInfo.DBBackupApi == nullptr) {
59 GLOGE("Fail to dlysm RD api symbol");
60 return GRD_INNER_ERR;
61 }
62 return GRD_DBApiInfo.DBBackupApi(db, backupDbFile, encryptedKey, encryptedKeyLen);
63 }
64
GRD_DBRestore(const char * dbFile,const char * backupDbFile,uint8_t * decryptedKey,uint32_t decryptedKeyLen)65 GRD_API int32_t GRD_DBRestore(const char *dbFile, const char *backupDbFile, uint8_t *decryptedKey,
66 uint32_t decryptedKeyLen)
67 {
68 if (GRD_DBApiInfo.DBRestoreApi == nullptr) {
69 GRD_DBApiInfo = GetApiInfoInstance();
70 }
71 if (GRD_DBApiInfo.DBRestoreApi == nullptr) {
72 GLOGE("Fail to dlysm RD api symbol");
73 return GRD_INNER_ERR;
74 }
75 return GRD_DBApiInfo.DBRestoreApi(dbFile, backupDbFile, decryptedKey, decryptedKeyLen);
76 }
77
GRD_Flush(GRD_DB * db,uint32_t flags)78 GRD_API int32_t GRD_Flush(GRD_DB *db, uint32_t flags)
79 {
80 if (GRD_DBApiInfo.FlushApi == nullptr) {
81 GRD_DBApiInfo = GetApiInfoInstance();
82 }
83 if (GRD_DBApiInfo.FlushApi == nullptr) {
84 GLOGE("Fail to dlysm RD api symbol");
85 return GRD_INNER_ERR;
86 }
87 return GRD_DBApiInfo.FlushApi(db, flags);
88 }
89
GRD_IndexPreload(GRD_DB * db,const char * collectionName)90 GRD_API int32_t GRD_IndexPreload(GRD_DB *db, const char *collectionName)
91 {
92 if (GRD_DBApiInfo.IndexPreloadApi == nullptr) {
93 GRD_DBApiInfo = GetApiInfoInstance();
94 }
95 if (GRD_DBApiInfo.IndexPreloadApi == nullptr) {
96 GLOGE("Fail to dlysm RD api symbol");
97 return GRD_INNER_ERR;
98 }
99 return GRD_DBApiInfo.IndexPreloadApi(db, collectionName);
100 }