Removed contacts_db_delete_record and added DeleteContactRecord in AddressbookUtil...
[framework/osp/social.git] / src / FScl_AddressbookManagerImpl.cpp
index 40ca6e1..3698b66 100644 (file)
@@ -1,5 +1,4 @@
 //
-// Open Service Platform
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the License);
@@ -63,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;
@@ -200,12 +200,12 @@ _AddressbookManagerImpl::CreateAddressbookN(AccountId accountId, const String& n
        SysTryReturn(NID_SCL, accountId >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. account id is invalid.", GetErrorMessage(E_INVALID_ARG));
        SysTryReturn(NID_SCL, !name.IsEmpty(), null, E_INVALID_ARG, "[%s] Invalid argument is used. The name is empty.", GetErrorMessage(E_INVALID_ARG));
 
+       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;
@@ -224,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));
-
-       __ContactsRecordHandle recordHandle(addressbookHandle);
+       unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::CreateContactRecordN(_contacts_address_book._uri));
+       SysTryReturn(NID_SCL, pAbRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       contacts_record_set_str(addressbookHandle, _contacts_address_book.name, pNameString.get());
-       contacts_record_set_int(addressbookHandle, _contacts_address_book.account_id, accountId);
+       contacts_record_set_str(pAbRecord.get(), _contacts_address_book.name, pNameString.get());
+       contacts_record_set_int(pAbRecord.get(), _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);
@@ -254,13 +249,10 @@ _AddressbookManagerImpl::CreateAddressbookN(AccountId accountId, const String& n
 result
 _AddressbookManagerImpl::DeleteAddressbook(AddressbookId addressbookId)
 {
-       SysTryReturn(NID_SCL, addressbookId > 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The addressbook ID is invalid or the default addressbook ID.", GetErrorMessage(E_INVALID_ARG));
+       SysTryReturn(NID_SCL, addressbookId > 0, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument used.The addressbook ID is invalid or the default addressbook ID.", GetErrorMessage(E_INVALID_ARG));
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
-
-       int ret = contacts_db_delete_record(_contacts_address_book._uri, addressbookId);
-       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));
-//     SysTryReturnResult(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OPERATION_FAILED, "Failed to delete an addressbook.(%d)", ret); // temp
+       result r = _AddressbookUtil::DeleteContactRecord(_contacts_address_book._uri, addressbookId);
+       SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
 
        return E_SUCCESS;
 }
@@ -268,19 +260,43 @@ _AddressbookManagerImpl::DeleteAddressbook(AddressbookId addressbookId)
 IList*
 _AddressbookManagerImpl::GetAddressbooksByAccountN(AccountId accountId) const
 {
-       SysTryReturn(NID_SCL, accountId >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. accountId = %d.", GetErrorMessage(E_INVALID_ARG), accountId);
+       SysTryReturn(NID_SCL, accountId >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. account id is invalid.", GetErrorMessage(E_INVALID_ARG));
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       __Filter<__ContactsAddressbook> filter;
-       filter.Construct();
-       filter.AddInt(_contacts_address_book.account_id, CONTACTS_MATCH_EQUAL, accountId);
+       ClearLastResult();
 
-       __Query<__ContactsAddressbook> query;
-       query.Construct();
-       query.SetFilter(filter);
+       IList* pAddressbooks = null;
 
-       IList* pAddressbooks = _AddressbookUtil::SearchWithQueryN<__ContactsAddressbook, Addressbook>(query);
-       SysTryReturn(NID_SCL, pAddressbooks != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+       __Filter<__ContactsAddressbook> accountFilter;
+       accountFilter.Construct();
+       accountFilter.AddInt(_contacts_address_book.account_id, CONTACTS_MATCH_EQUAL, accountId);
+
+       unique_ptr< __Filter<__ContactsAddressbook> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsAddressbook>());
+       if (pRwAbFilter->Get() == null)
+       {
+               __Query<__ContactsAddressbook> query;
+               query.Construct();
+               query.SetFilter(accountFilter);
+
+               pAddressbooks = _AddressbookUtil::SearchWithQueryN<__ContactsAddressbook, Addressbook>(query);
+               SysTryReturn(NID_SCL, pAddressbooks != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+       }
+       else
+       {
+               __Filter<__ContactsAddressbook> mainFilter;
+               mainFilter.Construct();
+
+               mainFilter.AddFilter(*pRwAbFilter);
+               mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+               mainFilter.AddFilter(accountFilter);
+
+               __Query<__ContactsAddressbook> query;
+               query.Construct();
+               query.SetFilter(mainFilter);
+
+               pAddressbooks = _AddressbookUtil::SearchWithQueryN<__ContactsAddressbook, Addressbook>(query);
+               SysTryReturn(NID_SCL, pAddressbooks != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+       }
 
        return pAddressbooks;
 }
@@ -290,8 +306,15 @@ _AddressbookManagerImpl::GetAllAddressbooksN(void) const
 {
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
+       ClearLastResult();
+
+       __Filter<__ContactsAddressbook> abFilter;
+       abFilter.Construct();
+       abFilter.AddInt(_contacts_address_book.mode, CONTACTS_MATCH_EQUAL, 0);
+
        __Query<__ContactsAddressbook> query;
        query.Construct();
+       query.SetFilter(abFilter);
        query.SetSort(_contacts_address_book.name, true);
 
        IList* pAddressbooks = _AddressbookUtil::SearchWithQueryN<__ContactsAddressbook, Addressbook>(query);
@@ -306,34 +329,32 @@ _AddressbookManagerImpl::GetAddressbookN(AddressbookId addressbookId) const
        SysTryReturn(NID_SCL, addressbookId >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. addressbookId.", GetErrorMessage(E_INVALID_ARG), addressbookId);
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
+       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();
 }
 
@@ -350,36 +371,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()));
 
+       unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, addressbookId));
+       SysTryReturn(NID_SCL, pAbRecord != null, 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);
-
-       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
@@ -388,31 +400,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)
                {
@@ -426,7 +437,6 @@ _AddressbookManagerImpl::AddCategory(Category& category, AddressbookId addressbo
        }
 
        return E_SUCCESS;
-
 }
 
 result
@@ -435,20 +445,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));
@@ -462,25 +466,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
@@ -496,32 +493,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;
 }
