mirror of
https://gitee.com/openharmony/telephony_core_service
synced 2024-11-22 23:50:24 +00:00
fix vcard import concurrent problem
Signed-off-by: mayuecheng <mayuecheng@huawei.com>
This commit is contained in:
parent
4a8566a23a
commit
d5c8f0539c
@ -633,7 +633,7 @@ HWTEST_F(ContactDataTest, VCardRdbHelper, Function | MediumTest | Level3)
|
||||
{
|
||||
VCardRdbHelper::GetInstance().SetDataHelper(nullptr);
|
||||
|
||||
EXPECT_EQ(VCardRdbHelper::GetInstance().QueryRawContactMaxId(), DB_FAILD);
|
||||
EXPECT_EQ(VCardRdbHelper::GetInstance().QueryRawContactMaxId(0), DB_FAILD);
|
||||
|
||||
std::vector<DataShare::DataShareValuesBucket> rawContactValues;
|
||||
OHOS::DataShare::DataShareValuesBucket rawContactValue;
|
||||
|
@ -229,6 +229,7 @@ public:
|
||||
static constexpr const char *ACCOUNT_ID = "account_id";
|
||||
static constexpr const char *CONTACT_ID = "contact_id";
|
||||
static constexpr const char *IS_DELETED = "is_deleted";
|
||||
static constexpr const char *PRIMARY_CONTACT = "primary_contact";
|
||||
};
|
||||
|
||||
// contact_data
|
||||
|
@ -43,7 +43,7 @@ public:
|
||||
static void SetDataHelper(std::shared_ptr<DataShare::DataShareHelper> dataShareHelper);
|
||||
static void Release();
|
||||
static VCardRdbHelper &GetInstance();
|
||||
static int32_t QueryRawContactMaxId();
|
||||
static int32_t QueryRawContactMaxId(int32_t queryNum);
|
||||
static int32_t BatchInsertRawContact(const std::vector<DataShare::DataShareValuesBucket> &rawContactValues);
|
||||
static int32_t BatchInsertContactData(const std::vector<DataShare::DataShareValuesBucket> &contactsDataValues);
|
||||
static int32_t QueryGroupId(std::string groupName);
|
||||
|
@ -113,8 +113,6 @@ void VCardContact::AddRemainDatas(std::string name, std::string rawValue, std::v
|
||||
AddIms(name, rawValue, propValue, values, parasMap);
|
||||
} else if (name == VCARD_TYPE_X_GROUP) {
|
||||
AddGroups(rawValue);
|
||||
} else {
|
||||
TELEPHONY_LOGI("No need to do anything");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,7 @@ std::string VCardEncoder::ContructVCard(std::shared_ptr<DataShare::DataShareResu
|
||||
std::vector<std::string> columns;
|
||||
DataShare::DataSharePredicates predicates;
|
||||
predicates.EqualTo(RawContact::CONTACT_ID, id)->And()->EqualTo(RawContact::IS_DELETED, CONTACTS_NOT_DELETED);
|
||||
predicates.NotEqualTo(RawContact::PRIMARY_CONTACT, TELEPHONY_ERROR);
|
||||
auto rawResultSet = VCardRdbHelper::GetInstance().QueryRawContact(columns, predicates);
|
||||
if (rawResultSet == nullptr) {
|
||||
TELEPHONY_LOGE("QueryContactData failed");
|
||||
|
@ -176,7 +176,7 @@ void VCardManager::BatchInsertContactDbAbility(int32_t accountId, int32_t &error
|
||||
void VCardManager::BatchInsertRawContact(
|
||||
int32_t accountId, uint32_t size, std::vector<int32_t> &rawIds, int32_t &errorCode)
|
||||
{
|
||||
int32_t rawContactMaxId = VCardRdbHelper::GetInstance().QueryRawContactMaxId();
|
||||
int32_t rawContactMaxId = VCardRdbHelper::GetInstance().QueryRawContactMaxId(static_cast<int32_t>(size));
|
||||
std::vector<DataShare::DataShareValuesBucket> rawContactValues;
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
OHOS::DataShare::DataShareValuesBucket valuesBucket;
|
||||
@ -184,8 +184,10 @@ void VCardManager::BatchInsertRawContact(
|
||||
if (IsContactsIdExit(accountId)) {
|
||||
valuesBucket.Put(RawContact::CONTACT_ID, accountId);
|
||||
}
|
||||
int32_t newRawId = rawContactMaxId + i + 1;
|
||||
valuesBucket.Put(RawContact::ID, newRawId);
|
||||
rawContactValues.push_back(valuesBucket);
|
||||
rawIds.push_back(rawContactMaxId + i + 1);
|
||||
rawIds.push_back(newRawId);
|
||||
}
|
||||
VCardRdbHelper::GetInstance().BatchInsertRawContact(rawContactValues);
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ OHOS::Uri uriRawContact("datashare:///com.ohos.contactsdataability/contacts/raw_
|
||||
OHOS::Uri uriContactData("datashare:///com.ohos.contactsdataability/contacts/contact_data");
|
||||
OHOS::Uri uriAccount("datashare:///com.ohos.contactsdataability/contacts/account");
|
||||
OHOS::Uri uriContact("datashare:///com.ohos.contactsdataability/contacts/contact");
|
||||
OHOS::Uri uriRawContactMaxId("datashare:///com.ohos.contactsdataability/raw_contact/get_inc_id");
|
||||
OHOS::Uri uriGroup("datashare:///com.ohos.contactsdataability/contacts/groups");
|
||||
OHOS::Uri uriRawContactMaxId("datashare:///com.ohos.contactsdataability/raw_contact/place_holder");
|
||||
|
||||
} // namespace
|
||||
|
||||
@ -40,29 +40,23 @@ VCardRdbHelper &VCardRdbHelper::GetInstance()
|
||||
return instance;
|
||||
}
|
||||
|
||||
int32_t VCardRdbHelper::QueryRawContactMaxId()
|
||||
int32_t VCardRdbHelper::QueryRawContactMaxId(int32_t queryNum)
|
||||
{
|
||||
if (dataShareHelper_ == nullptr) {
|
||||
TELEPHONY_LOGE("dataShareHelper is nullptr");
|
||||
return DB_FAILD;
|
||||
}
|
||||
Uri uriRawContactMaxIdQuery(uriRawContactMaxId.ToString() + "?isFromBatch=true");
|
||||
std::vector<std::string> columns;
|
||||
DataShare::DataSharePredicates predicates;
|
||||
std::shared_ptr<DataShare::DataShareResultSet> resultSet =
|
||||
dataShareHelper_->Query(uriRawContactMaxIdQuery, predicates, columns);
|
||||
if (resultSet == nullptr) {
|
||||
TELEPHONY_LOGE("resultSet is nullptr");
|
||||
DataShare::DataShareValuesBucket dbQueryNum;
|
||||
dbQueryNum.Put("importContactNum", queryNum);
|
||||
int32_t queryResult = dataShareHelper_->Insert(uriRawContactMaxIdQuery, dbQueryNum);
|
||||
if (queryResult < 0) {
|
||||
TELEPHONY_LOGE("query RawContactMaxId failed %{public}d", queryResult);
|
||||
|
||||
return DB_FAILD;
|
||||
}
|
||||
int rawMaxId = 0;
|
||||
if (resultSet->GoToFirstRow() == TELEPHONY_ERR_SUCCESS) {
|
||||
int curValueIndex;
|
||||
resultSet->GetColumnIndex("seq", curValueIndex);
|
||||
resultSet->GetInt(curValueIndex, rawMaxId);
|
||||
}
|
||||
TELEPHONY_LOGI("batchInsert rawId: %{public}d", rawMaxId);
|
||||
return rawMaxId;
|
||||
TELEPHONY_LOGW("batchInsert rawId: %{public}d", queryResult);
|
||||
return queryResult;
|
||||
}
|
||||
|
||||
int32_t VCardRdbHelper::BatchInsertRawContact(const std::vector<DataShare::DataShareValuesBucket> &rawContactValues)
|
||||
|
Loading…
Reference in New Issue
Block a user