• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 OHOS_ROSEN_WINDOW_SCENE_WMS_RDB_OPEN_CALLBACK_H
17 #define OHOS_ROSEN_WINDOW_SCENE_WMS_RDB_OPEN_CALLBACK_H
18 
19 #include "rdb_errno.h"
20 #include "rdb_open_callback.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 namespace {
25 constexpr static const char* STARTING_WINDOW_RDB_NAME = "/starting_window_config.db";
26 constexpr static const char* STARTING_WINDOW_TABLE_NAME = "starting_window_config";
27 constexpr static int32_t STARTING_WINDOW_RDB_VERSION = 2;
28 } // namespace
29 
30 struct WmsRdbConfig {
31     std::string dbPath;
32     std::string dbName { STARTING_WINDOW_RDB_NAME };
33     std::string tableName { STARTING_WINDOW_TABLE_NAME };
34     std::string createTableSql;
35     int32_t version { STARTING_WINDOW_RDB_VERSION };
36 };
37 
38 class WmsRdbOpenCallback : public NativeRdb::RdbOpenCallback {
39 public:
40     WmsRdbOpenCallback(const WmsRdbConfig& wmsRdbConfig);
41     int32_t OnCreate(NativeRdb::RdbStore& rdbStore) override;
42     int32_t OnUpgrade(NativeRdb::RdbStore& rdbStore, int currentVersion, int targetVersion) override;
43     int32_t OnDowngrade(NativeRdb::RdbStore& rdbStore, int currentVersion, int targetVersion) override;
44     int32_t OnOpen(NativeRdb::RdbStore& rdbStore) override;
45     int32_t onCorruption(std::string databaseFile) override;
46 
47 private:
48     void UpgradeDbToNextVersion(NativeRdb::RdbStore& rdbStore, int newVersion);
49     void AddColumn(NativeRdb::RdbStore& rdbStore, const std::string columnInfo);
50     WmsRdbConfig wmsRdbConfig_;
51 };
52 } // namespace Rosen
53 } // namespace OHOS
54 #endif // OHOS_ROSEN_WINDOW_SCENE_WMS_RDB_OPEN_CALLBACK_H