@@ -534,37 +523,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;
+       unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, category.GetRecordId()));
+       SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       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);
-
-       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);
@@ -579,7 +561,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);
@@ -591,13 +573,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()));
@@ -613,7 +593,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()));
@@ -633,10 +612,17 @@ _AddressbookManagerImpl::GetAllCategoriesN(void) const
 
        ClearLastResult();
 
+       unique_ptr< __Filter<__ContactsGroup> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsGroup>());
+
        __Query<__ContactsGroup> query;
        query.Construct();
        query.SetSort(_contacts_group.name, true);
 
+       if (pRwAbFilter->Get() != null)
+       {
+               query.SetFilter(*pRwAbFilter);
+       }
+
        IList* pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsGroup, Category>(query);
        SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
@@ -650,17 +636,38 @@ _AddressbookManagerImpl::GetCategoriesByContactN(RecordId contactId) const
        SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. The specified contact is invalid.", GetErrorMessage(E_INVALID_ARG));
 
        ClearLastResult();
+       IList* pCategories = null;
+       
+       unique_ptr< __Filter<__ContactsContactGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactGroupRel>());
 
-       __Filter<__ContactsGroupRelation> filter;
-       filter.Construct();
-       filter.AddInt(_contacts_group_relation.contact_id, CONTACTS_MATCH_EQUAL, contactId);
+       __Filter<__ContactsContactGroupRel> relFilter;
+       relFilter.Construct();
+       relFilter.AddInt(_contacts_contact_grouprel.contact_id, CONTACTS_MATCH_EQUAL, contactId);
 
-       __Query<__ContactsGroupRelation> query;
-       query.Construct();
-       query.SetFilter(filter);
+       if (pRwAbFilter->Get() != null)
+       {
+               __Filter<__ContactsContactGroupRel> mainFilter;
+               mainFilter.Construct();
+               mainFilter.AddFilter(*pRwAbFilter);
+               mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+               mainFilter.AddFilter(relFilter);
+
+               __Query<__ContactsContactGroupRel> query;
+               query.Construct();
+               query.SetFilter(mainFilter);
+
+               pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Category>(query);
+               SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+       }
+       else
+       {
+               __Query<__ContactsContactGroupRel> query;
+               query.Construct();
+               query.SetFilter(relFilter);
 
-       IList* pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsGroupRelation, Category>(query);
-       SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+               pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Category>(query);
+               SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+       }
 
        return pCategories;
 }
@@ -672,26 +679,54 @@ _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);
+       IList* pCategories = null;
+
+       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);
 
        unsigned int propertyIds[] =
        {
                _contacts_contact_grouprel.group_id,
        };
 
-       __Query<__ContactsContactGroupRel> query;
-       query.Construct();
-       query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
-       query.SetFilter(filter);
-       query.SetSort(_contacts_contact_grouprel.group_name, true);
-       query.SetDistinct(true);
+       if (pRwAbFilter->Get() != null)
+       {
 
-       IList* pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Category>(query);
-       SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+               __Filter<__ContactsContactGroupRel> mainFilter;
+               mainFilter.Construct();
+               mainFilter.AddFilter(*pRwAbFilter);
+               mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+               mainFilter.AddFilter(relFilter);
+
+
+               __Query<__ContactsContactGroupRel> query;
+               query.Construct();
+               query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
+               query.SetFilter(mainFilter);
+               query.SetSort(_contacts_contact_grouprel.group_name, true);
+               query.SetDistinct(true);
+
+               pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Category>(query);
+               SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+       }
+       else
+       {
+               __Query<__ContactsContactGroupRel> query;
+               query.Construct();
+               query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
+               query.SetFilter(relFilter);
+               query.SetSort(_contacts_contact_grouprel.group_name, true);
+               query.SetDistinct(true);
+
+               pCategories = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Category>(query);
+               SysTryReturn(NID_SCL, pCategories != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+       }
 
        return pCategories;
 }
@@ -703,10 +738,17 @@ _AddressbookManagerImpl::GetAllContactsN(void) const
 
        ClearLastResult();
 
+       unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
+
        __Query<__ContactsContact> query;
        query.Construct();
        query.SetSort(_contacts_contact.display_name, true);
 
+       if (pRwAbFilter->Get() != null)
+       {
+               query.SetFilter(*pRwAbFilter);
+       }
+
        IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
        SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
@@ -721,25 +763,47 @@ _AddressbookManagerImpl::GetContactsByCategoryN(RecordId categoryId) const
 
        ClearLastResult();
 
