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 RELATIONAL_DB_SYNC_INTERFACE_H
16 #define RELATIONAL_DB_SYNC_INTERFACE_H
17 #ifdef RELATIONAL_STORE
18 
19 #include "prepared_stmt.h"
20 #include "query_sync_object.h"
21 #include "relationaldb_properties.h"
22 #include "relational_row_data_set.h"
23 #include "relational_schema_object.h"
24 #include "relationaldb_properties.h"
25 #include "single_ver_kv_entry.h"
26 #include "sync_generic_interface.h"
27 #include "schema_negotiate.h"
28 
29 namespace DistributedDB {
30 class RelationalDBSyncInterface : public SyncGenericInterface {
31 public:
~RelationalDBSyncInterface()32     ~RelationalDBSyncInterface() override {};
33 
34     virtual RelationalSchemaObject GetSchemaInfo() const = 0;
35 
36     virtual std::vector<QuerySyncObject> GetTablesQuery() = 0;
37 
38     virtual int LocalDataChanged(int notifyEvent, std::vector<QuerySyncObject> &queryObj) = 0;
39 
40     virtual int CreateDistributedDeviceTable(const std::string &device, const RelationalSyncStrategy &syncStrategy) = 0;
41 
42     virtual int RegisterSchemaChangedCallback(const std::function<void()> &callback) = 0;
43 
44     using ISyncInterface::GetMaxTimestamp;
45     virtual int GetMaxTimestamp(const std::string &tableName, Timestamp &timestamp) const = 0;
46 
47     // return OK, when query finished. token will be set NULL; when query unfinished. token must not be null.
48     // return other errCode, some wrong, token will be set NULL.
49     virtual int ExecuteQuery(const PreparedStmt &prepStmt, size_t packetSize, RelationalRowDataSet &data,
50         ContinueToken &token) const = 0;
51 
52     virtual int SaveRemoteDeviceSchema(const std::string &deviceId, const std::string &remoteSchema, uint8_t type) = 0;
53 
54     virtual int GetSchemaFromDB(RelationalSchemaObject &schema) = 0;
55 
56     virtual int GetRemoteDeviceSchema(const std::string &deviceId, RelationalSchemaObject &schemaObj) = 0;
57 
58     virtual void ReleaseRemoteQueryContinueToken(ContinueToken &token) const = 0;
59 };
60 }
61 #endif // RELATIONAL_STORE
62 #endif