Filters read-only addressbook
authorGwangbok Kim <gwangbok.kim@samsung.com>
Thu, 30 May 2013 07:28:14 +0000 (16:28 +0900)
committerGwangbok Kim <gwangbok.kim@samsung.com>
Thu, 30 May 2013 14:19:39 +0000 (23:19 +0900)
Change-Id: I0a893b378f5d49bae85b1b5b22742ce3566baea3
Signed-off-by: Gwangbok Kim <gwangbok.kim@samsung.com>
src/FScl_AddressbookManagerImpl.cpp
src/FScl_AddressbookUtil.cpp
src/FScl_AddressbookUtil.h

index e531d7a..917f219 100644 (file)
@@ -62,6 +62,7 @@
 #include "FScl_ContactDbConnector.h"
 #include "FScl_UserProfileImpl.h"
 
+using namespace std;
 using namespace Tizen::App;
 using namespace Tizen::Base;
 using namespace Tizen::Base::Collection;
@@ -202,11 +203,9 @@ _AddressbookManagerImpl::CreateAddressbookN(AccountId accountId, const String& n
        ClearLastResult();
 
        result r = E_SUCCESS;
-       int ret = CONTACTS_ERROR_NONE;
        int recordId = 0;
-       contacts_record_h addressbookHandle = null;
 
-       std::unique_ptr<char[]> pNameString(_StringConverter::CopyToCharArrayN(name));
+       unique_ptr<char[]> pNameString(_StringConverter::CopyToCharArrayN(name));
        SysTryReturn(NID_SCL, pNameString !=null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
        __Filter<__ContactsAddressbook> filter;
@@ -225,25 +224,20 @@ _AddressbookManagerImpl::CreateAddressbookN(AccountId accountId, const String& n
        int count = _AddressbookUtil::GetCountWithQuery(query);
        SysTryReturn(NID_SCL, count == 0, null, E_OBJ_ALREADY_EXIST, "[%s] The name is already being used by other addressbook.", GetErrorMessage(E_OBJ_ALREADY_EXIST));
 
-       std::unique_ptr<Addressbook> pAddressbook(new (std::nothrow) Addressbook());
+       unique_ptr<Addressbook> pAddressbook(new (std::nothrow) Addressbook());
        SysTryReturn(NID_SCL, pAddressbook != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
        r = pAddressbook->Construct();
        SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
 
-       ret = contacts_record_create(_contacts_address_book._uri, &addressbookHandle);
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+       unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::CreateContactRecordN(_contacts_address_book._uri));
+       SysTryReturn(NID_SCL, pAbRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       __ContactsRecordHandle recordHandle(addressbookHandle);
+       contacts_record_set_str(pAbRecord.get(), _contacts_address_book.name, pNameString.get());
+       contacts_record_set_int(pAbRecord.get(), _contacts_address_book.account_id, accountId);
 
-       contacts_record_set_str(addressbookHandle, _contacts_address_book.name, pNameString.get());
-       contacts_record_set_int(addressbookHandle, _contacts_address_book.account_id, accountId);
-
-       ret = contacts_db_insert_record(addressbookHandle, &recordId);
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
+       r = _AddressbookUtil::InsertContactRecordN(pAbRecord.get(), recordId);
+       SysTryReturn(NID_SCL, !IsFailed(r), null, r, "[%s] Propagating.", GetErrorMessage(r));
 
        _AddressbookImpl::GetInstance(*pAddressbook)->SetAccountId(accountId);
        _AddressbookImpl::GetInstance(*pAddressbook)->SetName(name);
@@ -274,13 +268,22 @@ _AddressbookManagerImpl::GetAddressbooksByAccountN(AccountId accountId) const
 
        ClearLastResult();
 
-       __Filter<__ContactsAddressbook> filter;
-       filter.Construct();
-       filter.AddInt(_contacts_address_book.account_id, CONTACTS_MATCH_EQUAL, accountId);
+       __Filter<__ContactsAddressbook> accountFilter;
+       accountFilter.Construct();
+       accountFilter.AddInt(_contacts_address_book.account_id, CONTACTS_MATCH_EQUAL, accountId);
+
+       unique_ptr< __Filter<__ContactsAddressbook> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsAddressbook>());
+
+       __Filter<__ContactsAddressbook> mainFilter;
+       mainFilter.Construct();
+
+       mainFilter.AddFilter(*pRwAbFilter);
+       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+       mainFilter.AddFilter(accountFilter);
 
        __Query<__ContactsAddressbook> query;
        query.Construct();
-       query.SetFilter(filter);
+       query.SetFilter(mainFilter);
 
        IList* pAddressbooks = _AddressbookUtil::SearchWithQueryN<__ContactsAddressbook, Addressbook>(query);
        SysTryReturn(NID_SCL, pAddressbooks != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
@@ -295,8 +298,11 @@ _AddressbookManagerImpl::GetAllAddressbooksN(void) const
 
        ClearLastResult();
 
+       unique_ptr< __Filter<__ContactsAddressbook> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsAddressbook>());
+
        __Query<__ContactsAddressbook> query;
        query.Construct();
+       query.SetFilter(*pRwAbFilter);
        query.SetSort(_contacts_address_book.name, true);
 
        IList* pAddressbooks = _AddressbookUtil::SearchWithQueryN<__ContactsAddressbook, Addressbook>(query);
@@ -314,32 +320,29 @@ _AddressbookManagerImpl::GetAddressbookN(AddressbookId addressbookId) const
        ClearLastResult();
 
        result r = E_SUCCESS;
-       int ret = CONTACTS_ERROR_NONE;
-       contacts_record_h addressbookHandle = null;
        int intValue = 0;
        char* pCharValue = null;
 
-       std::unique_ptr<Addressbook> pAddressbook(new (std::nothrow) Addressbook());
+       unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, addressbookId));
+       SysTryReturn(NID_SCL, pAbRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+       contacts_record_get_int(pAbRecord.get(), _contacts_address_book.mode, &intValue);
+       SysTryReturn(NID_SCL, intValue == 0, null, E_OBJ_NOT_FOUND, "[%s] Addressbook does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
+
+       unique_ptr<Addressbook> pAddressbook(new (std::nothrow) Addressbook());
        SysTryReturn(NID_SCL, pAddressbook !=null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
        r = pAddressbook->Construct();
        SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-       ret = contacts_db_get_record(_contacts_address_book._uri, addressbookId, &addressbookHandle);
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The addressbook %d is not found.", GetErrorMessage(E_OBJ_NOT_FOUND), addressbookId);
-       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred. Addressbook Id(%d)", GetErrorMessage(E_SYSTEM), addressbookId);
-
        _AddressbookImpl::GetInstance(*pAddressbook)->SetId(addressbookId);
 
-       contacts_record_get_int(addressbookHandle, _contacts_address_book.account_id, &intValue);
+       contacts_record_get_int(pAbRecord.get(), _contacts_address_book.account_id, &intValue);
        _AddressbookImpl::GetInstance(*pAddressbook)->SetAccountId(intValue);
 
-       contacts_record_get_str_p(addressbookHandle, _contacts_address_book.name, &pCharValue);
+       contacts_record_get_str_p(pAbRecord.get(), _contacts_address_book.name, &pCharValue);
        _AddressbookImpl::GetInstance(*pAddressbook)->SetName(pCharValue);
 
-       contacts_record_destroy(addressbookHandle, true);
-
        return pAddressbook.release();
 }
 
@@ -356,35 +359,27 @@ _AddressbookManagerImpl::AddContact(Contact& contact, AddressbookId addressbookI
        SysTryReturn(NID_SCL, !_ContactImpl::GetInstance(contact)->IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified contact does not have any property.", GetErrorMessage(E_INVALID_ARG));
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       int recordId = 0;
-       contacts_record_h recordHandle = null;
-
-       int ret = contacts_db_get_record(_contacts_address_book._uri, addressbookId, &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_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The addressbook is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
-       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
-
-       contacts_record_destroy(recordHandle, true);
+       unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, addressbookId));
+       SysTryReturn(NID_SCL, pAbRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
+       int intValue = 0;
+       contacts_record_get_int(pAbRecord.get(), _contacts_address_book.mode, &intValue);
+       SysTryReturn(NID_SCL, intValue == 0, null, E_OBJ_NOT_FOUND, "[%s] Addressbook does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
 
+       contacts_record_h recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
        contacts_record_set_int(recordHandle, _contacts_contact.address_book_id, addressbookId);
 
-       ret = contacts_db_insert_record(recordHandle, &recordId);
-       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));
+       int recordId = 0;
+       result r = _AddressbookUtil::InsertContactRecordN(recordHandle, recordId);
+       SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
 
-       ret = contacts_db_get_record(_contacts_contact._uri, recordId, &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_NONE, E_SYSTEM, E_SYSTEM, "[%s] A sytem error has been occurred.", GetErrorMessage(E_SYSTEM));
+       unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, recordId));
+       SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       _ContactImpl::GetInstance(contact)->SetContactRecordHandle(recordHandle);
+       _ContactImpl::GetInstance(contact)->SetContactRecordHandle(pContactRecord.release());
        _RecordImpl::GetInstance(contact)->SetRecordId(recordId);
 
        return E_SUCCESS;
-
 }
 
 result
@@ -393,31 +388,30 @@ _AddressbookManagerImpl::AddCategory(Category& category, AddressbookId addressbo
        SysTryReturn(NID_SCL, category.GetRecordId() == INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified categoryId is not INVALID_RECORD_ID.", GetErrorMessage(E_INVALID_ARG));
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       int recordId = 0;
-       contacts_record_h recordHandle = null;
-       std::unique_ptr<IListT<int> > pList(null);
+       unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, addressbookId));
+       SysTryReturn(NID_SCL, pAbRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle();
+       int intValue = 0;
+       contacts_record_get_int(pAbRecord.get(), _contacts_address_book.mode, &intValue);
+       SysTryReturn(NID_SCL, intValue == 0, null, E_OBJ_NOT_FOUND, "[%s] Addressbook does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
 
+       contacts_record_h recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle();
        contacts_record_set_int(recordHandle, _contacts_group.address_book_id, addressbookId);
 
-       int ret = contacts_db_insert_record(recordHandle, &recordId);
-       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));
+       int recordId = 0;
+       result r = _AddressbookUtil::InsertContactRecordN(recordHandle, recordId);
+       SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
 
-       ret = contacts_db_get_record(_contacts_group._uri, recordId, &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));
-       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 sytem error has been occurred.", GetErrorMessage(E_SYSTEM));
+       unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, recordId));
+       SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       _CategoryImpl::GetInstance(category)->SetRecordHandle(recordHandle);
+       _CategoryImpl::GetInstance(category)->SetRecordHandle(pCategoryRecord.release());
        _RecordImpl::GetInstance(category)->SetRecordId(recordId);
 
