1cf69771bSopenharmony_ci/*
2cf69771bSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3cf69771bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4cf69771bSopenharmony_ci * you may not use this file except in compliance with the License.
5cf69771bSopenharmony_ci * You may obtain a copy of the License at
6cf69771bSopenharmony_ci *
7cf69771bSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8cf69771bSopenharmony_ci *
9cf69771bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10cf69771bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11cf69771bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12cf69771bSopenharmony_ci * See the License for the specific language governing permissions and
13cf69771bSopenharmony_ci * limitations under the License.
14cf69771bSopenharmony_ci */
15cf69771bSopenharmony_ci
16cf69771bSopenharmony_ci#ifndef TIMER_DATABASE_H
17cf69771bSopenharmony_ci#define TIMER_DATABASE_H
18cf69771bSopenharmony_ci
19cf69771bSopenharmony_ci#include "rdb_helper.h"
20cf69771bSopenharmony_ci#include "rdb_predicates.h"
21cf69771bSopenharmony_ci#include "rdb_store.h"
22cf69771bSopenharmony_ci
23cf69771bSopenharmony_cinamespace OHOS {
24cf69771bSopenharmony_cinamespace MiscServices {
25cf69771bSopenharmony_ciconstexpr const char *DB_NAME = "/data/service/el1/public/database/time/time.db";
26cf69771bSopenharmony_ciconstexpr int DATABASE_OPEN_VERSION = 1;
27cf69771bSopenharmony_ciconstexpr int DATABASE_OPEN_VERSION_2 = 2;
28cf69771bSopenharmony_ciconstexpr int CHECK_VERSION_FAILED = -1;
29cf69771bSopenharmony_ciconstexpr int API12_5_0_RELEASE = 50;
30cf69771bSopenharmony_ciconstexpr int INVALID_VERSION = -50;
31cf69771bSopenharmony_ciconstexpr int64_t MILLISECOND_TO_NANO = 1000000;
32cf69771bSopenharmony_ciconstexpr int CLOCK_POWEROFF_ALARM = 12;
33cf69771bSopenharmony_ciconstexpr const char *HOLD_ON_REBOOT = "hold_on_reboot";
34cf69771bSopenharmony_ciconstexpr const char *DROP_ON_REBOOT = "drop_on_reboot";
35cf69771bSopenharmony_ci
36cf69771bSopenharmony_ciint GetInt(std::shared_ptr<OHOS::NativeRdb::ResultSet> resultSet, int line);
37cf69771bSopenharmony_ciint64_t GetLong(std::shared_ptr<OHOS::NativeRdb::ResultSet> resultSet, int line);
38cf69771bSopenharmony_cistd::string GetString(std::shared_ptr<OHOS::NativeRdb::ResultSet> resultSet, int line);
39cf69771bSopenharmony_ci
40cf69771bSopenharmony_ciclass TimeDatabase {
41cf69771bSopenharmony_cipublic:
42cf69771bSopenharmony_ci    TimeDatabase();
43cf69771bSopenharmony_ci    static TimeDatabase &GetInstance();
44cf69771bSopenharmony_ci    bool Insert(const std::string &table, const OHOS::NativeRdb::ValuesBucket &insertValues);
45cf69771bSopenharmony_ci    bool Update(const OHOS::NativeRdb::ValuesBucket values, const OHOS::NativeRdb::AbsRdbPredicates &predicates);
46cf69771bSopenharmony_ci    std::shared_ptr<OHOS::NativeRdb::ResultSet> Query(
47cf69771bSopenharmony_ci        const OHOS::NativeRdb::AbsRdbPredicates &predicates, const std::vector<std::string> &columns);
48cf69771bSopenharmony_ci    bool Delete(const OHOS::NativeRdb::AbsRdbPredicates &predicates);
49cf69771bSopenharmony_ci    void ClearDropOnReboot();
50cf69771bSopenharmony_ci
51cf69771bSopenharmony_ciprivate:
52cf69771bSopenharmony_ci    bool RecoverDataBase();
53cf69771bSopenharmony_ci    std::shared_ptr<OHOS::NativeRdb::RdbStore> store_;
54cf69771bSopenharmony_ci};
55cf69771bSopenharmony_ci
56cf69771bSopenharmony_ciclass TimeDBOpenCallback : public OHOS::NativeRdb::RdbOpenCallback {
57cf69771bSopenharmony_cipublic:
58cf69771bSopenharmony_ci    int OnCreate(OHOS::NativeRdb::RdbStore &rdbStore) override;
59cf69771bSopenharmony_ci    int OnOpen(OHOS::NativeRdb::RdbStore &rdbStore) override;
60cf69771bSopenharmony_ci    int OnUpgrade(OHOS::NativeRdb::RdbStore &rdbStore, int oldVersion, int newVersion) override;
61cf69771bSopenharmony_ci    int OnDowngrade(OHOS::NativeRdb::RdbStore &rdbStore, int currentVersion, int targetVersion) override;
62cf69771bSopenharmony_ci};
63cf69771bSopenharmony_ci} // namespace MiscServices
64cf69771bSopenharmony_ci} // namespace OHOS
65cf69771bSopenharmony_ci#endif // TIMER_DATABASE_H