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 #ifndef TRACKER_TABLE_H 16 #define TRACKER_TABLE_H 17 #include <set> 18 #include "store_types.h" 19 #include "db_types.h" 20 #include "db_errno.h" 21 #include "json_object.h" 22 #include "sqlite_import.h" 23 24 #ifdef RELATIONAL_STORE 25 namespace DistributedDB { 26 using AfterBuildAction = std::function<int()>; 27 namespace TriggerMode { 28 enum class TriggerModeEnum; 29 } 30 class TrackerTable { 31 public: 32 TrackerTable() = default; ~TrackerTable()33 ~TrackerTable() {}; 34 35 std::string GetTableName() const; 36 const std::set<std::string> &GetTrackerColNames() const; 37 void Init(const TrackerSchema &schema); 38 const std::string GetAssignValSql(bool isDelete = false) const; 39 const std::string GetExtendAssignValSql(bool isDelete = false) const; 40 const std::string GetDiffTrackerValSql() const; 41 const std::string GetDiffIncCursorSql(const std::string &tableName) const; 42 const std::string GetExtendName() const; 43 const std::set<std::string> &GetExtendNames() const; 44 std::string ToString() const; 45 const std::vector<std::string> GetDropTempTriggerSql() const; 46 const std::string GetTempInsertTriggerSql(bool incFlag = false) const; 47 const std::string GetDropTempTriggerSql(TriggerMode::TriggerModeEnum mode) const; 48 const std::string GetCreateTempTriggerSql(TriggerMode::TriggerModeEnum mode) const; 49 const std::string GetTempTriggerName(TriggerMode::TriggerModeEnum mode) const; 50 const std::string GetTempUpdateTriggerSql(bool incFlag = false) const; 51 const std::string GetTempDeleteTriggerSql(bool incFlag = false) const; 52 const std::string GetTempUpdateLogCursorTriggerSql() const; 53 void SetTableName(const std::string &tableName); 54 void SetExtendNames(const std::set<std::string> &colNames); 55 void SetExtendName(const std::string &colName); 56 void SetTrackerNames(const std::set<std::string> &trackerNames); 57 bool IsEmpty() const; 58 bool IsTableNameEmpty() const; 59 bool IsChanging(const TrackerSchema &schema); 60 int ReBuildTempTrigger(sqlite3 *db, TriggerMode::TriggerModeEnum mode, const AfterBuildAction &action); 61 void SetTrackerAction(bool isTrackerAction); 62 void SetTriggerObserver(bool isTriggerObserver); 63 void SetKnowledgeTable(bool isKnowledgeTable); 64 std::string GetOnChangeType() const; 65 private: 66 std::string tableName_; 67 std::string extendColName_; 68 std::set<std::string> extendColNames_; 69 std::set<std::string> trackerColNames_; 70 bool isTrackerAction_ = false; 71 bool isTriggerObserver_ = true; 72 bool isKnowledgeTable_ = false; 73 }; 74 75 } // namespace DistributedDB 76 #endif // RELATIONAL_STORE 77 #endif // TRACKER_TABLE_H