-       pList.reset(_CategoryImpl::GetInstance(category)->GetAddedMembersN());
+       unique_ptr<IListT<int> > pList(_CategoryImpl::GetInstance(category)->GetAddedMembersN());
        if (pList != null && pList->GetCount() > 0)
        {
-               std::unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
+               unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
 
                while (pEnum->MoveNext() == E_SUCCESS)
                {
@@ -431,7 +425,6 @@ _AddressbookManagerImpl::AddCategory(Category& category, AddressbookId addressbo
        }
 
        return E_SUCCESS;
-
 }
 
 result
@@ -440,20 +433,14 @@ _AddressbookManagerImpl::RemoveContact(RecordId contactId)
        SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified contactId is invalid.", GetErrorMessage(E_INVALID_ARG));
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       contacts_record_h recordHandle = null;
+       unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_simple_contact._uri, contactId));
+       SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
        int intValue = 0;
-       int ret = contacts_db_get_record(_contacts_simple_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));
-       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
-
-       contacts_record_get_int(recordHandle, _contacts_simple_contact.id, &intValue);
-
-       contacts_record_destroy(recordHandle, true);
+       contacts_record_get_int(pContactRecord.get(), _contacts_simple_contact.id, &intValue);
        SysTryReturn(NID_SCL, intValue == contactId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
 
-       ret = contacts_db_delete_record(_contacts_contact._uri, contactId);
+       int ret = contacts_db_delete_record(_contacts_contact._uri, contactId);
        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_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_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
@@ -467,25 +454,18 @@ _AddressbookManagerImpl::RemoveCategory(RecordId categoryId)
        SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. categoryId = %d.", GetErrorMessage(E_INVALID_ARG), categoryId);
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
         
-       int intValue = 0;
-       int ret = CONTACTS_ERROR_NONE;
-       contacts_record_h recordHandle = null;
+       unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, categoryId));
+       SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       ret = contacts_db_get_record(_contacts_group._uri, categoryId, &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));
-       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));
-
-       __ContactsRecordHandle categoryHandle(recordHandle);
-
-       contacts_record_get_int(recordHandle, _contacts_group.id, &intValue);
+       int intValue = 0;
+       contacts_record_get_int(pCategoryRecord.get(), _contacts_group.id, &intValue);
        SysTryReturn(NID_SCL, intValue == categoryId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
 
        bool isReadOnly = false;
-       contacts_record_get_bool(recordHandle, _contacts_group.is_read_only, &isReadOnly);
+       contacts_record_get_bool(pCategoryRecord.get(), _contacts_group.is_read_only, &isReadOnly);
        SysTryReturn(NID_SCL, !isReadOnly, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified category is a default category.", GetErrorMessage(E_INVALID_ARG));
 
-       ret = contacts_db_delete_record(_contacts_group._uri, categoryId);
+       int ret = contacts_db_delete_record(_contacts_group._uri, categoryId);
        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_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
 //     SysTryReturnResult(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OPERATION_FAILED, "Failed to delete a category.(%d)", ret); // temp
@@ -501,32 +481,24 @@ _AddressbookManagerImpl::UpdateContact(const Contact& contact)
        SysTryReturn(NID_SCL, !_ContactImpl::GetInstance(contact)->IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified contact does not have any property.", GetErrorMessage(E_INVALID_ARG));
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       contacts_record_h recordHandle = null;
-       
-       int intValue = 0;
-       int ret = contacts_db_get_record(_contacts_simple_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));
-       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
-
-       contacts_record_get_int(recordHandle, _contacts_simple_contact.id, &intValue);
+       unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_simple_contact._uri, contactId));
+       SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       contacts_record_destroy(recordHandle, true);
+       int intValue = 0;
+       contacts_record_get_int(pContactRecord.get(), _contacts_simple_contact.id, &intValue);
        SysTryReturn(NID_SCL, intValue == contactId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
 
-       recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
+       contacts_record_h recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
 
-       ret = contacts_db_update_record(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.", 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));
 
-       ret = contacts_db_get_record(_contacts_contact._uri, contact.GetRecordId(), &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_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
+       pContactRecord.reset(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, contact.GetRecordId()));
+       SysTryReturn(NID_SCL, pContactRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       _ContactImpl::GetInstance(*const_cast<Contact*>(&contact))->SetContactRecordHandle(recordHandle);
+       _ContactImpl::GetInstance(*const_cast<Contact*>(&contact))->SetContactRecordHandle(pContactRecord.release());
 
        return E_SUCCESS;
 }
@@ -539,37 +511,30 @@ _AddressbookManagerImpl::UpdateCategory(const Category& category)
        SysTryReturn(NID_SCL, !category.GetName().IsEmpty(), E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The specified category does not have name.", GetErrorMessage(E_INVALID_ARG));
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       contacts_record_h recordHandle = null;
-       int intValue = 0;
-
-       int ret = contacts_db_get_record(_contacts_group._uri, categoryId, &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_NONE, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The specified category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
-
-       contacts_record_get_int(recordHandle, _contacts_group.id, &intValue);
+       unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, category.GetRecordId()));
+       SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       contacts_record_destroy(recordHandle, true);
+       int intValue = 0;
+       contacts_record_get_int(pCategoryRecord.get(), _contacts_group.id, &intValue);
        SysTryReturn(NID_SCL, intValue == categoryId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
 
-       recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle();
+       contacts_record_h recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle();
 
-       ret = contacts_db_update_record(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.", 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_group._uri, category.GetRecordId(), &recordHandle);
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The category is 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_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
+       pCategoryRecord.reset(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, category.GetRecordId()));
+       SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       _CategoryImpl::GetInstance(*const_cast<Category*>(&category))->SetRecordHandle(recordHandle);
+       _CategoryImpl::GetInstance(*const_cast<Category*>(&category))->SetRecordHandle(pCategoryRecord.release());
 
-       std::unique_ptr<IListT<int> > pList(_CategoryImpl::GetInstance(category)->GetAddedMembersN());
+       unique_ptr<IListT<int> > pList(_CategoryImpl::GetInstance(category)->GetAddedMembersN());
        if (pList != null && pList->GetCount() > 0)
        {
                int tableId = -1;
-               std::unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
+               unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
                while (pEnum->MoveNext() == E_SUCCESS)
                {
                        pEnum->GetCurrent(tableId);
@@ -584,7 +549,7 @@ _AddressbookManagerImpl::UpdateCategory(const Category& category)
        if (pList != null && pList->GetCount() > 0)
        {
                int tableId = -1;
-               std::unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
+               unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
                while (pEnum->MoveNext() == E_SUCCESS)
                {
                        pEnum->GetCurrent(tableId);
@@ -596,13 +561,11 @@ _AddressbookManagerImpl::UpdateCategory(const Category& category)
        }
 
        return E_SUCCESS;
-
 }
 
 result
 _AddressbookManagerImpl::AddMemberToCategory(RecordId categoryId, RecordId contactId)
 {
-
        SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. categoryId = %d.", GetErrorMessage(E_INVALID_ARG), categoryId);
        SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactId = %d.", GetErrorMessage(E_INVALID_ARG), contactId);
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
@@ -618,7 +581,6 @@ _AddressbookManagerImpl::AddMemberToCategory(RecordId categoryId, RecordId conta
 result
 _AddressbookManagerImpl::RemoveMemberFromCategory(RecordId categoryId, RecordId contactId)
 {
-
        SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. categoryId = %d.", GetErrorMessage(E_INVALID_ARG), categoryId);
        SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. contactId = %d.", GetErrorMessage(E_INVALID_ARG), contactId);
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
@@ -638,8 +600,11 @@ _AddressbookManagerImpl::GetAllCategoriesN(void) const
 
        ClearLastResult();
 
+       unique_ptr< __Filter<__ContactsGroup> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsGroup>());
+
        __Query<__ContactsGroup> query;
        query.Construct();
+       query.SetFilter(*pRwAbFilter);
        query.SetSort(_contacts_group.name, true);
 
        IList* pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsGroup, Category>(query);
@@ -656,15 +621,22 @@ _AddressbookManagerImpl::GetCategoriesByContactN(RecordId contactId) const
 
        ClearLastResult();
 
-       __Filter<__ContactsGroupRelation> filter;
-       filter.Construct();
-       filter.AddInt(_contacts_group_relation.contact_id, CONTACTS_MATCH_EQUAL, contactId);
+       unique_ptr< __Filter<__ContactsContactGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactGroupRel>());
 
-       __Query<__ContactsGroupRelation> query;
+       __Filter<__ContactsContactGroupRel> relFilter;
+       relFilter.Construct();
+       relFilter.AddInt(_contacts_group_relation.contact_id, CONTACTS_MATCH_EQUAL, contactId);
+
+       __Filter<__ContactsContactGroupRel> mainFilter;
+       mainFilter.AddFilter(*pRwAbFilter);
+       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+       mainFilter.AddFilter(relFilter);
+
+       __Query<__ContactsContactGroupRel> query;
        query.Construct();
-       query.SetFilter(filter);
+       query.SetFilter(mainFilter);
 
-       IList* pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsGroupRelation, Category>(query);
+       IList* pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Category>(query);
        SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
        return pCategories;
@@ -677,11 +649,18 @@ _AddressbookManagerImpl::GetCategoriesByPersonN(PersonId personId) const
 
        ClearLastResult();
 
-       __Filter<__ContactsContactGroupRel> filter;
-       filter.Construct();
-       filter.AddInt(_contacts_contact_grouprel.person_id, CONTACTS_MATCH_EQUAL, personId);
-       filter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
-       filter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_GREATER_THAN, 0);
+       unique_ptr< __Filter<__ContactsContactGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactGroupRel>());
+
+       __Filter<__ContactsContactGroupRel> relFilter;
+       relFilter.Construct();
+       relFilter.AddInt(_contacts_contact_grouprel.person_id, CONTACTS_MATCH_EQUAL, personId);
+       relFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+       relFilter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_GREATER_THAN, 0);
+
+       __Filter<__ContactsContactGroupRel> mainFilter;
+       mainFilter.AddFilter(*pRwAbFilter);
+       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+       mainFilter.AddFilter(relFilter);
 
        unsigned int propertyIds[] =
        {
@@ -691,7 +670,7 @@ _AddressbookManagerImpl::GetCategoriesByPersonN(PersonId personId) const
        __Query<__ContactsContactGroupRel> query;
        query.Construct();
        query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
-       query.SetFilter(filter);
+       query.SetFilter(mainFilter);
        query.SetSort(_contacts_contact_grouprel.group_name, true);
        query.SetDistinct(true);
 
@@ -708,8 +687,11 @@ _AddressbookManagerImpl::GetAllContactsN(void) const
 
        ClearLastResult();
 
+       unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
+
        __Query<__ContactsContact> query;
        query.Construct();
+       query.SetFilter(*pRwAbFilter);
        query.SetSort(_contacts_contact.display_name, true);
 
        IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
@@ -726,22 +708,30 @@ _AddressbookManagerImpl::GetContactsByCategoryN(RecordId categoryId) const
 
        ClearLastResult();
 
-       __Filter<__ContactsContactGroupRel> filter;
-       filter.Construct();
+       unique_ptr< __Filter<__ContactsContactGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactGroupRel>());
+
+       __Filter<__ContactsContactGroupRel> relFilter;
+       relFilter.Construct();
        
        if (categoryId != INVALID_RECORD_ID)
        {
-               filter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_EQUAL, categoryId);
+               relFilter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_EQUAL, categoryId);
        }
        else
        {
-               filter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_NONE, 0);
+               relFilter.AddInt(_contacts_contact_grouprel.group_id, CONTACTS_MATCH_NONE, 0);
        }
 
