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 #ifndef SYNC_GENERIC_INTERFACE_H
16 #define SYNC_GENERIC_INTERFACE_H
17 
18 #include "isync_interface.h"
19 #include "single_ver_kv_entry.h"
20 #include "store_types.h"
21 #include "query_object.h"
22 
23 namespace DistributedDB {
24 class SyncGenericInterface : public ISyncInterface {
25 public:
26     // Constructor/Destructor.
27     SyncGenericInterface() = default;
28     ~SyncGenericInterface() override = default;
29 
GetSyncData(Timestamp begin,Timestamp end,std::vector<DataItem> & dataItems,ContinueToken & continueStmtToken,const DataSizeSpecInfo & dataSizeInfo)30     virtual int GetSyncData(Timestamp begin, Timestamp end, std::vector<DataItem> &dataItems,
31         ContinueToken &continueStmtToken, const DataSizeSpecInfo &dataSizeInfo) const
32     {
33         LOGE("GetSyncData not support!");
34         return -E_NOT_SUPPORT;
35     }
36 
37     // Get the data which would be synced to other devices according the timestamp.
38     // if the data size is over than the blockSize, It would alloc one token and assign to continueStmtToken,
39     // it should be released when the read operation terminate.
GetSyncData(Timestamp begin,Timestamp end,std::vector<SingleVerKvEntry * > & entries,ContinueToken & continueStmtToken,const DataSizeSpecInfo & dataSizeInfo)40     virtual int GetSyncData(Timestamp begin, Timestamp end, std::vector<SingleVerKvEntry *> &entries,
41         ContinueToken &continueStmtToken, const DataSizeSpecInfo &dataSizeInfo) const
42     {
43         LOGE("GetSyncData not support!");
44         return -E_NOT_SUPPORT;
45     }
46 
47     // Get the data which would be synced with query condition
GetSyncData(QueryObject & query,const SyncTimeRange & timeRange,const DataSizeSpecInfo & dataSizeInfo,ContinueToken & continueStmtToken,std::vector<SingleVerKvEntry * > & entries)48     virtual int GetSyncData(QueryObject &query, const SyncTimeRange &timeRange,
49         const DataSizeSpecInfo &dataSizeInfo, ContinueToken &continueStmtToken,
50         std::vector<SingleVerKvEntry *> &entries) const
51     {
52         return -E_NOT_SUPPORT;
53     }
54 
GetSyncDataNext(std::vector<DataItem> & dataItems,ContinueToken & continueStmtToken,const DataSizeSpecInfo & dataSizeInfo)55     virtual int GetSyncDataNext(std::vector<DataItem> &dataItems, ContinueToken &continueStmtToken,
56         const DataSizeSpecInfo &dataSizeInfo) const
57     {
58         return -E_NOT_SUPPORT;
59     }
60 
GetSyncDataNext(std::vector<SingleVerKvEntry * > & entries,ContinueToken & continueStmtToken,const DataSizeSpecInfo & dataSizeInfo)61     virtual int GetSyncDataNext(std::vector<SingleVerKvEntry *> &entries, ContinueToken &continueStmtToken,
62         const DataSizeSpecInfo &dataSizeInfo) const
63     {
64         return -E_NOT_SUPPORT;
65     }
66 
GetCompressionOption(bool & needCompressOnSync,uint8_t & compressionRate)67     virtual int GetCompressionOption(bool &needCompressOnSync, uint8_t &compressionRate) const
68     {
69         return -E_NOT_SUPPORT;
70     }
71 
72     // Release the continue token of getting data.
ReleaseContinueToken(ContinueToken & continueStmtToken)73     virtual void ReleaseContinueToken(ContinueToken &continueStmtToken) const
74     {
75     }
76 
RemoveDeviceData(const std::string & deviceName,bool isNeedNotify)77     virtual int RemoveDeviceData(const std::string &deviceName, bool isNeedNotify)
78     {
79         return -E_NOT_SUPPORT;
80     }
81 
IsReadable()82     virtual bool IsReadable() const
83     {
84         return true;
85     }
86 
GetSecurityOption(SecurityOption & option)87     int GetSecurityOption(SecurityOption &option) const override
88     {
89         return -E_NOT_SUPPORT;
90     }
91 
NotifyRemotePushFinished(const std::string & targetId)92     virtual void NotifyRemotePushFinished(const std::string &targetId) const
93     {
94     }
95 
96     // Get the timestamp when database created or imported
GetDatabaseCreateTimestamp(Timestamp & outTime)97     virtual int GetDatabaseCreateTimestamp(Timestamp &outTime) const
98     {
99         return -E_NOT_SUPPORT;
100     }
101 
PutSyncDataWithQuery(const QueryObject & query,const std::vector<SingleVerKvEntry * > & entries,const std::string & deviceName)102     virtual int PutSyncDataWithQuery(const QueryObject &query, const std::vector<SingleVerKvEntry *> &entries,
103         const std::string &deviceName)
104     {
105         return -E_NOT_SUPPORT;
106     }
107 
CheckAndInitQueryCondition(QueryObject & query)108     virtual int CheckAndInitQueryCondition(QueryObject &query) const
109     {
110         return -E_NOT_SUPPORT;
111     }
112 
InterceptData(std::vector<SingleVerKvEntry * > & entries,const std::string & sourceID,const std::string & targetID,bool isPush)113     virtual int InterceptData(std::vector<SingleVerKvEntry *> &entries, const std::string &sourceID,
114         const std::string &targetID, bool isPush) const
115     {
116         return -E_NOT_SUPPORT;
117     }
118 
AddSubscribe(const std::string & subscribeId,const QueryObject & query,bool needCacheSubscribe)119     virtual int AddSubscribe(const std::string &subscribeId, const QueryObject &query, bool needCacheSubscribe)
120     {
121         return -E_NOT_SUPPORT;
122     }
123 
RemoveSubscribe(const std::string & subscribeId)124     virtual int RemoveSubscribe(const std::string &subscribeId)
125     {
126         return -E_NOT_SUPPORT;
127     }
128 
RemoveSubscribe(const std::vector<std::string> & subscribeIds)129     virtual int RemoveSubscribe(const std::vector<std::string> &subscribeIds)
130     {
131         return -E_NOT_SUPPORT;
132     }
133 
GetCompressionAlgo(std::set<CompressAlgorithm> & algorithmSet)134     virtual int GetCompressionAlgo(std::set<CompressAlgorithm> &algorithmSet) const
135     {
136         return -E_NOT_SUPPORT;
137     }
138 
CheckCompatible(const std::string & schema,uint8_t type)139     virtual bool CheckCompatible(const std::string &schema, uint8_t type) const
140     {
141         return false;
142     }
143 
GetDualTupleIdentifier()144     std::vector<uint8_t> GetDualTupleIdentifier() const override
145     {
146         return {};
147     }
148 
GetDBInfo(DBInfo & dbInfo)149     virtual void GetDBInfo(DBInfo &dbInfo) const
150     {
151         dbInfo.appId = GetDbProperties().GetStringProp(DBProperties::APP_ID, "");
152         dbInfo.userId = GetDbProperties().GetStringProp(DBProperties::USER_ID, "");
153         dbInfo.storeId = GetDbProperties().GetStringProp(DBProperties::STORE_ID, "");
154     }
155 
IsSupportSubscribe()156     int IsSupportSubscribe() const override
157     {
158         return -E_NOT_SUPPORT;
159     }
160 
TryHandle()161     virtual int TryHandle() const
162     {
163         return E_OK;
164     }
165 };
166 }
167 #endif // SYNC_GENERIC_INTERFACE_H
168