-       __Filter<__ContactsContactGroupRel> filter;
-       filter.Construct();
+       IList* pContacts = null;
+
+       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);
        }
 
-       __Query<__ContactsContactGroupRel> query;
-       query.Construct();
-       query.SetFilter(filter);
+       if (pRwAbFilter->Get() != null)
+       {
+               __Filter<__ContactsContactGroupRel> mainFilter;
+               mainFilter.Construct();
 
+               mainFilter.AddFilter(*pRwAbFilter);
+               mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+               mainFilter.AddFilter(relFilter);
 
-       IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Contact>(query);
-       SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+               __Query<__ContactsContactGroupRel> query;
+               query.Construct();
+               query.SetFilter(mainFilter);
+
+               pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Contact>(query);
+               SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+       }
+       else
+       {
+               __Query<__ContactsContactGroupRel> query;
+               query.Construct();
+               query.SetFilter(relFilter);
+
+               pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactGroupRel, Contact>(query);
+               SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+       }
 
        return pContacts;
 }
@@ -750,18 +814,42 @@ _AddressbookManagerImpl::GetContactsByPersonN(PersonId personId) const
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
        ClearLastResult();
+       
+       IList* pContacts = null;
 
-       __Filter<__ContactsContact> filter;
-       filter.Construct();
-       filter.AddInt(_contacts_contact.person_id, CONTACTS_MATCH_EQUAL, personId);
+       unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
 
-       __Query<__ContactsContact> query;
-       query.Construct();
-       query.SetFilter(filter);
-       query.SetSort(_contacts_contact.display_name, true);
+       __Filter<__ContactsContact> contactFilter;
+       contactFilter.Construct();
+       contactFilter.AddInt(_contacts_contact.person_id, CONTACTS_MATCH_EQUAL, personId);
 
-       IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
-       SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+       if (pRwAbFilter->Get() != null)
+       {
+               __Filter<__ContactsContact> mainFilter;
+               mainFilter.Construct();
+
+               mainFilter.AddFilter(*pRwAbFilter);
+               mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+               mainFilter.AddFilter(contactFilter);
+
+               __Query<__ContactsContact> query;
+               query.Construct();
+               query.SetFilter(mainFilter);
+               query.SetSort(_contacts_contact.display_name, true);
+
+               pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
+               SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+       }
+       else
+       {
+               __Query<__ContactsContact> query;
+               query.Construct();
+               query.SetFilter(contactFilter);
+               query.SetSort(_contacts_contact.display_name, true);
+
+               pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
+               SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+       }
 
        return pContacts;
 }
@@ -774,23 +862,47 @@ _AddressbookManagerImpl::SearchContactsByEmailN(const String& email) const
 
        ClearLastResult();
 
-       std::unique_ptr<char[]> pCharArray(_StringConverter::CopyToCharArrayN(email));
+       IList* pContacts = null;
+
+       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());
 
-       __Query<__ContactsContactEmail> query;
-       query.Construct();
-       query.SetFilter(filter);
-       query.SetSort(_contacts_contact_email.display_name, true);
+       if (pRwAbFilter->Get() != null)
+       {
+               __Filter<__ContactsContactEmail> mainFilter;
+               mainFilter.Construct();
 
-       IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, Contact>(query);
-       SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+               mainFilter.AddFilter(*pRwAbFilter);
+               mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+               mainFilter.AddFilter(emailFilter);
 
-       return pContacts;
+               __Query<__ContactsContactEmail> query;
+               query.Construct();
+               query.SetFilter(mainFilter);
+               query.SetSort(_contacts_contact_email.display_name, true);
 
+               pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, Contact>(query);
+               SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+       }
+       else
+       {
+               __Query<__ContactsContactEmail> query;
+               query.Construct();
+               query.SetFilter(emailFilter);
+               query.SetSort(_contacts_contact_email.display_name, true);
+
+               pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, Contact>(query);
+               SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+       }
+
+       return pContacts;
 }
 
 IList*
@@ -800,22 +912,46 @@ _AddressbookManagerImpl::SearchContactsByNameN(const String& name) const
 
        ClearLastResult();
 
+       IList* pContacts = null;
+
+       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());
 
-       __Query<__ContactsContact> query;
-       query.Construct();
-       query.SetFilter(filter);
-       query.SetSort(_contacts_contact.display_name, true);
+       if (pRwAbFilter->Get() != null)
+       {
+               __Filter<__ContactsContact> mainFilter;
+               mainFilter.Construct();
 
-       IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
-       SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+               mainFilter.AddFilter(*pRwAbFilter);
+               mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+               mainFilter.AddFilter(nameFilter);
+
+               __Query<__ContactsContact> query;
+               query.Construct();
+               query.SetFilter(mainFilter);
+               query.SetSort(_contacts_contact.display_name, true);
+
+               pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
+               SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+       }
+       else
+       {
+               __Query<__ContactsContact> query;
+               query.Construct();
+               query.SetFilter(nameFilter);
+               query.SetSort(_contacts_contact.display_name, true);
+
+               pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
+               SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+       }
 
        return pContacts;
 }
@@ -827,23 +963,49 @@ _AddressbookManagerImpl::SearchContactsByPhoneNumberN(const String& phoneNumber)
 
        ClearLastResult();
 
+       IList* pContacts = null;
+
        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());
 
