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 #include "rdb_pdp_profile_callback.h"
17
18 #include "data_storage_errors.h"
19 #include "data_storage_log_wrapper.h"
20 #include "parser_util.h"
21 #include "pdp_profile_data.h"
22 #include "rdb_errno.h"
23 #include "rdb_store.h"
24 #include "values_bucket.h"
25
26 namespace OHOS {
27 namespace Telephony {
OnUpgrade(NativeRdb::RdbStore & rdbStore,int oldVersion,int newVersion)28 int RdbPdpProfileCallback::OnUpgrade(NativeRdb::RdbStore &rdbStore, int oldVersion, int newVersion)
29 {
30 DATA_STORAGE_LOGI("RdbPdpProfileCallback::OnUpgrade##oldVersion = %d, newVersion = %d\n", oldVersion, newVersion);
31 return NativeRdb::E_OK;
32 }
33
OnDowngrade(NativeRdb::RdbStore & rdbStore,int currentVersion,int targetVersion)34 int RdbPdpProfileCallback::OnDowngrade(NativeRdb::RdbStore &rdbStore, int currentVersion, int targetVersion)
35 {
36 DATA_STORAGE_LOGI(
37 "RdbPdpProfileCallback::OnDowngrade##currentVersion = %d, "
38 "targetVersion = %d\n",
39 currentVersion, targetVersion);
40 return NativeRdb::E_OK;
41 }
42
OnOpen(NativeRdb::RdbStore & rdbStore)43 int RdbPdpProfileCallback::OnOpen(NativeRdb::RdbStore &rdbStore)
44 {
45 DATA_STORAGE_LOGI("RdbPdpProfileCallback::OnOpen\n");
46 InitData(rdbStore, TABLE_PDP_PROFILE);
47 return NativeRdb::E_OK;
48 }
49
InitData(NativeRdb::RdbStore & rdbStore,const std::string & tableName)50 void RdbPdpProfileCallback::InitData(NativeRdb::RdbStore &rdbStore, const std::string &tableName)
51 {
52 ParserUtil util;
53 std::vector<PdpProfile> vec;
54 int resultCode = util.ParserPdpProfileJson(vec);
55 if (resultCode != DATA_STORAGE_SUCCESS) {
56 return;
57 }
58 for (size_t i = 0; i < vec.size(); i++) {
59 NativeRdb::ValuesBucket value;
60 util.ParserPdpProfileToValuesBucket(value, vec[i]);
61 int64_t id;
62 rdbStore.Insert(id, tableName, value);
63 }
64 }
65 } // namespace Telephony
66 } // namespace OHOS
67