Replaced all the references for contacts_db_update_record with AddressbookUtil::Updat...
authorvivek <vivek.ellur@samsung.com>
Thu, 18 Jul 2013 09:00:19 +0000 (14:30 +0530)
committervivek <vivek.ellur@samsung.com>
Wed, 21 Aug 2013 11:41:48 +0000 (17:11 +0530)
Change-Id: Ie5f369c3302ca13ecaf8d4806988dadac51054c4

src/FScl_AddressbookImpl.cpp
src/FScl_AddressbookManagerImpl.cpp
src/FScl_AddressbookUtil.h
src/FScl_PersonImpl.cpp

index ac2d0c4..b482df9 100644 (file)
@@ -464,8 +464,8 @@ _AddressbookImpl::UpdateContact(const Contact& contact)
        recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
        SysTryReturn(NID_SCL, recordHandle != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-       ret = contacts_db_update_record(recordHandle);
-       if (ret == CONTACTS_ERROR_NO_DATA)
+       result r = _AddressbookUtil::UpdateContactRecord(recordHandle);
+       if (r == E_OBJ_NOT_FOUND)
        {
                unsigned int count = 0;
                unsigned int count2 = 0;
@@ -557,12 +557,14 @@ _AddressbookImpl::UpdateContact(const Contact& contact)
 
                        tempPath.Clear();
                }
+               SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+               SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
+       }
+       else
+       {
+               SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
        }
-
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
-       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
-
        ret = contacts_db_get_record(_contacts_contact._uri, contactId, &recordHandle);
        SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
        SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
@@ -630,11 +632,8 @@ _AddressbookImpl::UpdateCategory(const Category& category)
                SysTryReturn(NID_SCL, count == 0, E_OBJ_ALREADY_EXIST, E_OBJ_ALREADY_EXIST, "[%s] The category name is alread being used by other category.", GetErrorMessage(E_OBJ_ALREADY_EXIST));
        }
 
-       ret = contacts_db_update_record(recordHandle);
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
-       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
+       result r = _AddressbookUtil::UpdateContactRecord(recordHandle);
+        SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
 
        ret = contacts_db_get_record(_contacts_group._uri, category.GetRecordId(), &recordHandle);
        SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
@@ -1338,12 +1337,9 @@ _AddressbookImpl::UpdateContacts(const Tizen::Base::Collection::IList& contactLi
                contacts_list_add(listHandle, recordHandle);
        }
 
-       ret = contacts_db_update_records(listHandle);
+       result r = _AddressbookUtil::UpdateContactRecords(listHandle);
+       SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
        contacts_list_destroy(listHandle, false);
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
 
        return E_SUCCESS;
 }
@@ -1439,10 +1435,9 @@ _AddressbookImpl::SetUserProfile(const UserProfile* pUserProfile)
                                ret = contacts_record_clone(recordHandle, &newRecordHandle);
                                SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-                               ret = contacts_db_update_record(newRecordHandle);
+                               result r = _AddressbookUtil::UpdateContactRecord(newRecordHandle);
+                               SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
                                contacts_record_destroy(newRecordHandle, true);
-                               SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-                               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
                        }
                        else
                        {
index 8acd001..a0a88c4 100644 (file)
@@ -456,7 +456,7 @@ _AddressbookManagerImpl::RemoveCategory(RecordId categoryId)
 {
        SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified categoryId is invalid", GetErrorMessage(E_INVALID_ARG));
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
-        
+
        unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, categoryId));
        SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
@@ -488,14 +488,14 @@ _AddressbookManagerImpl::UpdateContact(const Contact& contact)
        contacts_record_h recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
        SysTryReturn(NID_SCL, recordHandle != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-       int ret = contacts_db_update_record(recordHandle);
-       if (ret == CONTACTS_ERROR_NO_DATA)
+       result r = _AddressbookUtil::UpdateContactRecord(recordHandle);
+       if (r == E_OBJ_NOT_FOUND)
        {
                unsigned int count = 0;
                unsigned int count2 = 0;
 
                contacts_record_h newRecordHandle = null;
-               ret = contacts_db_get_record(_contacts_contact._uri, contactId, &newRecordHandle);
+               int ret = contacts_db_get_record(_contacts_contact._uri, contactId, &newRecordHandle);
                SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
                SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
 
@@ -581,12 +581,14 @@ _AddressbookManagerImpl::UpdateContact(const Contact& contact)
 
                        tempPath.Clear();
                }
+               SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+               SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred. Failed to update a contact.", GetErrorMessage(E_SYSTEM));
+       }
+       else
+       {
+               SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
        }
