• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 SQLITE_LOG_TABLE_MANAGER_H
16 #define SQLITE_LOG_TABLE_MANAGER_H
17 #include <mutex>
18 
19 #include "relational_schema_object.h"
20 #include "sqlite_utils.h"
21 
22 namespace DistributedDB {
23 class SqliteLogTableManager {
24 public:
25     SqliteLogTableManager() = default;
26     virtual ~SqliteLogTableManager() = default;
27 
28     virtual std::string CalcPrimaryKeyHash(const std::string &references, const TableInfo &table,
29         const std::string &identity) = 0;
30 
31     // The parameter "identity" is a hash string that identifies a device
32     int AddRelationalLogTableTrigger(sqlite3 *db, const TableInfo &table, const std::string &identity);
33 
34     int CreateRelationalLogTable(sqlite3 *db, const TableInfo &table);
35 
36 protected:
37     virtual void GetIndexSql(const TableInfo &table, std::vector<std::string> &schema);
38     std::string GetLogTableName(const TableInfo &table) const;
39 
40 private:
41     virtual std::string GetInsertTrigger(const TableInfo &table, const std::string &identity) = 0;
42     virtual std::string GetUpdateTrigger(const TableInfo &table, const std::string &identity) = 0;
43     virtual std::string GetDeleteTrigger(const TableInfo &table, const std::string &identity) = 0;
44 
45     virtual std::string GetPrimaryKeySql(const TableInfo &table) = 0;
46 };
47 }
48 #endif // SQLITE_LOG_TABLE_MANAGER_H