• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef ICLOUD_SYNC_STORAGE_INTERFACE_H
17 #define ICLOUD_SYNC_STORAGE_INTERFACE_H
18 
19 #include "cloud/cloud_db_types.h"
20 #include "cloud/iAssetLoader.h"
21 #include "data_transformer.h"
22 #include "query_sync_object.h"
23 #include "sqlite_utils.h"
24 #include "store_observer.h"
25 
26 namespace DistributedDB {
27 
28 enum class OpType : uint8_t {
29     INSERT = 1,
30     UPDATE, // update data, gid and timestamp at same time
31     DELETE,
32     ONLY_UPDATE_GID,
33     // used in Cloud Force Push strategy, when SET_CLOUD_FORCE_PUSH_FLAG_ONE, upload process won't process this record
34     SET_CLOUD_FORCE_PUSH_FLAG_ONE,
35     SET_CLOUD_FORCE_PUSH_FLAG_ZERO,
36     UPDATE_TIMESTAMP,
37     CLEAR_GID,
38     UPDATE_VERSION,
39     SET_UPLOADING,
40     NOT_HANDLE
41 };
42 
43 typedef struct DownloadData {
44     std::vector<VBucket> data;
45     std::vector<OpType> opType;
46     std::vector<int64_t> existDataKey;
47 } DownloadData;
48 
49 class ICloudSyncStorageInterface {
50 public:
51     ICloudSyncStorageInterface() = default;
52     virtual ~ICloudSyncStorageInterface() = default;
53 
54     virtual int GetMetaData(const Key &key, Value &value) const = 0;
55 
56     virtual int PutMetaData(const Key &key, const Value &value) = 0;
57 
58     virtual int ChkSchema(const TableName &tableName) = 0;
59 
60     virtual int SetCloudDbSchema(const DataBaseSchema &schema) = 0;
61 
62     virtual int GetCloudDbSchema(std::shared_ptr<DataBaseSchema> &cloudSchema) = 0;
63 
64     virtual int GetCloudTableSchema(const TableName &tableName, TableSchema &tableSchema) = 0;
65 
66     virtual int StartTransaction(TransactType type) = 0;
67 
68     virtual int Commit() = 0;
69 
70     virtual int Rollback() = 0;
71 
72     virtual int GetUploadCount(const QuerySyncObject &query, const Timestamp &timestamp, bool isCloudForcePush,
73         int64_t &count) = 0;
74 
75     virtual int GetCloudData(const TableSchema &tableSchema, const QuerySyncObject &object, const Timestamp &beginTime,
76         ContinueToken &continueStmtToken, CloudSyncData &cloudDataResult) = 0;
77 
78     virtual int GetCloudDataNext(ContinueToken &continueStmtToken, CloudSyncData &cloudDataResult) = 0;
79 
80     virtual int GetCloudGid(const TableSchema &tableSchema, const QuerySyncObject &querySyncObject,
81         bool isCloudForcePush, std::vector<std::string> &cloudGid) = 0;
82 
83     virtual int ReleaseCloudDataToken(ContinueToken &continueStmtToken) = 0;
84 
85     virtual int GetInfoByPrimaryKeyOrGid(const std::string &tableName, const VBucket &vBucket,
86         DataInfoWithLog &dataInfoWithLog, VBucket &assetInfo) = 0;
87 
88     virtual int PutCloudSyncData(const std::string &tableName, DownloadData &downloadData) = 0;
89 
90     virtual int CleanCloudData(ClearMode mode, const std::vector<std::string> &tableNameList,
91         const RelationalSchemaObject &localSchema, std::vector<Asset> &assets) = 0;
92 
93     virtual void TriggerObserverAction(const std::string &deviceName, ChangedData &&changedData,
94         bool isChangedData) = 0;
95 
96     virtual int FillCloudAssetForDownload(const std::string &tableName, VBucket &asset, bool isDownloadSuccess) = 0;
97 
98     virtual int SetLogTriggerStatus(bool status) = 0;
99 
100     virtual int FillCloudLogAndAsset(OpType opType, const CloudSyncData &data, bool fillAsset, bool ignoreEmptyGid) = 0;
101 
102     virtual std::string GetIdentify() const = 0;
103 
104     virtual int GetCloudDataGid(const QuerySyncObject &query, Timestamp beginTime,
105         std::vector<std::string> &gid) = 0;
106 
107     virtual int CheckQueryValid(const QuerySyncObject &query) = 0;
108 
CreateTempSyncTrigger(const std::string & tableName)109     virtual int CreateTempSyncTrigger(const std::string &tableName)
110     {
111         return E_OK;
112     }
113 
GetAndResetServerObserverData(const std::string & tableName,ChangeProperties & changeProperties)114     virtual int GetAndResetServerObserverData(const std::string &tableName, ChangeProperties &changeProperties)
115     {
116         return E_OK;
117     }
118 
ClearAllTempSyncTrigger()119     virtual int ClearAllTempSyncTrigger()
120     {
121         return E_OK;
122     }
123 
124     virtual bool IsSharedTable(const std::string &tableName) = 0;
125 
SetCloudTaskConfig(const CloudTaskConfig & config)126     virtual void SetCloudTaskConfig([[gnu::unused]] const CloudTaskConfig &config)
127     {
128     }
129 
GetAssetsByGidOrHashKey(const TableSchema & tableSchema,const std::string & gid,const Bytes & hashKey,VBucket & assets)130     virtual int GetAssetsByGidOrHashKey(const TableSchema &tableSchema, const std::string &gid, const Bytes &hashKey,
131         VBucket &assets)
132     {
133         return E_OK;
134     }
135 
SetIAssetLoader(const std::shared_ptr<IAssetLoader> & loader)136     virtual int SetIAssetLoader([[gnu::unused]] const std::shared_ptr<IAssetLoader> &loader)
137     {
138         return E_OK;
139     }
140 
UpdateRecordFlag(const std::string & tableName,const std::string & gid,bool recordConflict)141     virtual int UpdateRecordFlag([[gnu::unused]] const std::string &tableName, [[gnu::unused]] const std::string &gid,
142         [[gnu::unused]] bool recordConflict)
143     {
144         return E_OK;
145     }
146 
GetCompensatedSyncQuery(std::vector<QuerySyncObject> & syncQuery)147     virtual int GetCompensatedSyncQuery([[gnu::unused]] std::vector<QuerySyncObject> &syncQuery)
148     {
149         return E_OK;
150     }
151 };
152 }
153 
154 #endif // ICLOUD_SYNC_STORAGE_INTERFACE_H
155