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 KV_STORE_TYPE_H 17 #define KV_STORE_TYPE_H 18 19 #include <functional> 20 #include <map> 21 #include <string> 22 23 #include "types_export.h" 24 25 namespace DistributedDB { 26 enum DBStatus { 27 DB_ERROR = -1, 28 OK = 0, 29 BUSY, 30 NOT_FOUND, 31 INVALID_ARGS, 32 TIME_OUT, 33 NOT_SUPPORT, 34 INVALID_PASSWD_OR_CORRUPTED_DB, 35 OVER_MAX_LIMITS, 36 INVALID_FILE, 37 NO_PERMISSION, 38 FILE_ALREADY_EXISTED, 39 SCHEMA_MISMATCH, 40 INVALID_SCHEMA, 41 READ_ONLY, 42 INVALID_VALUE_FIELDS, // invalid put value for json schema. 43 INVALID_FIELD_TYPE, // invalid put value field type for json schema. 44 CONSTRAIN_VIOLATION, // invalid put value constrain for json schema. 45 INVALID_FORMAT, // invalid put value format for json schema. 46 STALE, // new record is staler compared to the same key existed in db. 47 LOCAL_DELETED, // local data is deleted by the unpublish. 48 LOCAL_DEFEAT, // local data defeat the sync data while unpublish. 49 LOCAL_COVERED, // local data is covered by the sync data while unpublish. 50 INVALID_QUERY_FORMAT, 51 INVALID_QUERY_FIELD, 52 PERMISSION_CHECK_FORBID_SYNC, // permission check result , forbid sync. 53 ALREADY_SET, // already set. 54 COMM_FAILURE, // communicator may get some error. 55 EKEYREVOKED_ERROR, // EKEYREVOKED error when operating db file 56 SECURITY_OPTION_CHECK_ERROR, // such as remote device's SecurityOption not equal to local 57 SCHEMA_VIOLATE_VALUE, // Values already exist in dbFile do not match new schema 58 INTERCEPT_DATA_FAIL, // Interceptor push data failed. 59 LOG_OVER_LIMITS, // Log size is over the limits. 60 DISTRIBUTED_SCHEMA_NOT_FOUND, // the sync table is not a relational table 61 DISTRIBUTED_SCHEMA_CHANGED, // the schema was changed 62 MODE_MISMATCH, 63 NOT_ACTIVE, 64 USER_CHANGED, 65 NONEXISTENT, // for row record, pass invalid column name or invalid column index. 66 TYPE_MISMATCH, // for row record, get value with mismatch func. 67 REMOTE_OVER_SIZE, // for remote query, the data is too many, only get part or data. 68 }; 69 70 struct KvStoreConfig { 71 std::string dataDir; 72 }; 73 74 enum PragmaCmd { 75 AUTO_SYNC = 1, 76 SYNC_DEVICES = 2, // this cmd will be removed in the future, don't use it 77 RM_DEVICE_DATA = 3, // this cmd will be removed in the future, don't use it 78 PERFORMANCE_ANALYSIS_GET_REPORT, 79 PERFORMANCE_ANALYSIS_OPEN, 80 PERFORMANCE_ANALYSIS_CLOSE, 81 PERFORMANCE_ANALYSIS_SET_REPORTFILENAME, 82 GET_IDENTIFIER_OF_DEVICE, 83 GET_DEVICE_IDENTIFIER_OF_ENTRY, 84 GET_QUEUED_SYNC_SIZE, 85 SET_QUEUED_SYNC_LIMIT, 86 GET_QUEUED_SYNC_LIMIT, 87 SET_WIPE_POLICY, // set the policy of wipe remote stale data 88 RESULT_SET_CACHE_MODE, // Accept ResultSetCacheMode Type As PragmaData 89 RESULT_SET_CACHE_MAX_SIZE, // Allowed Int Type Range [1,16], Unit MB 90 SET_SYNC_RETRY, 91 SET_MAX_LOG_LIMIT, 92 EXEC_CHECKPOINT, 93 }; 94 95 enum ResolutionPolicyType { 96 AUTO_LAST_WIN = 0, // resolve conflicts by timestamp(default value) 97 CUSTOMER_RESOLUTION = 1 // resolve conflicts by user 98 }; 99 100 enum ObserverMode { 101 OBSERVER_CHANGES_NATIVE = 1, 102 OBSERVER_CHANGES_FOREIGN = 2, 103 OBSERVER_CHANGES_LOCAL_ONLY = 4, 104 }; 105 106 enum SyncMode { 107 SYNC_MODE_PUSH_ONLY, 108 SYNC_MODE_PULL_ONLY, 109 SYNC_MODE_PUSH_PULL, 110 }; 111 112 enum ConflictResolvePolicy { 113 LAST_WIN = 0, 114 DEVICE_COLLABORATION, 115 }; 116 117 struct TableStatus { 118 std::string tableName; 119 DBStatus status; 120 }; 121 using KvStoreCorruptionHandler = std::function<void (const std::string &appId, const std::string &userId, 122 const std::string &storeId)>; 123 using StoreCorruptionHandler = std::function<void (const std::string &appId, const std::string &userId, 124 const std::string &storeId)>; 125 using SyncStatusCallback = std::function<void(const std::map<std::string, std::vector<TableStatus>> &devicesMap)>; 126 127 struct RemoteCondition { 128 std::string sql; // The sql statement; 129 std::vector<std::string> bindArgs; // The bind args. 130 }; 131 } // namespace DistributedDB 132 #endif // KV_STORE_TYPE_H 133