-
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
-       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred. Failed to update a contact.", GetErrorMessage(E_SYSTEM));
-
        pContactRecord.reset(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, contact.GetRecordId()));
        SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
@@ -612,10 +614,8 @@ _AddressbookManagerImpl::UpdateCategory(const Category& category)
 
        contacts_record_h recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle();
 
-       int ret = contacts_db_update_record(recordHandle);
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
-       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
+       result r = _AddressbookUtil::UpdateContactRecord(recordHandle);
+        SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
 
        pCategoryRecord.reset(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, category.GetRecordId()));
        SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
@@ -717,7 +717,7 @@ _AddressbookManagerImpl::GetCategoriesByContactN(RecordId contactId) const
 
        ClearLastResult();
        IList* pCategories = null;
-       
+
        unique_ptr< __Filter<__ContactsContactGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactGroupRel>());
 
        __Filter<__ContactsContactGroupRel> relFilter;
@@ -849,7 +849,7 @@ _AddressbookManagerImpl::GetContactsByCategoryN(RecordId categoryId) const
 
        __Filter<__ContactsContactGroupRel> relFilter;
        relFilter.Construct();
-       
+
        if (categoryId != INVALID_RECORD_ID)
        {
                relFilter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_EQUAL, categoryId);
@@ -894,7 +894,7 @@ _AddressbookManagerImpl::GetContactsByPersonN(PersonId personId) const
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
        ClearLastResult();
-       
+
        IList* pContacts = null;
 
        unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
@@ -1087,7 +1087,7 @@ _AddressbookManagerImpl::SearchContactsByPhoneNumberN(const String& phoneNumber)
                pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, Contact>(query);
                SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
        }
-       
+
 
        return pContacts;
 }
@@ -1282,7 +1282,7 @@ _AddressbookManagerImpl::GetChangedCategoriesAfterN(int version, int& latestVers
        pChangedRelations->RemoveAll(false);
 
        latestVersion = latestVersion2 > latestVersion1 ? latestVersion2 : latestVersion1;
-       
+
        return pChangeList.release();
 }
 
@@ -1592,9 +1592,8 @@ _AddressbookManagerImpl::SetPersonAsFavorite(PersonId personId, bool isFavorite)
        {
                contacts_record_set_bool(pPersonRecord.get(), _contacts_person.is_favorite, isFavorite);
 
-               int ret = contacts_db_update_record(pPersonRecord.get());
-               SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
+               result r = _AddressbookUtil::UpdateContactRecord(pPersonRecord.get());
+               SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
        }
 
        return E_SUCCESS;
@@ -2158,7 +2157,7 @@ _AddressbookManagerImpl::OnEachContact(contacts_record_h recordHandle, void* pUs
 
        pContact.release();
 
-       return true;    
+       return true;
 }
 
 IList*
index 4a3d259..0403f1f 100644 (file)
@@ -835,6 +835,28 @@ public:
                return E_SUCCESS;
        }
 
+       static result UpdateContactRecord(contacts_record_h recordHandle)
+       {
+               int ret = contacts_db_update_record(recordHandle);
+               SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed. (%d)", GetErrorMessage(E_OUT_OF_MEMORY), ret);
+               SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The Record is not found. (%d)", GetErrorMessage(E_OBJ_NOT_FOUND), ret);
+               SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient. (%d)", GetErrorMessage(E_STORAGE_FULL), ret);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred. Failed to update a contact", GetErrorMessage(E_SYSTEM));
+
+               return E_SUCCESS;
+       }
+
+       static result UpdateContactRecords(contacts_list_h listHandle)
+       {
+               int ret = contacts_db_update_records(listHandle);
+               SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
+               SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
+               SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
+
+               return E_SUCCESS;
+       }
+
        static ContactRecord* GetContactRecordN(const char* pUri, RecordId recordId)
        {
                ClearLastResult();
index 77a1552..f8df1f8 100644 (file)
@@ -253,9 +253,8 @@ _PersonImpl::SetAsFavorite(bool isFavorite)
        {
                contacts_record_set_bool(personHandle, _contacts_person.is_favorite, isFavorite);
 
-               ret = contacts_db_update_record(personHandle);
-               SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
+               result r = _AddressbookUtil::UpdateContactRecord(personHandle);
+               SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
 
                __isFavorite = isFavorite;
        }