+       __Filter<__ContactsContactGroupRel> mainFilter;
+       mainFilter.Construct();
+
+       mainFilter.AddFilter(*pRwAbFilter);
+       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+       mainFilter.AddFilter(relFilter);
+
        __Query<__ContactsContactGroupRel> query;
        query.Construct();
-       query.SetFilter(filter);
-
+       query.SetFilter(mainFilter);
 
        IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Contact>(query);
        SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
@@ -756,13 +746,22 @@ _AddressbookManagerImpl::GetContactsByPersonN(PersonId personId) const
 
        ClearLastResult();
 
-       __Filter<__ContactsContact> filter;
-       filter.Construct();
-       filter.AddInt(_contacts_contact.person_id, CONTACTS_MATCH_EQUAL, personId);
+       unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
+
+       __Filter<__ContactsContact> contactFilter;
+       contactFilter.Construct();
+       contactFilter.AddInt(_contacts_contact.person_id, CONTACTS_MATCH_EQUAL, personId);
+
+       __Filter<__ContactsContact> mainFilter;
+       mainFilter.Construct();
+
+       mainFilter.AddFilter(*pRwAbFilter);
+       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+       mainFilter.AddFilter(contactFilter);
 
        __Query<__ContactsContact> query;
        query.Construct();
-       query.SetFilter(filter);
+       query.SetFilter(mainFilter);
        query.SetSort(_contacts_contact.display_name, true);
 
        IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
@@ -779,23 +778,31 @@ _AddressbookManagerImpl::SearchContactsByEmailN(const String& email) const
 
        ClearLastResult();
 
-       std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(email));
+       unique_ptr< __Filter<__ContactsContactEmail> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactEmail>());
+
+       unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(email));
        SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-       __Filter<__ContactsContactEmail> filter;
-       filter.Construct();
-       filter.AddString(_contacts_contact_email.email, CONTACTS_MATCH_CONTAINS, pCharArray.get());
+       __Filter<__ContactsContactEmail> emailFilter;
+       emailFilter.Construct();
+       emailFilter.AddString(_contacts_contact_email.email, CONTACTS_MATCH_CONTAINS, pCharArray.get());
+
+       __Filter<__ContactsContactEmail> mainFilter;
+       mainFilter.Construct();
+
+       mainFilter.AddFilter(*pRwAbFilter);
+       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+       mainFilter.AddFilter(emailFilter);
 
        __Query<__ContactsContactEmail> query;
        query.Construct();
-       query.SetFilter(filter);
+       query.SetFilter(mainFilter);
        query.SetSort(_contacts_contact_email.display_name, true);
 
        IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, Contact>(query);
        SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
        return pContacts;
-
 }
 
 IList*
@@ -805,18 +812,27 @@ _AddressbookManagerImpl::SearchContactsByNameN(const String& name) const
 
        ClearLastResult();
 
+       unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
+
        SysTryReturn(NID_SCL, !name.IsEmpty(), null, E_INVALID_ARG, "[%s] Invalid argument is used. The specified email is an name string.", GetErrorMessage(E_INVALID_ARG));
 
-       std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(name));
+       unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(name));
        SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-       __Filter<__ContactsContact> filter;
-       filter.Construct();
-       filter.AddString(_contacts_contact.display_name, CONTACTS_MATCH_CONTAINS, pCharArray.get());
+       __Filter<__ContactsContact> nameFilter;
+       nameFilter.Construct();
+       nameFilter.AddString(_contacts_contact.display_name, CONTACTS_MATCH_CONTAINS, pCharArray.get());
+
+       __Filter<__ContactsContact> mainFilter;
+       mainFilter.Construct();
+
+       mainFilter.AddFilter(*pRwAbFilter);
+       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+       mainFilter.AddFilter(nameFilter);
 
        __Query<__ContactsContact> query;
        query.Construct();
-       query.SetFilter(filter);
+       query.SetFilter(mainFilter);
        query.SetSort(_contacts_contact.display_name, true);
 
        IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
@@ -834,16 +850,25 @@ _AddressbookManagerImpl::SearchContactsByPhoneNumberN(const String& phoneNumber)
 
        SysTryReturn(NID_SCL, !phoneNumber.IsEmpty(), null, E_INVALID_ARG, "[%s] Invalid argument is used. The specified phoneNumber is an empty string.", GetErrorMessage(E_INVALID_ARG));
 
