• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 PROFILE_DATABASE_H
17 #define PROFILE_DATABASE_H
18 
19 #include <pthread.h>
20 
21 #include "rdb_errno.h"
22 #include "rdb_helper.h"
23 #include "rdb_open_callback.h"
24 #include "rdb_store.h"
25 #include "result_set.h"
26 
27 namespace OHOS {
28 namespace Contacts {
29 class ProfileDatabase {
30 public:
31     static std::shared_ptr<ProfileDatabase> GetInstance();
32     static std::shared_ptr<OHOS::NativeRdb::RdbStore> store_;
33     int BeginTransaction();
34     int Commit();
35     int RollBack();
36     static void DestroyInstanceAndRestore(std::string restorePath);
37 
38 private:
39     ProfileDatabase();
40     static bool Restore(std::string restorePath);
41     ProfileDatabase(const ProfileDatabase &);
42     const ProfileDatabase &operator=(const ProfileDatabase &);
43     static std::shared_ptr<ProfileDatabase> profileDatabase_;
44 };
45 
46 class SqliteOpenHelperProfileCallback : public OHOS::NativeRdb::RdbOpenCallback {
47 public:
48     int OnCreate(OHOS::NativeRdb::RdbStore &rdbStore) override;
49     int OnUpgrade(OHOS::NativeRdb::RdbStore &rdbStore, int oldVersion, int newVersion) override;
50     int OnDowngrade(OHOS::NativeRdb::RdbStore &rdbStore, int currentVersion, int targetVersion) override;
51 };
52 } // namespace Contacts
53 } // namespace OHOS
54 #endif // PROFILE_DATABASE_H
55