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 #define MLOG_TAG "Media_Upgrade"
16
17 #include "table_event_handler.h"
18
19 #include <string>
20 #include <vector>
21
22 #include "media_log.h"
23 #include "media_file_utils.h"
24 #include "photo_map_table_event_handler.h"
25
26 namespace OHOS::Media {
TableEventHandler()27 TableEventHandler::TableEventHandler()
28 {
29 this->handlers_ = {
30 std::make_shared<PhotoMapTableEventHandler>(),
31 };
32 }
33
OnCreate(std::shared_ptr<MediaLibraryRdbStore> store)34 int32_t TableEventHandler::OnCreate(std::shared_ptr<MediaLibraryRdbStore> store)
35 {
36 int32_t ret = E_OK;
37 int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
38 for (auto handler : this->handlers_) {
39 CHECK_AND_CONTINUE_ERR_LOG(handler != nullptr, "handler is null");
40 ret = handler->OnCreate(store);
41 CHECK_AND_PRINT_LOG(ret == 0, "handler OnCreate failed");
42 }
43 int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
44 int64_t costTime = endTime - startTime;
45 MEDIA_INFO_LOG("OnCreate, cost %{public}" PRId64 "ms.", costTime);
46 return E_OK;
47 }
48
OnUpgrade(std::shared_ptr<MediaLibraryRdbStore> store,int32_t oldVersion,int32_t newVersion)49 int32_t TableEventHandler::OnUpgrade(
50 std::shared_ptr<MediaLibraryRdbStore> store, int32_t oldVersion, int32_t newVersion)
51 {
52 int32_t ret = E_OK;
53 int64_t startTime = MediaFileUtils::UTCTimeMilliSeconds();
54 for (auto handler : this->handlers_) {
55 CHECK_AND_CONTINUE_ERR_LOG(handler != nullptr, "handler is null");
56 ret = handler->OnUpgrade(store, oldVersion, newVersion);
57 CHECK_AND_PRINT_LOG(ret == 0, "handler OnUpgrade failed");
58 }
59 int64_t endTime = MediaFileUtils::UTCTimeMilliSeconds();
60 int64_t costTime = endTime - startTime;
61 MEDIA_INFO_LOG("OnUpgrade, cost %{public}" PRId64 "ms.", costTime);
62 return E_OK;
63 }
64 } // namespace OHOS::Media