• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef OHOS_MEDIA_PHOTO_MAP_TABLE_EVENT_HANDLER_H
17 #define OHOS_MEDIA_PHOTO_MAP_TABLE_EVENT_HANDLER_H
18 
19 #include <string>
20 
21 #include "rdb_store.h"
22 #include "i_media_rdb_open_event.h"
23 #include "database_utils.h"
24 #include "photo_map_column.h"
25 
26 namespace OHOS::Media {
27 static const std::string SQL_DROP_NEW_TRIGGER = "DROP TRIGGER IF EXISTS album_map_insert_cloud_sync_trigger;";
28 static const std::string SQL_DROP_DELETE_TRIGGER = "DROP TRIGGER IF EXISTS album_map_delete_trigger;";
29 static const std::string SQL_DROP_INSERT_SEARCH_TRIGGER = "DROP TRIGGER IF EXISTS album_map_insert_search_trigger;";
30 static const std::string SQL_DROP_DELETE_SEARCH_TRIGGER = "DROP TRIGGER IF EXISTS album_map_delete_search_trigger;";
31 
32 class PhotoMapTableEventHandler : public IMediaRdbOpenEvent {
33 public:
34     virtual ~PhotoMapTableEventHandler() = default;
35 
36 public:
37     int32_t OnCreate(std::shared_ptr<MediaLibraryRdbStore> store) override;
38     int32_t OnUpgrade(std::shared_ptr<MediaLibraryRdbStore> store, int32_t oldVersion, int32_t newVersion) override;
39 
40 private:
41     using UpgradeHandle = int32_t (PhotoMapTableEventHandler::*)(
42         std::shared_ptr<MediaLibraryRdbStore>, int32_t, int32_t);
43     int32_t DropAllTriggers(std::shared_ptr<MediaLibraryRdbStore> store, int32_t oldVersion, int32_t newVersion);
44 
45 private:
46     const std::vector<UpgradeHandle> upgradeHandles_ = {
47         &PhotoMapTableEventHandler::DropAllTriggers,
48     };
49 
50 private:
51     DatabaseUtils dbUpgradeUtils_;
52 };
53 }  // namespace OHOS::Media
54 #endif  // OHOS_MEDIA_PHOTO_MAP_TABLE_EVENT_HANDLER_H