• 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 CALLLOG_DATABASE_H
17 #define CALLLOG_DATABASE_H
18 
19 #include <pthread.h>
20 
21 #include "datashare_predicates.h"
22 #include "datashare_result_set.h"
23 #include "datashare_values_bucket.h"
24 #include "rdb_errno.h"
25 #include "rdb_helper.h"
26 #include "rdb_open_callback.h"
27 #include "rdb_predicates.h"
28 #include "rdb_store.h"
29 #include "value_object.h"
30 
31 #include "common.h"
32 #include "contacts_columns.h"
33 #include "hilog_wrapper.h"
34 
35 namespace OHOS {
36 namespace Contacts {
37 class CallLogDataBase {
38 public:
39     static std::shared_ptr<CallLogDataBase> GetInstance();
40     static std::shared_ptr<OHOS::NativeRdb::RdbStore> store_;
41     int64_t InsertCallLog(OHOS::NativeRdb::ValuesBucket insertValues);
42     int UpdateCallLog(OHOS::NativeRdb::ValuesBucket values, OHOS::NativeRdb::RdbPredicates &rdbPredicates);
43     int DeleteCallLog(OHOS::NativeRdb::RdbPredicates &rdbPredicates);
44     std::unique_ptr<OHOS::NativeRdb::AbsSharedResultSet> Query(
45         OHOS::NativeRdb::RdbPredicates &rdbPredicates, std::vector<std::string> columns);
46     int BeginTransaction();
47     int Commit();
48     int RollBack();
49     void QueryContactsByInsertCalls(OHOS::NativeRdb::ValuesBucket &insertValues);
50 
51 private:
52     CallLogDataBase();
53     CallLogDataBase(const CallLogDataBase &);
54     const CallLogDataBase &operator=(const CallLogDataBase &);
55     static std::shared_ptr<CallLogDataBase> callLogDataBase_;
56     int UpdateTopContact(OHOS::NativeRdb::ValuesBucket &insertValues);
57 };
58 
59 class SqliteOpenHelperCallLogCallback : public OHOS::NativeRdb::RdbOpenCallback {
60 public:
61     int OnCreate(OHOS::NativeRdb::RdbStore &rdbStore) override;
62     int OnUpgrade(OHOS::NativeRdb::RdbStore &rdbStore, int oldVersion, int newVersion) override;
63     int OnDowngrade(OHOS::NativeRdb::RdbStore &rdbStore, int currentVersion, int targetVersion) override;
64 };
65 } // namespace Contacts
66 } // namespace OHOS
67 
68 #endif // CALLLOG_DATABASE_H
69