• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef TIMER_DATABASE_H
17 #define TIMER_DATABASE_H
18 
19 #include "rdb_helper.h"
20 #include "rdb_predicates.h"
21 
22 namespace OHOS {
23 namespace MiscServices {
24 
25 int GetInt(std::shared_ptr<OHOS::NativeRdb::ResultSet> resultSet, int line);
26 int64_t GetLong(std::shared_ptr<OHOS::NativeRdb::ResultSet> resultSet, int line);
27 std::string GetString(std::shared_ptr<OHOS::NativeRdb::ResultSet> resultSet, int line);
28 
29 class TimeDatabase {
30 public:
31     TimeDatabase();
32     static TimeDatabase &GetInstance();
33     bool Insert(const std::string &table, const OHOS::NativeRdb::ValuesBucket &insertValues);
34     bool Update(const OHOS::NativeRdb::ValuesBucket values, const OHOS::NativeRdb::AbsRdbPredicates &predicates);
35     std::shared_ptr<OHOS::NativeRdb::ResultSet> Query(
36         const OHOS::NativeRdb::AbsRdbPredicates &predicates, const std::vector<std::string> &columns);
37     bool Delete(const OHOS::NativeRdb::AbsRdbPredicates &predicates);
38     void ClearDropOnReboot();
39     void ClearInvaildDataInHoldOnReboot();
40 
41 private:
42     bool RecoverDataBase();
43     std::shared_ptr<OHOS::NativeRdb::RdbStore> store_;
44 };
45 
46 class TimeDBOpenCallback : public OHOS::NativeRdb::RdbOpenCallback {
47 public:
48     int OnCreate(OHOS::NativeRdb::RdbStore &rdbStore) override;
49     int OnOpen(OHOS::NativeRdb::RdbStore &rdbStore) override;
50     int OnUpgrade(OHOS::NativeRdb::RdbStore &rdbStore, int oldVersion, int newVersion) override;
51     int OnDowngrade(OHOS::NativeRdb::RdbStore &rdbStore, int currentVersion, int targetVersion) override;
52 };
53 } // namespace MiscServices
54 } // namespace OHOS
55 #endif // TIMER_DATABASE_H
56