• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef SQLITE_SINGLE_VER_DATABASE_UPGRADER_H
17 #define SQLITE_SINGLE_VER_DATABASE_UPGRADER_H
18 
19 #include "macro_utils.h"
20 #include "sqlite_utils.h"
21 #include "single_ver_database_upgrader.h"
22 
23 namespace DistributedDB {
24 class SQLiteSingleVerDatabaseUpgrader : virtual public SingleVerDatabaseUpgrader {
25 public:
26     explicit SQLiteSingleVerDatabaseUpgrader(sqlite3 *db, const SecurityOption &secopt, bool isMemDb);
27     ~SQLiteSingleVerDatabaseUpgrader() override;
28     DISABLE_COPY_ASSIGN_MOVE(SQLiteSingleVerDatabaseUpgrader);
29 
30     // used for transferring db file to new dir while classifycation feature in SOFTWARE_VERSION_RELEASE_3_0
31     static int TransferDatabasePath(const std::string &parentDir, const OpenDbProperties &option);
32     static int CreateDbDir();
33 
34     void SetMetaUpgrade(const SecurityOption &currentOpt, const SecurityOption &expectOpt, const std::string &subDir);
35     void SetSubdir(const std::string &subDir);
36     static int SetPathSecOptWithCheck(const std::string &path, const SecurityOption &secOption,
37         const std::string &dbStore, bool isWithChecked = false);
38     static int SetSecOption(const std::string &path, const SecurityOption &secOption, bool isWithChecked);
39 protected:
40     int BeginUpgrade() override;
41     int EndUpgrade(bool isSuccess) override;
42     int GetDatabaseVersion(int &version) const override;
43     int SetDatabaseVersion(int version) override;
44     int UpgradeFromDatabaseVersion(int version) override;
45     void SetUpgradeSqls(int version, std::vector<std::string> &sqls, bool &isCreateUpgradeFile) const;
46     static int MoveDatabaseToNewDir(const std::string &parentDir, const std::string &upgradeLockFile);
47     static int GetDbVersion(const std::string &dbPath, const OpenDbProperties &option, int &version);
48 
49     sqlite3 *db_ = nullptr;
50     SecurityOption secOpt_;
51     bool isMemDB_;
52     bool isMetaUpgrade_;
53     std::string subDir_;
54 };
55 } // namespace DistributedDB
56 #endif // SQLITE_SINGLE_VER_DATABASE_UPGRADER_H
57