-       std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(phoneNumber));
+       unique_ptr< __Filter<__ContactsContactNumber> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactNumber>());
+
+       unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(phoneNumber));
        SysTryReturn(NID_SCL, pCharArray != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-       __Filter<__ContactsContactNumber> filter;
-       filter.Construct();
-       filter.AddString(_contacts_contact_number.number, CONTACTS_MATCH_CONTAINS, pCharArray.get());
+       __Filter<__ContactsContactNumber> numberFilter;
+       numberFilter.Construct();
+       numberFilter.AddString(_contacts_contact_number.number, CONTACTS_MATCH_CONTAINS, pCharArray.get());
+
+       __Filter<__ContactsContactNumber> mainFilter;
+       mainFilter.Construct();
+
+       mainFilter.AddFilter(*pRwAbFilter);
+       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+       mainFilter.AddFilter(numberFilter);
 
        __Query<__ContactsContactNumber> query;
        query.Construct();
-       query.SetFilter(filter);
+       query.SetFilter(mainFilter);
        query.SetDistinct(true);
        query.SetSort(_contacts_contact_number.display_name, true);
 
@@ -858,11 +883,11 @@ _AddressbookManagerImpl::GetCategoryCount(void) const
 {
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       int count = -1;
-
        ClearLastResult();
 
-       count = _AddressbookUtil::GetCount<__ContactsGroup>();
+       unique_ptr< __Filter<__ContactsGroup> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsGroup>());
+
+       int count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsGroup>(pRwAbFilter->Get());
        SysTryReturn(NID_SCL, count >= 0, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
        return count;
@@ -873,11 +898,11 @@ _AddressbookManagerImpl::GetContactCount(void) const
 {
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       int count = -1;
-
        ClearLastResult();
 
-       count = _AddressbookUtil::GetCount<__ContactsContact>();
+       unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
+
+       int count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContact>(pRwAbFilter->Get());
        SysTryReturn(NID_SCL, count >= 0, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
        return count;
@@ -891,22 +916,25 @@ _AddressbookManagerImpl::GetContactN(RecordId contactId) const
 
        ClearLastResult();
 
-       int intValue = 0;
-       contacts_record_h contactHandle = null;
+       unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, contactId));
+       SysTryReturn(NID_SCL, pContactRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       std::unique_ptr<Contact> pContact(new (std::nothrow) Contact());
-       SysTryReturn(NID_SCL, pContact, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+       int intValue = 0;
+       contacts_record_get_int(pContactRecord.get(), _contacts_contact.address_book_id, &intValue);
 
-       int ret = contacts_db_get_record(_contacts_contact._uri, contactId, &contactHandle);
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
-       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
+       unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, intValue));
+       SysTryReturn(NID_SCL, pAbRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(contactHandle);
+       contacts_record_get_int(pAbRecord.get(), _contacts_address_book.mode, &intValue);
+       SysTryReturn(NID_SCL, intValue == 0, null, E_OBJ_NOT_FOUND, "[%s] Contact does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
 
-       contacts_record_get_int(contactHandle, _contacts_contact.id, &intValue);
+       contacts_record_get_int(pContactRecord.get(), _contacts_contact.id, &intValue);
        SysTryReturn(NID_SCL, intValue == contactId, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
 
+       unique_ptr<Contact> pContact(new (std::nothrow) Contact());
+       SysTryReturn(NID_SCL, pContact, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(pContactRecord.release());
        _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
 
        return pContact.release();
@@ -918,22 +946,15 @@ _AddressbookManagerImpl::GetPersonN(PersonId personId) const
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
        SysTryReturn(NID_SCL, personId >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. personId = %d.", GetErrorMessage(E_INVALID_ARG), personId);
 
-       contacts_record_h recordHandle = null;
-
        ClearLastResult();
 
-       int intValue = 0;
-       int ret = contacts_db_get_record(_contacts_person._uri, personId, &recordHandle);
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The person is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
-       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
-
-       __ContactsRecordHandle personRecord(recordHandle);
+       unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, personId));
 
-       contacts_record_get_int(recordHandle, _contacts_person.id, &intValue);
+       int intValue = 0;
+       contacts_record_get_int(pPersonRecord.get(), _contacts_person.id, &intValue);
        SysTryReturn(NID_SCL, intValue == personId, null, E_OBJ_NOT_FOUND, "[%s] The person is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
 
-       Person* pPerson = __ContactsPerson::ConvertHandleTo<Person>(recordHandle);
+       Person* pPerson = __ContactsPerson::ConvertHandleTo<Person>(pPersonRecord.get());
        SysTryReturn(NID_SCL, pPerson != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
        return pPerson;
@@ -945,23 +966,27 @@ _AddressbookManagerImpl::GetCategoryN(RecordId categoryId) const
        SysTryReturn(NID_SCL, categoryId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. categoryId = %d.", categoryId);
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       contacts_record_h recordHandle = null;
-
        ClearLastResult();
 
-       int ret = contacts_db_get_record(_contacts_group._uri, categoryId, &recordHandle);
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
+       unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, categoryId));
+       SysTryReturn(NID_SCL, pCategoryRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
        int intValue = 0;
-       contacts_record_get_int(recordHandle, _contacts_group.id, &intValue);
-       
-       std::unique_ptr<Category> pCategory(new (std::nothrow) Category());
-       SysTryReturn(NID_SCL, pCategory != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
+       contacts_record_get_int(pCategoryRecord.get(), _contacts_group.id, &intValue);
        SysTryReturn(NID_SCL, categoryId == intValue, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
 
+       contacts_record_get_int(pCategoryRecord.get(), _contacts_group.address_book_id, &intValue);
+
+       unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, intValue));
+       SysTryReturn(NID_SCL, pAbRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+       contacts_record_get_int(pAbRecord.get(), _contacts_address_book.mode, &intValue);
+       SysTryReturn(NID_SCL, intValue == 0, null, E_OBJ_NOT_FOUND, "[%s] Category does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
+
+       unique_ptr<Category> pCategory(new (std::nothrow) Category());
+       SysTryReturn(NID_SCL, pCategory != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
        __Filter<__ContactsGroupRelation> filter;
        filter.Construct();
        filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, categoryId);
@@ -973,7 +998,7 @@ _AddressbookManagerImpl::GetCategoryN(RecordId categoryId) const
        int count = _AddressbookUtil::GetCountWithQuery(query);
        SysTryReturn(NID_SCL, count >= 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(recordHandle);
+       _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(pCategoryRecord.release());
        _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count);
        _RecordImpl::GetInstance(*pCategory)->SetRecordId(categoryId);
 
@@ -1003,7 +1028,9 @@ _AddressbookManagerImpl::GetChangedContactsAfterN(int version, int& latestVersio
 
        ClearLastResult();
 
-       IList* pChangedContacts = _AddressbookUtil::SearchWithVersionN<__ContactsContactUpdatedInfo, ContactChangeInfo>(-1, version, latestVersion);
+       unique_ptr< IListT<AddressbookId> > pRwAbIdList(_AddressbookUtil::GetRwAbIdListN());
+
+       IList* pChangedContacts = _AddressbookUtil::SearchWithVersionN<__ContactsContactUpdatedInfo, ContactChangeInfo>(-1, version, latestVersion, pRwAbIdList.get());
        SysTryReturn(NID_SCL, pChangedContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
        return pChangedContacts;
@@ -1020,13 +1047,15 @@ _AddressbookManagerImpl::GetChangedCategoriesAfterN(int version, int& latestVers
        int latestVersion1 = 0;
        int latestVersion2 = 0;
 
-       std::unique_ptr<IList, AllElementsDeleter> pChangedGroups(_AddressbookUtil::SearchWithVersionN<__ContactsGroupUpdatedInfo, CategoryChangeInfo>(-1, version, latestVersion1));
+       unique_ptr< IListT<AddressbookId> > pRwAbIdList(_AddressbookUtil::GetRwAbIdListN());
+
+       unique_ptr<IList, AllElementsDeleter> pChangedGroups(_AddressbookUtil::SearchWithVersionN<__ContactsGroupUpdatedInfo, CategoryChangeInfo>(-1, version, latestVersion1, pRwAbIdList.get()));
        SysTryReturn(NID_SCL, pChangedGroups != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       std::unique_ptr<IList, AllElementsDeleter> pChangedRelations(_AddressbookUtil::SearchWithVersionN<__ContactsGroupRelUpdatedInfo, CategoryChangeInfo>(-1, version, latestVersion2));
+       unique_ptr<IList, AllElementsDeleter> pChangedRelations(_AddressbookUtil::SearchWithVersionN<__ContactsGroupRelUpdatedInfo, CategoryChangeInfo>(-1, version, latestVersion2, pRwAbIdList.get()));
        SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       std::unique_ptr<ArrayList, AllElementsDeleter> pChangeList(new (std::nothrow) Tizen::Base::Collection::ArrayList());
+       unique_ptr<ArrayList, AllElementsDeleter> pChangeList(new (std::nothrow) Tizen::Base::Collection::ArrayList());
        SysTryReturn(NID_SCL, pChangeList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
        result r = pChangeList->AddItems(*pChangedGroups);
@@ -1041,7 +1070,6 @@ _AddressbookManagerImpl::GetChangedCategoriesAfterN(int version, int& latestVers
        latestVersion = latestVersion2 > latestVersion1 ? latestVersion2 : latestVersion1;
        
        return pChangeList.release();
-
 }
 
 IList*
@@ -1052,7 +1080,9 @@ _AddressbookManagerImpl::GetChangedGroupsAfterN(int version, int& latestVersion)
 
        ClearLastResult();
 
-       IList* pChangedRelations = _AddressbookUtil::SearchWithVersionN<__ContactsGroupUpdatedInfo, CategoryChangeInfo>(-1, version, latestVersion);
+       unique_ptr< IListT<AddressbookId> > pRwAbIdList(_AddressbookUtil::GetRwAbIdListN());
+
+       IList* pChangedRelations = _AddressbookUtil::SearchWithVersionN<__ContactsGroupUpdatedInfo, CategoryChangeInfo>(-1, version, latestVersion, pRwAbIdList.get());
        SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
        return pChangedRelations;
@@ -1066,7 +1096,9 @@ _AddressbookManagerImpl::GetChangedRelationsAfterN(int version, int& latestVersi
 
        ClearLastResult();
 
-       IList* pChangedRelations = _AddressbookUtil::SearchWithVersionN<__ContactsGroupRelUpdatedInfo, CategoryChangeInfo>(-1, version, latestVersion);
+       unique_ptr< IListT<AddressbookId> > pRwAbIdList(_AddressbookUtil::GetRwAbIdListN());
+
+       IList* pChangedRelations = _AddressbookUtil::SearchWithVersionN<__ContactsGroupRelUpdatedInfo, CategoryChangeInfo>(-1, version, latestVersion, pRwAbIdList.get());
        SysTryReturn(NID_SCL, pChangedRelations != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
        return pChangedRelations;
@@ -1155,16 +1187,10 @@ _AddressbookManagerImpl::RemovePerson(PersonId personId)
        SysTryReturnResult(NID_SCL, personId > 0, E_INVALID_ARG, "[%s] Invalid argument is used. personId = %d.", GetErrorMessage(E_INVALID_ARG), personId);
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       contacts_record_h recordHandle = null;
-
-       int ret = contacts_db_get_record(_contacts_person._uri, personId, &recordHandle);
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The person 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_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred. Failed remove a person.", GetErrorMessage(E_SYSTEM));
-
-       contacts_record_destroy(recordHandle, true);
+       unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, personId));
+       SysTryReturn(NID_SCL, pPersonRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       ret = contacts_db_delete_record(_contacts_person._uri, personId);
+       int ret = contacts_db_delete_record(_contacts_person._uri, personId);
        SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The person is 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_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred. Failed remove a person.", GetErrorMessage(E_SYSTEM));
@@ -1179,11 +1205,30 @@ _AddressbookManagerImpl::GetAllPersonsN(void) const
 
        ClearLastResult();
 
-       __Query<__ContactsPerson> query;
+       unique_ptr< __Filter<__ContactsPersonGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsPersonGroupRel>());
+
+//     unsigned int propertyIds[] = { _contacts_person_grouprel.person_id };
+       unsigned int propertyIds[] =
+       {
+               _contacts_person_grouprel.person_id,
+               _contacts_person_grouprel.display_name,
+               _contacts_person_grouprel.image_thumbnail_path,
+               _contacts_person_grouprel.ringtone_path,
+               _contacts_person_grouprel.is_favorite,
+               _contacts_person_grouprel.has_phonenumber,
+               _contacts_person_grouprel.has_email,
+               _contacts_person_grouprel.addressbook_ids,
+       };
+
+
+       __Query<__ContactsPersonGroupRel> query;
        query.Construct();
+       query.SetFilter(*pRwAbFilter);
        query.SetSort(_contacts_person.display_name, true);
+       query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
+       query.SetDistinct(true);
 
-       IList* pPersons = _AddressbookUtil::SearchWithQueryN<__ContactsPerson, Person>(query);
+       IList* pPersons = _AddressbookUtil::SearchWithQueryN<__ContactsPersonGroupRel, Person>(query);
        SysTryReturn(NID_SCL, pPersons != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
        return pPersons;
@@ -1197,15 +1242,17 @@ _AddressbookManagerImpl::GetPersonsByCategoryN(RecordId categoryId) const
 
        ClearLastResult();
 
-       __Filter<__ContactsPersonGroupRel> filter;
-       filter.Construct();
+       unique_ptr< __Filter<__ContactsPersonGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsPersonGroupRel>());
+
+       __Filter<__ContactsPersonGroupRel> groupFilter;
+       groupFilter.Construct();
        if (categoryId != INVALID_RECORD_ID)
        {
-               filter.AddInt(_contacts_person_grouprel.group_id, CONTACTS_MATCH_EQUAL, categoryId);
+               groupFilter.AddInt(_contacts_person_grouprel.group_id, CONTACTS_MATCH_EQUAL, categoryId);
        }
        else
        {
-               filter.AddInt(_contacts_person_grouprel.group_id, CONTACTS_MATCH_NONE, 0);
+               groupFilter.AddInt(_contacts_person_grouprel.group_id, CONTACTS_MATCH_NONE, 0);
        }
 
        unsigned int propertyIds[] =
@@ -1217,13 +1264,21 @@ _AddressbookManagerImpl::GetPersonsByCategoryN(RecordId categoryId) const
                _contacts_person_grouprel.is_favorite,
                _contacts_person_grouprel.has_phonenumber,
                _contacts_person_grouprel.has_email,
-               _contacts_person_grouprel.link_count,
+               _contacts_person_grouprel.addressbook_ids,
        };
 
+       __Filter<__ContactsPersonGroupRel> mainFilter;
+       mainFilter.Construct();
+
+       mainFilter.AddFilter(*pRwAbFilter);
+       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+       mainFilter.AddFilter(groupFilter);
+
+
        __Query<__ContactsPersonGroupRel> query;
        query.Construct();
        query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
-       query.SetFilter(filter);
+       query.SetFilter(mainFilter);
        query.SetSort(_contacts_person_grouprel.display_name, true);
        query.SetDistinct(true);
 
@@ -1264,15 +1319,15 @@ _AddressbookManagerImpl::SearchPersonsN(const Tizen::Base::String& keyword) cons
        ClearLastResult();
 
        contacts_record_h currentRecord = null;
-       std::unique_ptr<Person> pPerson(null);
+       unique_ptr<Person> pPerson(null);
 
-       std::unique_ptr<ArrayList, AllElementsDeleter> pPersonList(new (std::nothrow) ArrayList());
+       unique_ptr<ArrayList, AllElementsDeleter> pPersonList(new (std::nothrow) ArrayList());
        SysTryReturn(NID_SCL, pPersonList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
        result r = pPersonList->Construct();
        SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-       std::unique_ptr<__SearchResult<__ContactsPerson> > pSearchResult(_AddressbookUtil::Search<__ContactsPerson>(keyword));
+       unique_ptr<__SearchResult<__ContactsPerson> > pSearchResult(_AddressbookUtil::Search<__ContactsPerson>(keyword));
        SysTryReturn(NID_SCL, pSearchResult != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
        while (pSearchResult->MoveNext() == E_SUCCESS)
@@ -1298,22 +1353,17 @@ _AddressbookManagerImpl::SetPersonAsFavorite(PersonId personId, bool isFavorite)
        SysTryReturn(NID_SCL, personId > 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. personId = %d.", GetErrorMessage(E_INVALID_ARG), personId);
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       bool boolValue = false;
-       contacts_record_h personHandle = null;
-       
-       int ret = contacts_db_get_record(_contacts_person._uri, personId, &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_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The person is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
-
-       __ContactsRecordHandle recordHandle(personHandle);
+       unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, personId));
+       SysTryReturn(NID_SCL, pPersonRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       contacts_record_get_bool(personHandle, _contacts_person.is_favorite, &boolValue);
+       bool boolValue = false;
+       contacts_record_get_bool(pPersonRecord.get(), _contacts_person.is_favorite, &boolValue);
 
        if (boolValue != isFavorite)
        {
-               contacts_record_set_bool(personHandle, _contacts_person.is_favorite, isFavorite);
+               contacts_record_set_bool(pPersonRecord.get(), _contacts_person.is_favorite, isFavorite);
 
-               ret = contacts_db_update_record(personHandle);
+               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));
        }
@@ -1373,12 +1423,21 @@ _AddressbookManagerImpl::SearchN(const AddressbookFilter& filter, unsigned long
        {
        case AB_FI_TYPE_ADDRESSBOOK:
                {
-                       __Filter<__ContactsAddressbook> filter;
-                       filter.Construct(filterHandle);
+                       unique_ptr< __Filter<__ContactsAddressbook> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsAddressbook>());
+
+                       __Filter<__ContactsAddressbook> abFilter;
+                       abFilter.Construct(filterHandle);
+
+                       __Filter<__ContactsAddressbook> mainFilter;
+                       mainFilter.Construct();
+
+                       mainFilter.AddFilter(*pRwAbFilter);
+                       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+                       mainFilter.AddFilter(abFilter);
 
                        __Query<__ContactsAddressbook> query;
                        query.Construct();
-                       query.SetFilter(filter);
+                       query.SetFilter(mainFilter);
 
                        if (viewSortPropertyId != 0)
                        {
@@ -1390,8 +1449,17 @@ _AddressbookManagerImpl::SearchN(const AddressbookFilter& filter, unsigned long
                break;
        case AB_FI_TYPE_PERSON:
                {
-                       __Filter<__ContactsPersonGroupRel> filter;
-                       filter.Construct(filterHandle);
+                       unique_ptr< __Filter<__ContactsPersonGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsPersonGroupRel>());
+
+                       __Filter<__ContactsPersonGroupRel> personFilter;
+                       personFilter.Construct(filterHandle);
+
+                       __Filter<__ContactsPersonGroupRel> mainFilter;
+                       mainFilter.Construct();
+
+                       mainFilter.AddFilter(*pRwAbFilter);
+                       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+                       mainFilter.AddFilter(personFilter);
 
                        unsigned int propertyIds[] =
                        { _contacts_person_grouprel.person_id,
@@ -1406,7 +1474,7 @@ _AddressbookManagerImpl::SearchN(const AddressbookFilter& filter, unsigned long
 
                        __Query<__ContactsPersonGroupRel> query;
                        query.Construct();
-                       query.SetFilter(filter);
+                       query.SetFilter(mainFilter);
                        query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
                        query.SetDistinct(true);
 
@@ -1420,12 +1488,21 @@ _AddressbookManagerImpl::SearchN(const AddressbookFilter& filter, unsigned long
                break;
        case AB_FI_TYPE_CONTACT:
                {
-                       __Filter<__ContactsContact> filter;
-                       filter.Construct(filterHandle);
+                       unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
+
+                       __Filter<__ContactsContact> contactFilter;
+                       contactFilter.Construct(filterHandle);
+
+                       __Filter<__ContactsContact> mainFilter;
+                       mainFilter.Construct();
+
+                       mainFilter.AddFilter(*pRwAbFilter);
+                       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+                       mainFilter.AddFilter(contactFilter);
 
                        __Query<__ContactsContact> query;
                        query.Construct();
-                       query.SetFilter(filter);
+                       query.SetFilter(mainFilter);
 
                        if (viewSortPropertyId != 0)
                        {
@@ -1437,12 +1514,21 @@ _AddressbookManagerImpl::SearchN(const AddressbookFilter& filter, unsigned long
                break;
        case AB_FI_TYPE_CATEGORY:
                {
-                       __Filter<__ContactsGroup> filter;
-                       filter.Construct(filterHandle);
+                       unique_ptr< __Filter<__ContactsGroup> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsGroup>());
+
+                       __Filter<__ContactsGroup> groupFilter;
+                       groupFilter.Construct(filterHandle);
+
+                       __Filter<__ContactsGroup> mainFilter;
+                       mainFilter.Construct();
+
+                       mainFilter.AddFilter(*pRwAbFilter);
+                       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+                       mainFilter.AddFilter(groupFilter);
 
                        __Query<__ContactsGroup> query;
                        query.Construct();
-                       query.SetFilter(filter);
+                       query.SetFilter(mainFilter);
 
                        if (viewSortPropertyId != 0)
                        {
@@ -1454,12 +1540,21 @@ _AddressbookManagerImpl::SearchN(const AddressbookFilter& filter, unsigned long
                break;
        case AB_FI_TYPE_PHONE_CONTACT:
                {
-                       __Filter<__ContactsContactNumber> filter;
-                       filter.Construct(filterHandle);
+                       unique_ptr< __Filter<__ContactsContactNumber> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactNumber>());
+
+                       __Filter<__ContactsContactNumber> numberFilter;
+                       numberFilter.Construct(filterHandle);
+
+                       __Filter<__ContactsContactNumber> mainFilter;
+                       mainFilter.Construct();
+
+                       mainFilter.AddFilter(*pRwAbFilter);
+                       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+                       mainFilter.AddFilter(numberFilter);
 
                        __Query<__ContactsContactNumber> query;
                        query.Construct();
-                       query.SetFilter(filter);
+                       query.SetFilter(mainFilter);
 
                        if (viewSortPropertyId != 0)
                        {
@@ -1471,12 +1566,21 @@ _AddressbookManagerImpl::SearchN(const AddressbookFilter& filter, unsigned long
                break;
        case AB_FI_TYPE_EMAIL_CONTACT:
                {
-                       __Filter<__ContactsContactEmail> filter;
-                       filter.Construct(filterHandle);
+                       unique_ptr< __Filter<__ContactsContactEmail> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactEmail>());
+
+                       __Filter<__ContactsContactEmail> emailFilter;
+                       emailFilter.Construct(filterHandle);
+
+                       __Filter<__ContactsContactEmail> mainFilter;
+                       mainFilter.Construct();
+
+                       mainFilter.AddFilter(*pRwAbFilter);
+                       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+                       mainFilter.AddFilter(emailFilter);
 
                        __Query<__ContactsContactEmail> query;
                        query.Construct();
-                       query.SetFilter(filter);
+                       query.SetFilter(mainFilter);
 
                        if (viewSortPropertyId != 0)
                        {
@@ -1508,18 +1612,39 @@ _AddressbookManagerImpl::GetMatchedItemCount(const AddressbookFilter& filter)
        switch(type)
        {
        case AB_FI_TYPE_ADDRESSBOOK:
-               count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsAddressbook>(filterHandle);
+               {
+                       unique_ptr< __Filter<__ContactsAddressbook> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsAddressbook>());
+
+                       __Filter<__ContactsAddressbook> abFilter;
+                       abFilter.Construct(filterHandle);
+
+                       __Filter<__ContactsAddressbook> mainFilter;
+                       mainFilter.Construct();
+                       mainFilter.AddFilter(*pRwAbFilter);
+                       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+                       mainFilter.AddFilter(abFilter);
+
+                       count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsAddressbook>(mainFilter.Get());
+               }
                break;
        case AB_FI_TYPE_PERSON:
                {
-                       __Filter<__ContactsPersonGroupRel> filter;
-                       filter.Construct(filterHandle);
+                       unique_ptr< __Filter<__ContactsPersonGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsPersonGroupRel>());
+
+                       __Filter<__ContactsPersonGroupRel> personFilter;
+                       personFilter.Construct(filterHandle);
+
+                       __Filter<__ContactsPersonGroupRel> mainFilter;
+                       mainFilter.Construct();
+                       mainFilter.AddFilter(*pRwAbFilter);
+                       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+                       mainFilter.AddFilter(personFilter);
 
                        unsigned int propertyIds[] = { _contacts_person_grouprel.person_id };
 
                        __Query<__ContactsPersonGroupRel> query;
                        query.Construct();
-                       query.SetFilter(filter);
+                       query.SetFilter(mainFilter);
                        query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
                        query.SetDistinct(true);
 
@@ -1528,16 +1653,68 @@ _AddressbookManagerImpl::GetMatchedItemCount(const AddressbookFilter& filter)
 
                break;
        case AB_FI_TYPE_CONTACT:
-               count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContact>(filterHandle);
+               {
+                       unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
+
+                       __Filter<__ContactsContact> contactFilter;
+                       contactFilter.Construct(filterHandle);
+
+                       __Filter<__ContactsContact> mainFilter;
+                       mainFilter.Construct();
+                       mainFilter.AddFilter(*pRwAbFilter);
+                       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+                       mainFilter.AddFilter(contactFilter);
+
+                       count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContact>(mainFilter.Get());
+               }
                break;
        case AB_FI_TYPE_CATEGORY:
-               count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsGroup>(filterHandle);
+               {
+                       unique_ptr< __Filter<__ContactsGroup> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsGroup>());
+
+                       __Filter<__ContactsGroup> groupFilter;
+                       groupFilter.Construct(filterHandle);
+
+                       __Filter<__ContactsGroup> mainFilter;
+                       mainFilter.Construct();
+                       mainFilter.AddFilter(*pRwAbFilter);
+                       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+                       mainFilter.AddFilter(groupFilter);
+
+                       count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsGroup>(mainFilter.Get());
+               }
                break;
        case AB_FI_TYPE_PHONE_CONTACT:
-               count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContactNumber>(filterHandle);
+               {
+                       unique_ptr< __Filter<__ContactsContactNumber> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactNumber>());
+
+                       __Filter<__ContactsContactNumber> numberFilter;
+                       numberFilter.Construct(filterHandle);
+
+                       __Filter<__ContactsContactNumber> mainFilter;
+                       mainFilter.Construct();
+                       mainFilter.AddFilter(*pRwAbFilter);
+                       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+                       mainFilter.AddFilter(numberFilter);
+
+                       count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContactNumber>(mainFilter.Get());
+               }
                break;
        case AB_FI_TYPE_EMAIL_CONTACT:
-               count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContactEmail>(filterHandle);
+               {
+                       unique_ptr< __Filter<__ContactsContactEmail> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactEmail>());
+
+                       __Filter<__ContactsContactEmail> emailFilter;
+                       emailFilter.Construct(filterHandle);
+
+                       __Filter<__ContactsContactEmail> mainFilter;
+                       mainFilter.Construct();
+                       mainFilter.AddFilter(*pRwAbFilter);
+                       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+                       mainFilter.AddFilter(emailFilter);
+
+                       count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContactEmail>(mainFilter.Get());
+               }
                break;
        default:
                SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. The type of the filter is invalid", GetErrorMessage(GetLastResult()));
@@ -1554,7 +1731,7 @@ _AddressbookManagerImpl::OnEachContact(contacts_record_h recordHandle, void* pUs
 
        ClearLastResult();
 
-       std::unique_ptr<Contact> pContact(new (std::nothrow) Contact());
+       unique_ptr<Contact> pContact(new (std::nothrow) Contact());
        SysTryReturn(NID_SCL, pContact != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
        contacts_record_h newRecordHandle = null;
@@ -1586,9 +1763,9 @@ _AddressbookManagerImpl::ParseContactsFromVcardN(const Tizen::Base::String& vcar
        SysTryReturn(NID_SCL, r != E_FILE_NOT_FOUND, null, E_FILE_NOT_FOUND, "[%s] The specified file does not exist.", GetErrorMessage(E_FILE_NOT_FOUND));
        SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
 
-       std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
+       unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
 
-       std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(vcardPath));
+       unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(vcardPath));
 
        int ret = contacts_vcard_parse_to_contact_foreach(pCharArray.get(), OnEachContact, pList.get());
        SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
@@ -1612,17 +1789,11 @@ _AddressbookManagerImpl::ExportPersonToVcard(const Person& person, const Tizen::
        SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
        SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
 
-       contacts_record_h personRecordHandle = null;
-
-       int ret = contacts_db_get_record(_contacts_person._uri, person.GetId(), &personRecordHandle);
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The specified person does not exist.", 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_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
-
-       __ContactsRecordHandle recordHandle(personRecordHandle);
+       unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, person.GetId()));
+       SysTryReturn(NID_SCL, pPersonRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
        char* pVcardStream = null;
-       ret = contacts_vcard_make_from_person(personRecordHandle, &pVcardStream);
+       int ret = contacts_vcard_make_from_person(pPersonRecord.get(), &pVcardStream);
        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));
 
@@ -1651,24 +1822,20 @@ _AddressbookManagerImpl::ExportPersonsToVcard(const Tizen::Base::Collection::ILi
        SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
        SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
 
-       contacts_record_h personRecordHandle = null;
-       __ContactsRecordHandle recordHandle(null);
 
-       std::unique_ptr<IEnumerator> pEnum(personList.GetEnumeratorN());
+       unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(null);
+
+       unique_ptr<IEnumerator> pEnum(personList.GetEnumeratorN());
        SysTryReturnResult(NID_SCL, pEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
        while (pEnum->MoveNext() == E_SUCCESS)
        {
                Person* pPerson = static_cast<Person*>(pEnum->GetCurrent());
 
-               ret = contacts_db_get_record(_contacts_person._uri, pPerson->GetId(), &personRecordHandle);
-               SysTryReturnResult(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, "The specified person does not exist.");
-               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));
-
-               recordHandle.Reset(personRecordHandle);
+               pPersonRecord.reset(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, pPerson->GetId()));
+               SysTryReturn(NID_SCL, pPersonRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-               ret = contacts_vcard_make_from_person(personRecordHandle, &pVcardStream);
+               ret = contacts_vcard_make_from_person(pPersonRecord.get(), &pVcardStream);
                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));
 
@@ -1731,7 +1898,7 @@ _AddressbookManagerImpl::ExportContactsToVcard(const Tizen::Base::Collection::IL
 
        contacts_record_h recordHandle = null;
 
-       std::unique_ptr<IEnumerator> pEnum(contactList.GetEnumeratorN());
+       unique_ptr<IEnumerator> pEnum(contactList.GetEnumeratorN());
        SysTryReturnResult(NID_SCL, pEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
        while (pEnum->MoveNext() == E_SUCCESS)
@@ -1770,7 +1937,7 @@ _AddressbookManagerImpl::ExportContactToVcardStreamN(const Contact& contact)
        SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
        SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-       std::unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
+       unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
        if (pByteBuffer == null)
        {
                free(pVcardStream);
@@ -1811,10 +1978,10 @@ _AddressbookManagerImpl::ExportContactsToVcardStreamN(const Tizen::Base::Collect
 
        contacts_record_h recordHandle = null;
 
-       std::unique_ptr<IEnumerator> pEnum(contactList.GetEnumeratorN());
+       unique_ptr<IEnumerator> pEnum(contactList.GetEnumeratorN());
        SysTryReturn(NID_SCL, pEnum != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-       std::unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
+       unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
        SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
        r = pByteBuffer->Construct(capacity);
@@ -1862,25 +2029,17 @@ _AddressbookManagerImpl::ExportPersonToVcardStreamN(const Person& person)
 
        ClearLastResult();
 
-       int ret = CONTACTS_ERROR_NONE;
-
-       contacts_record_h personRecordHandle = null;
-
-       ret =contacts_db_get_record(_contacts_person._uri, person.GetId(), &personRecordHandle);
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
-       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
-
-       __ContactsRecordHandle recordHandle(personRecordHandle);
+       unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, person.GetId()));
+       SysTryReturn(NID_SCL, GetLastResult() != E_OBJ_NOT_FOUND,  null, E_INVALID_ARG, "[%s] Person does not exist.", GetErrorMessage(E_INVALID_ARG));
+       SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS,  null, E_INVALID_ARG, "[%s] Person does not exist.", GetErrorMessage(E_INVALID_ARG));
 
        char* pVcardStream = null;
-
-       ret = contacts_vcard_make_from_person(personRecordHandle, &pVcardStream);
+       int ret = contacts_vcard_make_from_person(pPersonRecord.get(), &pVcardStream);
        SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
        SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
        SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
 
-       std::unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
+       unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
        if (pByteBuffer == null)
        {
                free(pVcardStream);
@@ -1918,13 +2077,12 @@ _AddressbookManagerImpl::ExportPersonsToVcardStreamN(const Tizen::Base::Collecti
 
        int capacity = 0;
 
-       contacts_record_h personRecordHandle = null;
-       __ContactsRecordHandle recordHandle(null);
+       unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(null);
 
-       std::unique_ptr<IEnumerator> pEnum(personList.GetEnumeratorN());
+       unique_ptr<IEnumerator> pEnum(personList.GetEnumeratorN());
        SysTryReturn(NID_SCL, pEnum != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-       std::unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
+       unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
        SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
        result r = pByteBuffer->Construct(capacity);
@@ -1939,14 +2097,11 @@ _AddressbookManagerImpl::ExportPersonsToVcardStreamN(const Tizen::Base::Collecti
        {
                pPerson = static_cast<Person*>(pEnum->GetCurrent());
 
-               ret = contacts_db_get_record(_contacts_person._uri, pPerson->GetId(), &personRecordHandle);
-               SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-               SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
-               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
-
-               recordHandle.Reset(personRecordHandle);
+               pPersonRecord.reset(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, pPerson->GetId()));
+               SysTryReturn(NID_SCL, GetLastResult() != E_OBJ_NOT_FOUND,  null, E_INVALID_ARG, "[%s] Person does not exist.", GetErrorMessage(E_INVALID_ARG));
+               SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS,  null, E_INVALID_ARG, "[%s] Person does not exist.", GetErrorMessage(E_INVALID_ARG));
 
-               ret = contacts_vcard_make_from_person(personRecordHandle, &pVcardStream);
+               ret = contacts_vcard_make_from_person(pPersonRecord.get(), &pVcardStream);
                SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
                SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, null, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
                SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
@@ -1988,7 +2143,7 @@ _AddressbookManagerImpl::ParseVcardStreamN(const Tizen::Base::ByteBuffer& vcardS
        contacts_record_h recordHandle = null;
        contacts_list_get_count(listHandle, &count);
 
-       std::unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
+       unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
        if (pList == null)
        {
                contacts_list_destroy(listHandle, true);
@@ -2008,7 +2163,7 @@ _AddressbookManagerImpl::ParseVcardStreamN(const Tizen::Base::ByteBuffer& vcardS
 
        for (unsigned int i = 0; i < count; i++)
        {
-               std::unique_ptr<Contact> pContact(new (std::nothrow) Contact());
+               unique_ptr<Contact> pContact(new (std::nothrow) Contact());
                if (pContact == null)
                {
                        contacts_list_destroy(listHandle, true);
@@ -2029,7 +2184,7 @@ _AddressbookManagerImpl::ParseVcardStreamN(const Tizen::Base::ByteBuffer& vcardS
                pContact.release();
        }
 
-       std::unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
+       unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
 
        while (pEnum->MoveNext() == E_SUCCESS)
        {
@@ -2064,7 +2219,7 @@ _AddressbookManagerImpl::ExportUserProfileToVcardStreamN(const UserProfile& user
        SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
        SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-       std::unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
+       unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
        if (pByteBuffer == null)
        {
                free(pVcardStream);
@@ -2104,10 +2259,10 @@ _AddressbookManagerImpl::ExportUserProfilesToVcardStreamN(const Tizen::Base::Col
        result r = E_SUCCESS;
        int capacity = 0;
 
-       std::unique_ptr<IEnumerator> pEnum(userProfileList.GetEnumeratorN());
+       unique_ptr<IEnumerator> pEnum(userProfileList.GetEnumeratorN());
        SysTryReturn(NID_SCL, pEnum != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-       std::unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
+       unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
        SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
        r = pByteBuffer->Construct(capacity);
@@ -2198,7 +2353,7 @@ _AddressbookManagerImpl::ExportUserProfilesToVcard(const Tizen::Base::Collection
        SysTryReturn(NID_SCL, r != E_STORAGE_FULL, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is full.", GetErrorMessage(E_STORAGE_FULL));
        SysTryReturn(NID_SCL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
 
-       std::unique_ptr<IEnumerator> pEnum(userProfileList.GetEnumeratorN());
+       unique_ptr<IEnumerator> pEnum(userProfileList.GetEnumeratorN());
        SysTryReturnResult(NID_SCL, pEnum != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
        while (pEnum->MoveNext() == E_SUCCESS)
@@ -2229,11 +2384,15 @@ _AddressbookManagerImpl::GetAllUserProfilesN(void) const
 
        ClearLastResult();
 
-       __Query<__ContactsUserProfile> query;
-       query.Construct();
-       query.SetSort(_contacts_my_profile.display_name, true);
+       unique_ptr< __Filter<__ContactsUserProfile> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsUserProfile>());
+       SysTryReturn(NID_SCL, pRwAbFilter != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       IList* pUserProfilesList = _AddressbookUtil::SearchWithQueryN<__ContactsUserProfile, UserProfile>(query);
+       __Query<__ContactsUserProfile> query2;
+       query2.Construct();
+       query2.SetFilter(*pRwAbFilter);
+       query2.SetSort(_contacts_my_profile.display_name, true);
+
+       IList* pUserProfilesList = _AddressbookUtil::SearchWithQueryN<__ContactsUserProfile, UserProfile>(query2);
        SysTryReturn(NID_SCL, pUserProfilesList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
        return pUserProfilesList;
@@ -2247,13 +2406,12 @@ _AddressbookManagerImpl::GetUserProfileN(AddressbookId addressbookId) const
 
        ClearLastResult();
 
-       contacts_record_h addressbookHandle = null;
-       int ret = contacts_db_get_record(_contacts_address_book._uri, addressbookId, &addressbookHandle);
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The addressbook %d is not found.", GetErrorMessage(E_OBJ_NOT_FOUND), addressbookId);
-       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred. Addressbook Id(%d)", GetErrorMessage(E_SYSTEM), addressbookId);
+       int mode = 0;
+       unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, addressbookId));
+       SysTryReturn(NID_SCL, pAbRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       contacts_record_destroy(addressbookHandle, true);
+       contacts_record_get_int(pAbRecord.get(), _contacts_address_book.mode, &mode);
+       SysTryReturn(NID_SCL, mode == 0, null, E_OBJ_NOT_FOUND, "[%s] The addressbook does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
 
        __Filter<__ContactsUserProfile> filter;
        filter.Construct();
@@ -2263,7 +2421,7 @@ _AddressbookManagerImpl::GetUserProfileN(AddressbookId addressbookId) const
        query.Construct();
        query.SetFilter(filter);
 
-       std::unique_ptr<IList, AllElementsDeleter> pUserProfilesList(_AddressbookUtil::SearchWithQueryN<__ContactsUserProfile, UserProfile>(query));
+       unique_ptr<IList, AllElementsDeleter> pUserProfilesList(_AddressbookUtil::SearchWithQueryN<__ContactsUserProfile, UserProfile>(query));
        SysTryReturn(NID_SCL, pUserProfilesList.get() != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
        SysTryReturn(NID_SCL, pUserProfilesList->GetCount() != 0, null, E_SUCCESS, "No UserProfile Set for this Addressbook.");
        SysTryReturn(NID_SCL, pUserProfilesList->GetCount() == 1, null, E_SYSTEM, "[%s] Propagating. More than one UserProfile not allowed.", GetErrorMessage(E_SYSTEM));
index 5f44972..b658f3e 100644 (file)
@@ -880,4 +880,39 @@ _AddressbookUtil::Search(const Tizen::Base::String& keyword)
        return pQueryResult;
 }
 
+IListT<AddressbookId>*
+_AddressbookUtil::GetRwAbIdListN(void)
+{
+       ClearLastResult();
+
+       __Filter<__ContactsAddressbook> filter;
+       filter.Construct();
+       filter.AddInt(_contacts_address_book.mode, CONTACTS_MATCH_EQUAL, 0);
+
+       __Query<__ContactsAddressbook> query;
+       query.Construct();
+       query.SetFilter(filter);
+
+       std::unique_ptr<IList, AllElementsDeleter> pAbList(SearchWithQueryN<__ContactsAddressbook, Addressbook>(query));
+       SysTryReturn(NID_SCL, pAbList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+       std::unique_ptr<IEnumerator> pEnum(pAbList->GetEnumeratorN());
+       SysTryReturn(NID_SCL, pEnum != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+       std::unique_ptr< ArrayListT<AddressbookId> > pAbIdList(new (std::nothrow) ArrayListT<AddressbookId>);
+       SysTryReturn(NID_SCL, pAbIdList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       result r = pAbIdList->Construct(pAbList->GetCount());
+       SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       while (pEnum->MoveNext() == E_SUCCESS)
+       {
+               Addressbook* pAddressbook = static_cast<Addressbook*>(pEnum->GetCurrent());
+
+               pAbIdList->Add(pAddressbook->GetId());
+       }
+
+       return pAbIdList.release();
+}
+
 }}  // Tizen::Social
index c5e738b..9e55282 100644 (file)
@@ -35,6 +35,17 @@ class Person;
 class Contact;
 class UserProfile;
 
+typedef __contacts_record_h ContactRecord;
+
+struct ContactRecordDeleter
+{
+       void operator()(ContactRecord* pRecord)
+       {
+               contacts_record_destroy(pRecord, true);
+       }
+};
+
+
 class __ContactsRecordHandle
 {
 public:
@@ -352,6 +363,11 @@ public:
        template<typename Type>
        static Type* ConvertResultTo(__SearchResult<__ContactsAddressbook>& searchResult);
 
+       static int GetAbPropertyId(void)
+       {
+               return _contacts_address_book.id;
+       }
+
 };
 
 class __ContactsPerson
@@ -393,6 +409,10 @@ public:
        template<typename Type>
        static Type* ConvertResultTo(__SearchResult<__ContactsPersonGroupRel>& searchResult);
 
+       static int GetAbPropertyId(void)
+       {
+               return _contacts_person_grouprel.address_book_id;
+       }
 };
 
 class __ContactsPersonNumber
@@ -415,6 +435,11 @@ public:
 
        template<typename Type>
        static Type* ConvertResultTo(__SearchResult<__ContactsGroup>& searchResult);
+
+       static int GetAbPropertyId(void)
+       {
+               return _contacts_group.address_book_id;
+       }
 };
 
 class __ContactsGroupRelation
@@ -439,6 +464,11 @@ public:
 
        template<typename Type>
        static Type* ConvertResultTo(__SearchResult<__ContactsContact>& searchResult);
+
+       static int GetAbPropertyId(void)
+       {
+               return _contacts_contact.address_book_id;
+       }
 };
 
 class __ContactsContactGroupRel
@@ -451,6 +481,11 @@ public:
 
        template<typename Type>
        static Type* ConvertResultTo(__SearchResult<__ContactsContactGroupRel>& searchResult);
+
+       static int GetAbPropertyId(void)
+       {
+               return _contacts_contact_grouprel.address_book_id;
+       }
 };
 
 class __ContactsContactEmail
@@ -463,6 +498,11 @@ public:
 
        template<typename Type>
        static Type* ConvertResultTo(__SearchResult<__ContactsContactEmail>& searchResult);
+
+       static int GetAbPropertyId(void)
+       {
+               return _contacts_contact_email.address_book_id;
+       }
 };
 
 class __ContactsContactNumber
@@ -475,6 +515,11 @@ public:
 
        template<typename Type>
        static Type* ConvertResultTo(__SearchResult<__ContactsContactNumber>& searchResult);
+
+       static int GetAbPropertyId(void)
+       {
+               return _contacts_contact_number.address_book_id;
+       }
 };
 
 class __ContactsContactUpdatedInfo
@@ -532,6 +577,11 @@ public:
 
        template<typename Type>
        static Type* ConvertResultTo(__SearchResult<__ContactsUserProfile>& searchResult);
+
+       static int GetAbPropertyId(void)
+       {
+               return _contacts_my_profile.address_book_id;
+       }
 };
 
 
@@ -641,7 +691,7 @@ public:
        static Person* CreatePersonN(void);
 
        template<typename __View, typename ChangeInfo>
-       static Tizen::Base::Collection::IList* SearchWithVersionN(int addressbookId, int currentVersion, int& latestVersion)
+       static Tizen::Base::Collection::IList* SearchWithVersionN(int addressbookId, int currentVersion, int& latestVersion, Tizen::Base::Collection::IListT<AddressbookId>* pRwAbIdList = null)
        {
                SysTryReturn(NID_SCL, currentVersion >= 0, null, E_INVALID_ARG, "[%s] currentVersion %d must be greater that or equal 0.", GetErrorMessage(GetLastResult()), currentVersion);
 
@@ -661,6 +711,11 @@ public:
                while (pSearchResult->MoveNext() == E_SUCCESS)
                {
                        pChangeInfo.reset(__View::template ConvertResultTo<ChangeInfo>(*pSearchResult));
+                       if (pRwAbIdList != null && !(pRwAbIdList->Contains(pChangeInfo->GetAddressbookId())))
+                       {
+                               continue;
+                       }
+
                        if (pChangeInfo == null)
                        {
                                SysTryReturn(NID_SCL, GetLastResult() != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
@@ -736,6 +791,78 @@ public:
 
                return count;
        }
+
+       static ContactRecord* CreateContactRecordN(const char* pUri)
+       {
+               ClearLastResult();
+
+               contacts_record_h recordHandle = null;
+
+               int ret = contacts_record_create(pUri, &recordHandle);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               return recordHandle;
+       }
+
+       static result InsertContactRecordN(contacts_record_h recordHandle, int& recordId)
+       {
+               int ret = contacts_db_insert_record(recordHandle, &recordId);
+               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));
+
+
+               return E_SUCCESS;
+       }
+
+
+       static ContactRecord* GetContactRecordN(const char* pUri, RecordId recordId)
+       {
+               ClearLastResult();
+
+               contacts_record_h recordHandle = null;
+               int ret = contacts_db_get_record(pUri, recordId, &recordHandle);
+               SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+               SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The record %d is not found.", GetErrorMessage(E_OBJ_NOT_FOUND), recordId);
+               SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred. Record Id(%d)", GetErrorMessage(E_SYSTEM), recordId);
+
+               return recordHandle;
+       }
+
+       static Tizen::Base::Collection::IListT<AddressbookId>* GetRwAbIdListN(void);
+
+       template<typename __View>
+       static __Filter<__View>* GetRwAbFilterN(void)
+       {
+               std::unique_ptr< Tizen::Base::Collection::IListT<AddressbookId> > pAbIdList(GetRwAbIdListN());
+               SysTryReturn(NID_SCL, pAbIdList != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               std::unique_ptr< __Filter<__View> > pFilter(new (std::nothrow) __Filter<__View>);
+               SysTryReturn(NID_SCL, pFilter != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               pFilter->Construct();
+
+               bool isFirst = true;
+               AddressbookId addressbookId = -1;
+
+               std::unique_ptr< Tizen::Base::Collection::IEnumeratorT<AddressbookId> > pEnum(pAbIdList->GetEnumeratorN());
+               while (pEnum->MoveNext() == E_SUCCESS)
+               {
+                       pEnum->GetCurrent(addressbookId);
+                       if (!isFirst)
+                       {
+                               pFilter->AddOperator(CONTACTS_FILTER_OPERATOR_OR);
+                       }
+                       else
+                       {
+                               isFirst = false;
+                       }
+
+                       pFilter->AddInt(__View::GetAbPropertyId(), CONTACTS_MATCH_EQUAL, addressbookId);
+               }
+
+               return pFilter.release();
+       }
 };
 
 }} // Tizen::Social