-       __Query<__ContactsContactNumber> query;
-       query.Construct();
-       query.SetFilter(filter);
-       query.SetDistinct(true);
-       query.SetSort(_contacts_contact_number.display_name, true);
+       if (pRwAbFilter->Get() != null)
+       {
+               __Filter<__ContactsContactNumber> mainFilter;
+               mainFilter.Construct();
 
-       IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, Contact>(query);
-       SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+               mainFilter.AddFilter(*pRwAbFilter);
+               mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+               mainFilter.AddFilter(numberFilter);
+
+               __Query<__ContactsContactNumber> query;
+               query.Construct();
+               query.SetFilter(mainFilter);
+               query.SetDistinct(true);
+               query.SetSort(_contacts_contact_number.display_name, true);
+
+               pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, Contact>(query);
+               SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+       }
+       else
+       {
+               __Query<__ContactsContactNumber> query;
+               query.Construct();
+               query.SetFilter(numberFilter);
+               query.SetDistinct(true);
+               query.SetSort(_contacts_contact_number.display_name, true);
+
+               pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, Contact>(query);
+               SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+       }
+       
 
        return pContacts;
 }
@@ -853,11 +1015,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;
@@ -868,11 +1030,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;
@@ -882,25 +1044,29 @@ Contact*
 _AddressbookManagerImpl::GetContactN(RecordId contactId) const
 {
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
-
        SysTryReturn(NID_SCL, contactId != INVALID_RECORD_ID, null, E_INVALID_ARG, "[%s] Invalid argument is used. contactId = %d.", GetErrorMessage(E_INVALID_ARG), contactId);
 
-       int intValue = 0;
-       contacts_record_h contactHandle = null;
+       ClearLastResult();
 
-       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));
+       unique_ptr<ContactRecord, ContactRecordDeleter> pContactRecord(_AddressbookUtil::GetContactRecordN(_contacts_contact._uri, contactId));
+       SysTryReturn(NID_SCL, pContactRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       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));
+       int intValue = 0;
+       contacts_record_get_int(pContactRecord.get(), _contacts_contact.address_book_id, &intValue);
 
-       _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(contactHandle);
+       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(contactHandle, _contacts_contact.id, &intValue);
+       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(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();
@@ -910,23 +1076,17 @@ Person*
 _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;
-
-       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));
+       ClearLastResult();
 
-       __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;
@@ -938,24 +1098,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);
@@ -967,7 +1130,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);
 
@@ -995,8 +1158,11 @@ _AddressbookManagerImpl::GetChangedContactsAfterN(int version, int& latestVersio
        SysTryReturn(NID_SCL, version >= 0, null, E_INVALID_ARG, "[%s] Invalid arguent is used. version %d must be greater that or equal 0.", GetErrorMessage(E_INVALID_ARG), version);
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
+       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;
@@ -1013,13 +1179,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);
@@ -1034,7 +1202,6 @@ _AddressbookManagerImpl::GetChangedCategoriesAfterN(int version, int& latestVers
        latestVersion = latestVersion2 > latestVersion1 ? latestVersion2 : latestVersion1;
        
        return pChangeList.release();
-
 }
 
 IList*
@@ -1045,7 +1212,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;
@@ -1059,7 +1228,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;
@@ -1148,16 +1319,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;
+       unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, personId));
+       SysTryReturn(NID_SCL, pPersonRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       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);
-
-       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));
@@ -1172,11 +1337,33 @@ _AddressbookManagerImpl::GetAllPersonsN(void) const
 
        ClearLastResult();
 
-       __Query<__ContactsPerson> query;
+       unique_ptr< __Filter<__ContactsPersonGroupRel> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsPersonGroupRel>());
+
+       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.SetSort(_contacts_person.display_name, true);
+       query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
+       query.SetDistinct(true);
 
-       IList* pPersons = _AddressbookUtil::SearchWithQueryN<__ContactsPerson, Person>(query);
+       if (pRwAbFilter->Get() != null)
+       {
+               query.SetFilter(*pRwAbFilter);
+       }
+
+       IList* pPersons = _AddressbookUtil::SearchWithQueryN<__ContactsPersonGroupRel, Person>(query);
        SysTryReturn(NID_SCL, pPersons != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
        return pPersons;
@@ -1190,15 +1377,19 @@ _AddressbookManagerImpl::GetPersonsByCategoryN(RecordId categoryId) const
 
        ClearLastResult();
 
-       __Filter<__ContactsPersonGroupRel> filter;
-       filter.Construct();
+       IList* pPersons = null;
+
+       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[] =
@@ -1210,18 +1401,41 @@ _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,
        };
 
