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 SQLITE_RELATIONAL_ENGINE_H 16 #define SQLITE_RELATIONAL_ENGINE_H 17 #ifdef RELATIONAL_STORE 18 19 #include "macro_utils.h" 20 #include "sqlite_storage_engine.h" 21 #include "sqlite_single_ver_relational_storage_executor.h" 22 23 namespace DistributedDB { 24 class SQLiteSingleRelationalStorageEngine : public SQLiteStorageEngine { 25 public: 26 SQLiteSingleRelationalStorageEngine(); 27 ~SQLiteSingleRelationalStorageEngine() override; 28 29 // Delete the copy and assign constructors 30 DISABLE_COPY_ASSIGN_MOVE(SQLiteSingleRelationalStorageEngine); 31 32 void SetSchema(const RelationalSchemaObject &schema); 33 34 const RelationalSchemaObject &GetSchemaRef() const; 35 36 int CreateDistributedTable(const std::string &tableName, bool &schemaChanged); 37 38 int CleanDistributedDeviceTable(std::vector<std::string> &missingTables); 39 40 protected: 41 StorageExecutor *NewSQLiteStorageExecutor(sqlite3 *db, bool isWrite, bool isMemDb) override; 42 int Upgrade(sqlite3 *db) override; 43 int CreateNewExecutor(bool isWrite, StorageExecutor *&handle) override; 44 45 private: 46 // For executor. 47 int ReleaseExecutor(SQLiteSingleVerRelationalStorageExecutor *&handle); 48 49 // For db. 50 int RegisterFunction(sqlite3 *db) const; 51 52 int UpgradeDistributedTable(const std::string &tableName); 53 54 RelationalSchemaObject schema_; 55 mutable std::mutex schemaMutex_; 56 }; 57 } // namespace DistributedDB 58 #endif 59 #endif // SQLITE_RELATIONAL_ENGINE_H