• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     RATE_LIMIT,
69     DATA_HANDLE_ERROR, // remote handle data failed
70     CONSTRAINT, // constraint check failed in sqlite
71 };
72 
73 struct KvStoreConfig {
74     std::string dataDir;
75 };
76 
77 enum PragmaCmd {
78     AUTO_SYNC = 1,
79     SYNC_DEVICES = 2, // this cmd will be removed in the future, don't use it
80     RM_DEVICE_DATA = 3, // this cmd will be removed in the future, don't use it
81     PERFORMANCE_ANALYSIS_GET_REPORT,
82     PERFORMANCE_ANALYSIS_OPEN,
83     PERFORMANCE_ANALYSIS_CLOSE,
84     PERFORMANCE_ANALYSIS_SET_REPORTFILENAME,
85     GET_IDENTIFIER_OF_DEVICE,
86     GET_DEVICE_IDENTIFIER_OF_ENTRY,
87     GET_QUEUED_SYNC_SIZE,
88     SET_QUEUED_SYNC_LIMIT,
89     GET_QUEUED_SYNC_LIMIT,
90     SET_WIPE_POLICY,  // set the policy of wipe remote stale data
91     RESULT_SET_CACHE_MODE, // Accept ResultSetCacheMode Type As PragmaData
92     RESULT_SET_CACHE_MAX_SIZE, // Allowed Int Type Range [1,16], Unit MB
93     SET_SYNC_RETRY,
94     SET_MAX_LOG_LIMIT,
95     EXEC_CHECKPOINT,
96 };
97 
98 enum ResolutionPolicyType {
99     AUTO_LAST_WIN = 0,      // resolve conflicts by timestamp(default value)
100     CUSTOMER_RESOLUTION = 1 // resolve conflicts by user
101 };
102 
103 enum ObserverMode {
104     OBSERVER_CHANGES_NATIVE = 1,
105     OBSERVER_CHANGES_FOREIGN = 2,
106     OBSERVER_CHANGES_LOCAL_ONLY = 4,
107 };
108 
109 enum SyncMode {
110     SYNC_MODE_PUSH_ONLY,
111     SYNC_MODE_PULL_ONLY,
112     SYNC_MODE_PUSH_PULL,
113 };
114 
115 enum ConflictResolvePolicy {
116     LAST_WIN = 0,
117     DEVICE_COLLABORATION,
118 };
119 
120 struct TableStatus {
121     std::string tableName;
122     DBStatus status;
123 };
124 using KvStoreCorruptionHandler = std::function<void (const std::string &appId, const std::string &userId,
125     const std::string &storeId)>;
126 using StoreCorruptionHandler = std::function<void (const std::string &appId, const std::string &userId,
127     const std::string &storeId)>;
128 using SyncStatusCallback = std::function<void(const std::map<std::string, std::vector<TableStatus>> &devicesMap)>;
129 
130 struct RemoteCondition {
131     std::string sql;  // The sql statement;
132     std::vector<std::string> bindArgs;  // The bind args.
133 };
134 
135 using UpdateKeyCallback = std::function<void (const Key &originKey, Key &newKey)>;
136 } // namespace DistributedDB
137 #endif // KV_STORE_TYPE_H
138