-       __Query<__ContactsPersonGroupRel> query;
-       query.Construct();
-       query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
-       query.SetFilter(filter);
-       query.SetSort(_contacts_person_grouprel.display_name, true);
-       query.SetDistinct(true);
+       if (pRwAbFilter->Get() != null)
+       {
+               __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(mainFilter);
+               query.SetSort(_contacts_person_grouprel.display_name, true);
+               query.SetDistinct(true);
+
+               pPersons = _AddressbookUtil::SearchWithQueryN<__ContactsPersonGroupRel, Person>(query);
+               SysTryReturn(NID_SCL, pPersons != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+       }
+       else
+       {
+               __Query<__ContactsPersonGroupRel> query;
+               query.Construct();
+               query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
+               query.SetFilter(groupFilter);
+               query.SetSort(_contacts_person_grouprel.display_name, true);
+               query.SetDistinct(true);
 
-       IList* pPersons = _AddressbookUtil::SearchWithQueryN<__ContactsPersonGroupRel, Person>(query);
-       SysTryReturn(NID_SCL, pPersons != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+               pPersons = _AddressbookUtil::SearchWithQueryN<__ContactsPersonGroupRel, Person>(query);
+               SysTryReturn(NID_SCL, pPersons != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+       }
 
        return pPersons;
 }
@@ -1252,17 +1466,20 @@ IList*
 _AddressbookManagerImpl::SearchPersonsN(const Tizen::Base::String& keyword) const
 {
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+       SysTryReturn(NID_SCL, !keyword.IsEmpty(), null, E_INVALID_ARG, "Invalid argument is used. keyword is empty string.", GetErrorMessage(E_INVALID_ARG));
+
+       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)
@@ -1288,22 +1505,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));
+       unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, personId));
+       SysTryReturn(NID_SCL, pPersonRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       __ContactsRecordHandle recordHandle(personHandle);
-
-       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));
        }
@@ -1342,6 +1554,8 @@ _AddressbookManagerImpl::SearchN(const AddressbookFilter& filter, unsigned long
 {
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
+       ClearLastResult();
+
        IList* pList = null;
        bool ascending = false;
        unsigned int viewSortPropertyId = 0;
@@ -1361,25 +1575,55 @@ _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>());
 
-                       __Query<__ContactsAddressbook> query;
-                       query.Construct();
-                       query.SetFilter(filter);
+                       __Filter<__ContactsAddressbook> abFilter;
+                       abFilter.Construct(filterHandle);
 
-                       if (viewSortPropertyId != 0)
+                       if (pRwAbFilter->Get() != null)
                        {
-                               query.SetSort(viewSortPropertyId, ascending);
+                               __Filter<__ContactsAddressbook> mainFilter;
+                               mainFilter.Construct();
+                               mainFilter.AddFilter(*pRwAbFilter);
+                               if (abFilter.Get() != null)
+                               {
+                                       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+                                       mainFilter.AddFilter(abFilter);
+                               }
+
+                               __Query<__ContactsAddressbook> query;
+                               query.Construct();
+                               query.SetFilter(mainFilter);
+
+                               if (viewSortPropertyId != 0)
+                               {
+                                       query.SetSort(viewSortPropertyId, ascending);
+                               }
+
+                               pList = _AddressbookUtil::SearchWithQueryN<__ContactsAddressbook, Addressbook>(query, offset, maxCount);
                        }
+                       else
+                       {
+                               __Query<__ContactsAddressbook> query;
+                               query.Construct();
+                               query.SetFilter(abFilter);
+
+                               if (viewSortPropertyId != 0)
+                               {
+                                       query.SetSort(viewSortPropertyId, ascending);
+                               }
 
-                       pList = _AddressbookUtil::SearchWithQueryN<__ContactsAddressbook, Addressbook>(query, offset, maxCount);
+                               pList = _AddressbookUtil::SearchWithQueryN<__ContactsAddressbook, Addressbook>(query, offset, maxCount);
+
+                       }
                }
                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);
 
                        unsigned int propertyIds[] =
                        { _contacts_person_grouprel.person_id,
@@ -1392,86 +1636,222 @@ _AddressbookManagerImpl::SearchN(const AddressbookFilter& filter, unsigned long
                                _contacts_person_grouprel.display_name
                        };
 
-                       __Query<__ContactsPersonGroupRel> query;
-                       query.Construct();
-                       query.SetFilter(filter);
-                       query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
-                       query.SetDistinct(true);
-
-                       if (viewSortPropertyId != 0)
+                       if (pRwAbFilter->Get() != null)
                        {
-                               query.SetSort(viewSortPropertyId, ascending);
+                               __Filter<__ContactsPersonGroupRel> mainFilter;
+                               mainFilter.Construct();
+                               mainFilter.AddFilter(*pRwAbFilter);
+                               if (personFilter.Get() != null)
+                               {
+                                       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+                                       mainFilter.AddFilter(personFilter);
+                               }
+
+                               __Query<__ContactsPersonGroupRel> query;
+                               query.Construct();
+                               query.SetFilter(mainFilter);
+                               query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
+                               query.SetDistinct(true);
+
+                               if (viewSortPropertyId != 0)
+                               {
+                                       query.SetSort(viewSortPropertyId, ascending);
+                               }
+
+                               pList = _AddressbookUtil::SearchWithQueryN<__ContactsPersonGroupRel, Person>(query, offset, maxCount);
+                       }
+                       else
+                       {
+                               __Query<__ContactsPersonGroupRel> query;
+                               query.Construct();
+                               query.SetFilter(personFilter);
+                               query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
+                               query.SetDistinct(true);
+
+                               if (viewSortPropertyId != 0)
+                               {
+                                       query.SetSort(viewSortPropertyId, ascending);
+                               }
+
+                               pList = _AddressbookUtil::SearchWithQueryN<__ContactsPersonGroupRel, Person>(query, offset, maxCount);
                        }
-
-                       pList = _AddressbookUtil::SearchWithQueryN<__ContactsPersonGroupRel, Person>(query, offset, maxCount);
                }
                break;
        case AB_FI_TYPE_CONTACT:
                {
-                       __Filter<__ContactsContact> filter;
-                       filter.Construct(filterHandle);
+                       unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
 
-                       __Query<__ContactsContact> query;
-                       query.Construct();
-                       query.SetFilter(filter);
+                       __Filter<__ContactsContact> contactFilter;
+                       contactFilter.Construct(filterHandle);
 
-                       if (viewSortPropertyId != 0)
+                       if (pRwAbFilter->Get() != null)
                        {
-                               query.SetSort(viewSortPropertyId, ascending);
+                               __Filter<__ContactsContact> mainFilter;
+                               mainFilter.Construct();
+                               mainFilter.AddFilter(*pRwAbFilter);
+                               if (contactFilter.Get() != null)
+                               {
+                                       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+                                       mainFilter.AddFilter(contactFilter);
+                               }
+
+                               __Query<__ContactsContact> query;
+                               query.Construct();
+                               query.SetFilter(mainFilter);
+
+                               if (viewSortPropertyId != 0)
+                               {
+                                       query.SetSort(viewSortPropertyId, ascending);
+                               }
+
+                               pList = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query, offset, maxCount);
                        }
