1 /* 2 * Copyright (c) 2021 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 NATIVE_RDB_RDB_OPEN_CALLBACK_H 17 #define NATIVE_RDB_RDB_OPEN_CALLBACK_H 18 19 #include "rdb_store.h" 20 21 namespace OHOS { 22 namespace NativeRdb { 23 24 /** 25 * The RdbOpenCallback class of RDB. 26 */ 27 class API_EXPORT RdbOpenCallback { 28 public: 29 /** 30 * @brief Called when the database associate whit this RdbStore is created with the first time. 31 * 32 * This is where the creation of tables and insert the initial data of tables should happen. 33 * 34 * @param rdbStore Indicates the RdbStore object. 35 */ 36 virtual int OnCreate(RdbStore &rdbStore) = 0; 37 38 /** 39 * @brief Called when the database associate whit this RdbStore needs to be upgrade. 40 * 41 * @param rdbStore Indicates the RdbStore object. 42 * @param currentVersion Indicates the old database version. 43 * @param targetVersion Indicates the new database version. 44 */ 45 virtual int OnUpgrade(RdbStore &rdbStore, int currentVersion, int targetVersion) = 0; 46 47 /** 48 * @brief Called when the database associate whit this RdbStore needs to be downgrade. 49 * 50 * @param rdbStore Indicates the RdbStore object. 51 * @param currentVersion Indicates the old database version. 52 * @param targetVersion Indicates the new database version. 53 */ OnDowngrade(RdbStore & rdbStore,int currentVersion,int targetVersion)54 virtual int OnDowngrade(RdbStore &rdbStore, int currentVersion, int targetVersion) 55 { 56 return 0; 57 } 58 59 /** 60 * @brief Called when the RdbStore has been opened. 61 * 62 * @param rdbStore Indicates the RdbStore object. 63 */ OnOpen(RdbStore & rdbStore)64 virtual int OnOpen(RdbStore &rdbStore) 65 { 66 return 0; 67 } 68 69 /** 70 * @brief Called when the RdbStore has been corrupted 71 * 72 * @param databaseFile Indicates the RdbStore file name. 73 */ onCorruption(std::string databaseFile)74 virtual int onCorruption(std::string databaseFile) 75 { 76 return 0; 77 } 78 79 /** 80 * @brief Virtual destructor to ensure proper cleanup of derived class objects. 81 */ 82 virtual ~RdbOpenCallback() = default; 83 }; 84 85 } // namespace NativeRdb 86 } // namespace OHOS 87 #endif 88