+                       else
+                       {
+                               __Query<__ContactsContact> query;
+                               query.Construct();
+                               query.SetFilter(contactFilter);
+
+                               if (viewSortPropertyId != 0)
+                               {
+                                       query.SetSort(viewSortPropertyId, ascending);
+                               }
 
-                       pList = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query, offset, maxCount);
+                               pList = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query, offset, maxCount);
+
+                       }
                }
                break;
        case AB_FI_TYPE_CATEGORY:
                {
-                       __Filter<__ContactsGroup> filter;
-                       filter.Construct(filterHandle);
+                       unique_ptr< __Filter<__ContactsGroup> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsGroup>());
 
-                       __Query<__ContactsGroup> query;
-                       query.Construct();
-                       query.SetFilter(filter);
+                       __Filter<__ContactsGroup> groupFilter;
+                       groupFilter.Construct(filterHandle);
 
-                       if (viewSortPropertyId != 0)
+                       if (pRwAbFilter->Get() != null)
                        {
-                               query.SetSort(viewSortPropertyId, ascending);
+                               __Filter<__ContactsGroup> mainFilter;
+                               mainFilter.Construct();
+                               mainFilter.AddFilter(*pRwAbFilter);
+                               if (groupFilter.Get() != null)
+                               {
+                                       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+                                       mainFilter.AddFilter(groupFilter);
+                               }
+
+                               __Query<__ContactsGroup> query;
+                               query.Construct();
+                               query.SetFilter(mainFilter);
+
+                               if (viewSortPropertyId != 0)
+                               {
+                                       query.SetSort(viewSortPropertyId, ascending);
+                               }
+
+                               pList = _AddressbookUtil::SearchWithQueryN<__ContactsGroup, Category>(query, offset, maxCount);
                        }
+                       else
+                       {
+                               __Query<__ContactsGroup> query;
+                               query.Construct();
+                               query.SetFilter(groupFilter);
+
+                               if (viewSortPropertyId != 0)
+                               {
+                                       query.SetSort(viewSortPropertyId, ascending);
+                               }
 
-                       pList = _AddressbookUtil::SearchWithQueryN<__ContactsGroup, Category>(query, offset, maxCount);
+                               pList = _AddressbookUtil::SearchWithQueryN<__ContactsGroup, Category>(query, offset, maxCount);
+                       }
                }
                break;
        case AB_FI_TYPE_PHONE_CONTACT:
                {
-                       __Filter<__ContactsContactNumber> filter;
-                       filter.Construct(filterHandle);
+                       unique_ptr< __Filter<__ContactsContactNumber> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactNumber>());
 
-                       __Query<__ContactsContactNumber> query;
-                       query.Construct();
-                       query.SetFilter(filter);
+                       __Filter<__ContactsContactNumber> numberFilter;
+                       numberFilter.Construct(filterHandle);
 
-                       if (viewSortPropertyId != 0)
+                       if (pRwAbFilter->Get() != null)
                        {
-                               query.SetSort(viewSortPropertyId, ascending);
+                               __Filter<__ContactsContactNumber> mainFilter;
+                               mainFilter.Construct();
+                               mainFilter.AddFilter(*pRwAbFilter);
+                               if (numberFilter.Get() != null)
+                               {
+                                       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+                                       mainFilter.AddFilter(numberFilter);
+                               }
+
+                               __Query<__ContactsContactNumber> query;
+                               query.Construct();
+                               query.SetFilter(mainFilter);
+
+                               if (viewSortPropertyId != 0)
+                               {
+                                       query.SetSort(viewSortPropertyId, ascending);
+                               }
+
+                               pList = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, PhoneNumberContact>(query, offset, maxCount);
                        }
+                       else
+                       {
+                               __Query<__ContactsContactNumber> query;
+                               query.Construct();
+                               query.SetFilter(numberFilter);
+
+                               if (viewSortPropertyId != 0)
+                               {
+                                       query.SetSort(viewSortPropertyId, ascending);
+                               }
 
-                       pList = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, PhoneNumberContact>(query, offset, maxCount);
+                               pList = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, PhoneNumberContact>(query, offset, maxCount);
+                       }
                }
                break;
        case AB_FI_TYPE_EMAIL_CONTACT:
                {
-                       __Filter<__ContactsContactEmail> filter;
-                       filter.Construct(filterHandle);
+                       unique_ptr< __Filter<__ContactsContactEmail> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactEmail>());
 
-                       __Query<__ContactsContactEmail> query;
-                       query.Construct();
-                       query.SetFilter(filter);
+                       __Filter<__ContactsContactEmail> emailFilter;
+                       emailFilter.Construct(filterHandle);
 
-                       if (viewSortPropertyId != 0)
+                       if (pRwAbFilter->Get() != null)
                        {
-                               query.SetSort(viewSortPropertyId, ascending);
+                               __Filter<__ContactsContactEmail> mainFilter;
+                               mainFilter.Construct();
+                               mainFilter.AddFilter(*pRwAbFilter);
+                               if (emailFilter.Get() != null)
+                               {
+                                       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+                                       mainFilter.AddFilter(emailFilter);
+                               }
+
+                               __Query<__ContactsContactEmail> query;
+                               query.Construct();
+                               query.SetFilter(mainFilter);
+
+                               if (viewSortPropertyId != 0)
+                               {
+                                       query.SetSort(viewSortPropertyId, ascending);
+                               }
+
+                               pList = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, EmailContact>(query, offset, maxCount);
                        }
+                       else
+                       {
+                               __Query<__ContactsContactEmail> query;
+                               query.Construct();
+                               query.SetFilter(emailFilter);
 
-                       pList = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, EmailContact>(query, offset, maxCount);
+                               if (viewSortPropertyId != 0)
+                               {
+                                       query.SetSort(viewSortPropertyId, ascending);
+                               }
+
+                               pList = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, EmailContact>(query, offset, maxCount);
+                       }
                }
                break;
        default:
@@ -1487,6 +1867,8 @@ _AddressbookManagerImpl::GetMatchedItemCount(const AddressbookFilter& filter)
 {
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
+       ClearLastResult();
+
        int count = 0;
        AddressbookFilterType type = _AddressbookFilterImpl::GetInstance(filter)->GetType();
        contacts_filter_h filterHandle = _AddressbookFilterImpl::GetInstance(filter)->GetFilterHandle();
@@ -1494,36 +1876,178 @@ _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);
+
+                       if (pRwAbFilter->Get() != null)
+                       {
+                               __Filter<__ContactsAddressbook> mainFilter;
+                               mainFilter.Construct();
+                               mainFilter.AddFilter(*pRwAbFilter);
+                               if (abFilter.Get() != null)
+                               {
+                                       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+                                       mainFilter.AddFilter(abFilter);
+                               }
+
+                               count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsAddressbook>(mainFilter.Get());
+                       }
+                       else
+                       {
+                               count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsAddressbook>(abFilter.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);
 
-                       unsigned int propertyIds[] = { _contacts_person_grouprel.person_id };
+                       if (pRwAbFilter->Get() != null)
+                       {
+                               __Filter<__ContactsPersonGroupRel> mainFilter;
+                               mainFilter.Construct();
+                               mainFilter.AddFilter(*pRwAbFilter);
+                               if (personFilter.Get() != null)
+                               {
+                                       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+                                       mainFilter.AddFilter(personFilter);
+                               }
+
+                               unsigned int propertyIds[] = { _contacts_person_grouprel.person_id };
+
+                               __Query<__ContactsPersonGroupRel> query;
+                               query.Construct();
+                               query.SetFilter(mainFilter);
+                               query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
+                               query.SetDistinct(true);
+
+                               count = _AddressbookUtil::GetCountWithQuery(query);
+                       }
+                       else
+                       {
+                               unsigned int propertyIds[] = { _contacts_person_grouprel.person_id };
 
-                       __Query<__ContactsPersonGroupRel> query;
-                       query.Construct();
-                       query.SetFilter(filter);
-                       query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
-                       query.SetDistinct(true);
+                               __Query<__ContactsPersonGroupRel> query;
+                               query.Construct();
+                               query.SetFilter(personFilter);
+                               query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
+                               query.SetDistinct(true);
 
-                       count = _AddressbookUtil::GetCountWithQuery(query);
+                               count = _AddressbookUtil::GetCountWithQuery(query);
+
+                       }
                }
 
                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);
+
+                       if (pRwAbFilter->Get() != null)
+                       {
+                               __Filter<__ContactsContact> mainFilter;
+                               mainFilter.Construct();
+                               mainFilter.AddFilter(*pRwAbFilter);
+                               if (contactFilter.Get() != null)
+                               {
+                                       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+                                       mainFilter.AddFilter(contactFilter);
+                               }
+
+                               count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContact>(mainFilter.Get());
+                       }
+                       else
+                       {
+                               count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContact>(contactFilter.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);
+
+                       if (pRwAbFilter->Get() != null)
+                       {
+                               __Filter<__ContactsGroup> mainFilter;
+                               mainFilter.Construct();
+                               mainFilter.AddFilter(*pRwAbFilter);
+                               if (groupFilter.Get() != null)
+                               {
+                                       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+                                       mainFilter.AddFilter(groupFilter);
+                               }
+
+                               count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsGroup>(mainFilter.Get());
+                       }
+                       else
+                       {
+                               count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsGroup>(groupFilter.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);
+
+                       if (pRwAbFilter->Get() != null)
+                       {
+                               __Filter<__ContactsContactNumber> mainFilter;
+                               mainFilter.Construct();
+                               mainFilter.AddFilter(*pRwAbFilter);
+                               if (numberFilter.Get() != null)
+                               {
+                                       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+                                       mainFilter.AddFilter(numberFilter);
+                               }
+
+                               count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContactNumber>(mainFilter.Get());
+                       }
+                       else
+                       {
+                               count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContactNumber>(numberFilter.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);
+
+                       if (pRwAbFilter->Get() != null)
+                       {
+                               __Filter<__ContactsContactEmail> mainFilter;
+                               mainFilter.Construct();
+                               mainFilter.AddFilter(*pRwAbFilter);
+                               if (emailFilter.Get() != null)
+                               {
+                                       mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+                                       mainFilter.AddFilter(emailFilter);
+                               }
+
+                               count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContactEmail>(mainFilter.Get());
+                       }
+                       else
+                       {
+                               count = _AddressbookUtil::GetMatchedItemCountWithFilter<__ContactsContactEmail>(emailFilter.Get());
+                       }
+               }
                break;
        default:
                SysLogException(NID_SCL, E_INVALID_ARG, "[%s] Invalid argument is used. The type of the filter is invalid", GetErrorMessage(GetLastResult()));
@@ -1540,7 +2064,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;
@@ -1572,9 +2096,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));
@@ -1598,17 +2122,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));
 
@@ -1637,24 +2155,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));
 
@@ -1717,7 +2231,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)
@@ -1744,6 +2258,8 @@ _AddressbookManagerImpl::ExportContactToVcardStreamN(const Contact& contact)
 {
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
+       ClearLastResult();
+
        contacts_record_h recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
 
        char* pVcardStream = null;
@@ -1754,7 +2270,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);
@@ -1785,6 +2301,8 @@ _AddressbookManagerImpl::ExportContactsToVcardStreamN(const Tizen::Base::Collect
 {
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
+       ClearLastResult();
+
        char* pVcardStream = null;
        int ret = CONTACTS_ERROR_NONE;
        Contact* pContact = null;
@@ -1793,10 +2311,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);
@@ -1842,25 +2360,19 @@ _AddressbookManagerImpl::ExportPersonToVcardStreamN(const Person& person)
 {
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       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));
+       ClearLastResult();
 
-       __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);
@@ -1890,19 +2402,20 @@ _AddressbookManagerImpl::ExportPersonsToVcardStreamN(const Tizen::Base::Collecti
 {
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
+       ClearLastResult();
+
        int ret = CONTACTS_ERROR_NONE;
        Person* pPerson = null;
        char* pVcardStream = null;
 
        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);
@@ -1917,14 +2430,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));
@@ -1953,6 +2463,8 @@ _AddressbookManagerImpl::ParseVcardStreamN(const Tizen::Base::ByteBuffer& vcardS
 {
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
+       ClearLastResult();
+
        contacts_list_h listHandle = null;
        result r = E_SUCCESS;
 
@@ -1964,7 +2476,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);
@@ -1982,9 +2494,9 @@ _AddressbookManagerImpl::ParseVcardStreamN(const Tizen::Base::ByteBuffer& vcardS
                return null;
        }
 
-       for (int i = 0; i < count; i++)
+       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);
@@ -2005,7 +2517,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)
        {
@@ -2022,11 +2534,13 @@ _AddressbookManagerImpl::ParseVcardStreamN(const Tizen::Base::ByteBuffer& vcardS
        return pList.release();
 }
 
-Tizen::Base::ByteBuffer*
+ByteBuffer*
 _AddressbookManagerImpl::ExportUserProfileToVcardStreamN(const UserProfile& userProfile)
 {
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
+       ClearLastResult();
+
        char* pVcardStream = null;
        int ret = CONTACTS_ERROR_NONE;
        contacts_record_h recordHandle = null;
@@ -2038,7 +2552,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);
@@ -2065,21 +2579,23 @@ _AddressbookManagerImpl::ExportUserProfileToVcardStreamN(const UserProfile& user
        return pByteBuffer.release();
 }
 
-Tizen::Base::ByteBuffer*
+ByteBuffer*
 _AddressbookManagerImpl::ExportUserProfilesToVcardStreamN(const Tizen::Base::Collection::IList& userProfileList)
 {
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
+       ClearLastResult();
+
        char* pVcardStream = null;
        int ret = CONTACTS_ERROR_NONE;
        UserProfile* pProfile = null;
        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);
@@ -2170,7 +2686,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)
@@ -2194,17 +2710,25 @@ _AddressbookManagerImpl::ExportUserProfilesToVcard(const Tizen::Base::Collection
        return E_SUCCESS;
 }
 
-Tizen::Base::Collection::IList*
+IList*
 _AddressbookManagerImpl::GetAllUserProfilesN(void) const
 {
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
        ClearLastResult();
 
+       unique_ptr< __Filter<__ContactsUserProfile> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsUserProfile>());
+       SysTryReturn(NID_SCL, pRwAbFilter != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
        __Query<__ContactsUserProfile> query;
        query.Construct();
        query.SetSort(_contacts_my_profile.display_name, true);
 
+       if (pRwAbFilter->Get() != null)
+       {
+               query.SetFilter(*pRwAbFilter);
+       }
+
        IList* pUserProfilesList = _AddressbookUtil::SearchWithQueryN<__ContactsUserProfile, UserProfile>(query);
        SysTryReturn(NID_SCL, pUserProfilesList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
@@ -2219,13 +2743,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();
@@ -2235,7 +2758,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));