Removed contacts_db_delete_record and added DeleteContactRecord in AddressbookUtil...
[framework/osp/social.git] / src / FScl_AddressbookManagerImpl.cpp
index 782729b..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);
 #include <FIoFile.h>
 #include <FSclAddressbook.h>
 #include <FSclAddressbookManager.h>
+#include <FSclIAddressbookChangeEventListener.h>
 #include <FSclContact.h>
 #include <FSclCategory.h>
+#include <FSclUserProfile.h>
 #include <FSclContactChangeInfo.h>
 #include <FSclCategoryChangeInfo.h>
 #include <FSclPerson.h>
-#include <FSclAddressbook.h>
 #include <FSclPhoneNumberContact.h>
 #include <FScl_PhoneNumberContactImpl.h>
 #include <FSclEmailContact.h>
@@ -60,7 +60,9 @@
 #include "FScl_CategoryChangeInfoImpl.h"
 #include "FScl_ContactDbMonitor.h"
 #include "FScl_ContactDbConnector.h"
+#include "FScl_UserProfileImpl.h"
 
+using namespace std;
 using namespace Tizen::App;
 using namespace Tizen::Base;
 using namespace Tizen::Base::Collection;
@@ -72,6 +74,7 @@ namespace Tizen { namespace Social
 
 _AddressbookManagerImpl::_AddressbookManagerImpl(void)
        : __pIAddressbookEventListener(null)
+       , __pIAddressbookChangeEventListener(null)
        , __dbVersionForContact(0)
        , __dbVersionForGroup(0)
        , __dbVersionForRelation(0)
@@ -81,7 +84,7 @@ _AddressbookManagerImpl::_AddressbookManagerImpl(void)
 
 _AddressbookManagerImpl::~_AddressbookManagerImpl(void)
 {
-       if (__pIAddressbookEventListener != null)
+       if (__pIAddressbookEventListener != null || __pIAddressbookChangeEventListener != null)
        {
                _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
                if (pContactDbMonitor != null)
@@ -101,7 +104,7 @@ _AddressbookManagerImpl::Construct(void)
 }
 
 result
-_AddressbookManagerImpl::SetEventListener(const IAddressbookEventListener* pListener)
+_AddressbookManagerImpl::SetEventListener(IAddressbookEventListener* pListener)
 {
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
@@ -109,15 +112,53 @@ _AddressbookManagerImpl::SetEventListener(const IAddressbookEventListener* pList
 
        if (pListener != null)
        {
-               if (__pIAddressbookEventListener == null)
+               if (__pIAddressbookEventListener == null && __pIAddressbookChangeEventListener == null)
+               {
+                       _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
+                       SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+                       r = pContactDbMonitor->AddListener(*this);
+                       SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
+               }
+
+               __dbVersionForContact = GetLatestVersion();
+               SysTryReturn(NID_SCL, __dbVersionForContact != -1, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+               __dbVersionForGroup = __dbVersionForContact;
+               __dbVersionForRelation = __dbVersionForContact;
+
+               __pIAddressbookChangeEventListener = null;
+               __pIAddressbookEventListener = pListener;
+       }
+       else
+       {
+               if (__pIAddressbookEventListener != null || __pIAddressbookChangeEventListener != null)
                {
-                       __dbVersionForContact = GetLatestVersion();
-                       SysTryReturn(NID_SCL, __dbVersionForContact != -1, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-                       __dbVersionForGroup = __dbVersionForContact;
-                       __dbVersionForRelation = __dbVersionForContact;
+                       _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
+                       SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+                       pContactDbMonitor->RemoveListener(*this);
+               }
+
+               __pIAddressbookEventListener = null;
+               __pIAddressbookChangeEventListener = null;
+       }
+
+       return E_SUCCESS;
+}
+
+result
+_AddressbookManagerImpl::SetAddressbookChangeEventListener(IAddressbookChangeEventListener* pListener)
+{
+       SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
+       result r = E_SUCCESS;
 
+       if (pListener != null)
+       {
+               if (__pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null)
+               {
                        _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
                        SysTryReturn(NID_SCL, pContactDbMonitor != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
@@ -125,11 +166,18 @@ _AddressbookManagerImpl::SetEventListener(const IAddressbookEventListener* pList
                        SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
                }
 
-               __pIAddressbookEventListener = const_cast<IAddressbookEventListener*>(pListener);
+               __dbVersionForContact = GetLatestVersion();
+               SysTryReturn(NID_SCL, __dbVersionForContact != -1, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+               __dbVersionForGroup = __dbVersionForContact;
+               __dbVersionForRelation = __dbVersionForContact;
+
+               __pIAddressbookEventListener = null;
+               __pIAddressbookChangeEventListener = pListener;
        }
        else
        {
-               if (__pIAddressbookEventListener != null)
+               if (__pIAddressbookChangeEventListener != null || __pIAddressbookEventListener != null)
                {
 
                        _ContactDbMonitor* pContactDbMonitor = _ContactDbMonitor::GetInstance();
@@ -138,6 +186,7 @@ _AddressbookManagerImpl::SetEventListener(const IAddressbookEventListener* pList
                        pContactDbMonitor->RemoveListener(*this);
                }
 
+               __pIAddressbookChangeEventListener = null;
                __pIAddressbookEventListener = null;
        }
 
@@ -148,20 +197,25 @@ Addressbook*
 _AddressbookManagerImpl::CreateAddressbookN(AccountId accountId, const String& name)
 {
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
-       SysTryReturn(NID_SCL, accountId >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. The accountId(%d) is invalid.", GetErrorMessage(E_INVALID_ARG), accountId);
-       SysTryReturn(NID_SCL, !name.IsEmpty(), null, E_INVALID_ARG, "[%s] Invalid argument is used. The addressbook name is an empty string.", GetErrorMessage(E_INVALID_ARG));
+       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;
        filter.Construct();
        filter.AddString(_contacts_address_book.name, CONTACTS_MATCH_EXACTLY, pNameString.get());
+       if (accountId != 0)
+       {
+               filter.AddOperator(CONTACTS_FILTER_OPERATOR_OR);
+               filter.AddInt(_contacts_address_book.account_id, CONTACTS_MATCH_EQUAL, accountId);
+       }
 
        __Query<__ContactsAddressbook> query;
        query.Construct();
@@ -170,26 +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. %x", GetErrorMessage(E_SYSTEM), ret);
+       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);
@@ -201,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;
 }
@@ -215,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;
 }
@@ -237,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);
@@ -253,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();
 }
 
@@ -297,35 +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_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
@@ -334,30 +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_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)
                {
@@ -371,7 +437,6 @@ _AddressbookManagerImpl::AddCategory(Category& category, AddressbookId addressbo
        }
 
        return E_SUCCESS;
-
 }
 
 result
@@ -380,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));
@@ -407,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;
-
-       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);
+       unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, categoryId));
+       SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       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
@@ -441,31 +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;
 }
@@ -478,36 +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;
-
-       int ret = contacts_db_get_record(_contacts_group._uri, categoryId, &recordHandle);
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The specified category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
-
-       contacts_record_get_int(recordHandle, _contacts_group.id, &intValue);
+       unique_ptr<ContactRecord, ContactRecordDeleter> pCategoryRecord(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, category.GetRecordId()));
+       SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       contacts_record_destroy(recordHandle, true);
+       int intValue = 0;
+       contacts_record_get_int(pCategoryRecord.get(), _contacts_group.id, &intValue);
        SysTryReturn(NID_SCL, intValue == categoryId, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
 
-       recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle();
+       contacts_record_h recordHandle = _CategoryImpl::GetInstance(category)->GetRecordHandle();
 
-       ret = contacts_db_update_record(recordHandle);
+       int ret = contacts_db_update_record(recordHandle);
        SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_FILE_NO_SPACE, E_STORAGE_FULL, E_STORAGE_FULL, "[%s] The storage is insufficient.", GetErrorMessage(E_STORAGE_FULL));
        SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
 
-       ret = contacts_db_get_record(_contacts_group._uri, category.GetRecordId(), &recordHandle);
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The category is not found.");
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
+       pCategoryRecord.reset(_AddressbookUtil::GetContactRecordN(_contacts_group._uri, category.GetRecordId()));
+       SysTryReturn(NID_SCL, pCategoryRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       _CategoryImpl::GetInstance(*const_cast<Category*>(&category))->SetRecordHandle(recordHandle);
+       _CategoryImpl::GetInstance(*const_cast<Category*>(&category))->SetRecordHandle(pCategoryRecord.release());
 
-       std::unique_ptr<IListT<int> > pList(_CategoryImpl::GetInstance(category)->GetAddedMembersN());
+       unique_ptr<IListT<int> > pList(_CategoryImpl::GetInstance(category)->GetAddedMembersN());
        if (pList != null && pList->GetCount() > 0)
        {
                int tableId = -1;
-               std::unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
+               unique_ptr<IEnumeratorT<int> > pEnum(pList->GetEnumeratorN());
                while (pEnum->MoveNext() == E_SUCCESS)
                {
                        pEnum->GetCurrent(tableId);
@@ -522,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);
@@ -534,7 +573,6 @@ _AddressbookManagerImpl::UpdateCategory(const Category& category)
        }
 
        return E_SUCCESS;
-
 }
 
 result
@@ -555,28 +593,11 @@ _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()));
 
-
-       contacts_record_h recordHandle = null;
-       int ret = contacts_db_get_record(_contacts_simple_contact._uri, contactId, &recordHandle);
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The contact does not exist.", GetErrorMessage(E_INVALID_ARG));
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
-
-       contacts_record_destroy(recordHandle, true);
-
-       ret = contacts_db_get_record(_contacts_group._uri, categoryId, &recordHandle);
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used. The category does not exist.", GetErrorMessage(E_INVALID_ARG));
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
-
-       contacts_record_destroy(recordHandle, true);
-
-       ret = contacts_group_remove_contact(categoryId, contactId);
+       int ret = contacts_group_remove_contact(categoryId, contactId);
        SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_INVALID_PARAMETER, E_INVALID_ARG, E_INVALID_ARG, "[%s] Invalid argument is used.", GetErrorMessage(E_INVALID_ARG));
        SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
        SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
@@ -591,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()));
 
@@ -605,19 +633,41 @@ IList*
 _AddressbookManagerImpl::GetCategoriesByContactN(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. 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;
 }
@@ -629,24 +679,54 @@ _AddressbookManagerImpl::GetCategoriesByPersonN(PersonId personId) const
 
        ClearLastResult();
 
-       __Filter<__ContactsContactGroupRel> filter;
-       filter.Construct();
-       filter.AddInt(_contacts_contact_grouprel.person_id, CONTACTS_MATCH_EQUAL, personId);
+       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;
 }
@@ -658,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()));
 
@@ -676,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;
 }
@@ -705,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;
 }
@@ -729,75 +862,150 @@ _AddressbookManagerImpl::SearchContactsByEmailN(const String& email) const
 
        ClearLastResult();
 
-       std::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());
-
-       __Query<__ContactsContactEmail> query;
-       query.Construct();
-       query.SetFilter(filter);
-       query.SetSort(_contacts_contact_email.display_name, true);
+       IList* pContacts = null;
 
-       IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, Contact>(query);
-       SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+       unique_ptr< __Filter<__ContactsContactEmail> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContactEmail>());
 
-       return pContacts;
+       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> emailFilter;
+       emailFilter.Construct();
+       emailFilter.AddString(_contacts_contact_email.email, CONTACTS_MATCH_CONTAINS, pCharArray.get());
 
-IList*
-_AddressbookManagerImpl::SearchContactsByNameN(const String& name) const
-{
-       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));
-       SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+       if (pRwAbFilter->Get() != null)
+       {
+               __Filter<__ContactsContactEmail> mainFilter;
+               mainFilter.Construct();
 
-       ClearLastResult();
+               mainFilter.AddFilter(*pRwAbFilter);
+               mainFilter.AddOperator(CONTACTS_FILTER_OPERATOR_AND);
+               mainFilter.AddFilter(emailFilter);
 
-       std::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));
+               __Query<__ContactsContactEmail> query;
+               query.Construct();
+               query.SetFilter(mainFilter);
+               query.SetSort(_contacts_contact_email.display_name, true);
 
-       __Filter<__ContactsContact> filter;
-       filter.Construct();
-       filter.AddString(_contacts_contact.display_name, CONTACTS_MATCH_CONTAINS, pCharArray.get());
+               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);
 
-       __Query<__ContactsContact> query;
-       query.Construct();
-       query.SetFilter(filter);
-       query.SetSort(_contacts_contact.display_name, true);
+               pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactEmail, Contact>(query);
+               SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContact, Contact>(query);
-       SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+       }
 
        return pContacts;
 }
 
 IList*
-_AddressbookManagerImpl::SearchContactsByPhoneNumberN(const String& phoneNumber) const
+_AddressbookManagerImpl::SearchContactsByNameN(const String& name) const
 {
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
        ClearLastResult();
 
-       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));
+       IList* pContacts = null;
 
-       std::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));
+       unique_ptr< __Filter<__ContactsContact> > pRwAbFilter(_AddressbookUtil::GetRwAbFilterN<__ContactsContact>());
 
-       __Filter<__ContactsContactNumber> filter;
-       filter.Construct();
-       filter.AddString(_contacts_contact_number.number, CONTACTS_MATCH_CONTAINS, pCharArray.get());
+       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));
 
-       __Query<__ContactsContactNumber> query;
-       query.Construct();
-       query.SetFilter(filter);
-       query.SetDistinct(true);
-       query.SetSort(_contacts_contact_number.display_name, true);
+       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));
 
-       IList* pContacts = _AddressbookUtil::SearchWithQueryN<__ContactsContactNumber, Contact>(query);
-       SysTryReturn(NID_SCL, pContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+       __Filter<__ContactsContact> nameFilter;
+       nameFilter.Construct();
+       nameFilter.AddString(_contacts_contact.display_name, CONTACTS_MATCH_CONTAINS, pCharArray.get());
+
+       if (pRwAbFilter->Get() != null)
+       {
+               __Filter<__ContactsContact> mainFilter;
+               mainFilter.Construct();
+
+               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;
+}
+
+IList*
+_AddressbookManagerImpl::SearchContactsByPhoneNumberN(const String& phoneNumber) const
+{
+       SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+       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));
+
+       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> numberFilter;
+       numberFilter.Construct();
+       numberFilter.AddString(_contacts_contact_number.number, CONTACTS_MATCH_CONTAINS, pCharArray.get());
+
+       if (pRwAbFilter->Get() != null)
+       {
+               __Filter<__ContactsContactNumber> mainFilter;
+               mainFilter.Construct();
+
+               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;
 }
@@ -807,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;
@@ -822,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;
@@ -836,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);
+
+       unique_ptr<ContactRecord, ContactRecordDeleter> pAbRecord(_AddressbookUtil::GetContactRecordN(_contacts_address_book._uri, intValue));
+       SysTryReturn(NID_SCL, pAbRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(contactHandle);
+       contacts_record_get_int(pAbRecord.get(), _contacts_address_book.mode, &intValue);
+       SysTryReturn(NID_SCL, intValue == 0, null, E_OBJ_NOT_FOUND, "[%s] Contact does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
 
-       contacts_record_get_int(contactHandle, _contacts_contact.id, &intValue);
+       contacts_record_get_int(pContactRecord.get(), _contacts_contact.id, &intValue);
        SysTryReturn(NID_SCL, intValue == contactId, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
 
+       unique_ptr<Contact> pContact(new (std::nothrow) Contact());
+       SysTryReturn(NID_SCL, pContact, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(pContactRecord.release());
        _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
 
        return pContact.release();
@@ -864,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;
@@ -892,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);
@@ -921,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);
 
@@ -949,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();
+
+       unique_ptr< IListT<AddressbookId> > pRwAbIdList(_AddressbookUtil::GetRwAbIdListN());
 
-       IList* pChangedContacts = _AddressbookUtil::SearchWithVersionN<__ContactsContactUpdatedInfo, ContactChangeInfo>(-1, version, latestVersion);
+       IList* pChangedContacts = _AddressbookUtil::SearchWithVersionN<__ContactsContactUpdatedInfo, ContactChangeInfo>(-1, version, latestVersion, pRwAbIdList.get());
        SysTryReturn(NID_SCL, pChangedContacts != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
        return pChangedContacts;
@@ -967,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);
@@ -988,7 +1202,6 @@ _AddressbookManagerImpl::GetChangedCategoriesAfterN(int version, int& latestVers
        latestVersion = latestVersion2 > latestVersion1 ? latestVersion2 : latestVersion1;
        
        return pChangeList.release();
-
 }
 
 IList*
@@ -999,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;
@@ -1013,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;
@@ -1022,7 +1239,7 @@ _AddressbookManagerImpl::GetChangedRelationsAfterN(int version, int& latestVersi
 void
 _AddressbookManagerImpl::OnContactChanged(void)
 {
-       if (__pIAddressbookEventListener == null)
+       if (__pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null)
        {
                return;
        }
@@ -1032,7 +1249,11 @@ _AddressbookManagerImpl::OnContactChanged(void)
 
        if (pChangedContactList->GetCount() > 0)
        {
-               if (__pIAddressbookEventListener != null)
+               if (__pIAddressbookChangeEventListener != null)
+               {
+                       __pIAddressbookChangeEventListener->OnContactsChanged(*pChangedContactList);
+               }
+               else
                {
                        __pIAddressbookEventListener->OnContactsChanged(*pChangedContactList);
                }
@@ -1045,7 +1266,7 @@ _AddressbookManagerImpl::OnContactChanged(void)
 void
 _AddressbookManagerImpl::OnCategoryChanged(void)
 {
-       if (__pIAddressbookEventListener == null)
+       if (__pIAddressbookChangeEventListener == null && __pIAddressbookEventListener == null)
        {
                return;
        }
@@ -1055,7 +1276,11 @@ _AddressbookManagerImpl::OnCategoryChanged(void)
 
        if (pChangedCategoryList->GetCount() > 0)
        {
-               if (__pIAddressbookEventListener != null)
+               if (__pIAddressbookChangeEventListener != null)
+               {
+                       __pIAddressbookChangeEventListener->OnCategoriesChanged(*pChangedCategoryList);
+               }
+               else
                {
                        __pIAddressbookEventListener->OnCategoriesChanged(*pChangedCategoryList);
                }
@@ -1094,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;
-
-       int ret = contacts_db_get_record(_contacts_person._uri, personId, &recordHandle);
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[%s] The person is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
-       SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred. Failed remove a person.", GetErrorMessage(E_SYSTEM));
-
-       contacts_record_destroy(recordHandle, true);
+       unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, personId));
+       SysTryReturn(NID_SCL, pPersonRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       ret = contacts_db_delete_record(_contacts_person._uri, personId);
+       int ret = contacts_db_delete_record(_contacts_person._uri, personId);
        SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The person is not found.");
        SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
        SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred. Failed remove a person.", GetErrorMessage(E_SYSTEM));
@@ -1118,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;
@@ -1136,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[] =
@@ -1156,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;
 }
@@ -1198,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)
@@ -1234,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));
-
-       __ContactsRecordHandle recordHandle(personHandle);
+       unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(_AddressbookUtil::GetContactRecordN(_contacts_person._uri, personId));
+       SysTryReturn(NID_SCL, pPersonRecord != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       contacts_record_get_bool(personHandle, _contacts_person.is_favorite, &boolValue);
+       bool boolValue = false;
+       contacts_record_get_bool(pPersonRecord.get(), _contacts_person.is_favorite, &boolValue);
 
        if (boolValue != isFavorite)
        {
-               contacts_record_set_bool(personHandle, _contacts_person.is_favorite, isFavorite);
+               contacts_record_set_bool(pPersonRecord.get(), _contacts_person.is_favorite, isFavorite);
 
-               ret = contacts_db_update_record(personHandle);
+               int ret = contacts_db_update_record(pPersonRecord.get());
                SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
                SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, E_SYSTEM, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
        }
@@ -1288,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;
@@ -1307,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,
@@ -1338,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);
 
-                       pList = _AddressbookUtil::SearchWithQueryN<__ContactsGroup, Category>(query, offset, maxCount);
+                               if (viewSortPropertyId != 0)
+                               {
+                                       query.SetSort(viewSortPropertyId, ascending);
+                               }
+
+                               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:
@@ -1433,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();
@@ -1440,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>());
 
-                       unsigned int propertyIds[] = { _contacts_person_grouprel.person_id };
+                       __Filter<__ContactsPersonGroupRel> personFilter;
+                       personFilter.Construct(filterHandle);
 
-                       __Query<__ContactsPersonGroupRel> query;
-                       query.Construct();
-                       query.SetFilter(filter);
-                       query.SetProjection(propertyIds, sizeof(propertyIds)/sizeof(unsigned int));
-                       query.SetDistinct(true);
+                       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(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()));
@@ -1486,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;
@@ -1496,8 +2074,6 @@ _AddressbookManagerImpl::OnEachContact(contacts_record_h recordHandle, void* pUs
 
        _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(newRecordHandle);
 
-       _RecordImpl::GetInstance(*pContact)->SetRecordId(INVALID_RECORD_ID);
-
        result r = pList->Add(*pContact);
        SysTryReturn(NID_SCL, !IsFailed(r), false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
@@ -1511,17 +2087,22 @@ _AddressbookManagerImpl::ParseContactsFromVcardN(const Tizen::Base::String& vcar
 {
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
+       ClearLastResult();
+
        File file;
        result r = file.Construct(vcardPath, "r");
+       SysTryReturn(NID_SCL, r != E_INVALID_ARG, null, E_INVALID_ARG, "[%s] Invalid argument is used..", GetErrorMessage(E_INVALID_ARG));
        SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, null, E_ILLEGAL_ACCESS, "[%s] Access to the vcard file is denied due to insufficient permission.", GetErrorMessage(E_ILLEGAL_ACCESS));
+       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));
+       SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
        SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
        return pList.release();
@@ -1530,30 +2111,28 @@ _AddressbookManagerImpl::ParseContactsFromVcardN(const Tizen::Base::String& vcar
 result
 _AddressbookManagerImpl::ExportPersonToVcard(const Person& person, const Tizen::Base::String& vcardPath)
 {
-       SysTryReturn(NID_SCL, !File::IsFileExist(vcardPath), E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
+       bool exist = File::IsFileExist(vcardPath);
+       SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
+       SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
        File file;
        result r = file.Construct(vcardPath, "w");
        SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, E_ILLEGAL_ACCESS, E_ILLEGAL_ACCESS, "[%s] Access to the vcard file is denied due to insufficient permission.", GetErrorMessage(E_ILLEGAL_ACCESS));
+       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));
 
        r = file.Write(pVcardStream, strlen(pVcardStream));
        free(pVcardStream);
+       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));
 
        return E_SUCCESS;
@@ -1562,7 +2141,9 @@ _AddressbookManagerImpl::ExportPersonToVcard(const Person& person, const Tizen::
 result
 _AddressbookManagerImpl::ExportPersonsToVcard(const Tizen::Base::Collection::IList& personList, const Tizen::Base::String& vcardPath)
 {
-       SysTryReturn(NID_SCL, !File::IsFileExist(vcardPath), E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
+       bool exist = File::IsFileExist(vcardPath);
+       SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
+       SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
        int ret = CONTACTS_ERROR_NONE;
@@ -1571,31 +2152,29 @@ _AddressbookManagerImpl::ExportPersonsToVcard(const Tizen::Base::Collection::ILi
 
        result r = file.Construct(vcardPath, "w");
        SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, E_ILLEGAL_ACCESS, E_ILLEGAL_ACCESS, "[%s] Access to the vcard file is denied due to insufficient permission.", GetErrorMessage(E_ILLEGAL_ACCESS));
+       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));
 
                r = file.Write(pVcardStream, strlen(pVcardStream));
                free(pVcardStream);
+               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));
        }
 
@@ -1605,12 +2184,15 @@ _AddressbookManagerImpl::ExportPersonsToVcard(const Tizen::Base::Collection::ILi
 result
 _AddressbookManagerImpl::ExportContactToVcard(const Contact& contact, const Tizen::Base::String& vcardPath)
 {
-       SysTryReturn(NID_SCL, !File::IsFileExist(vcardPath), E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
+       bool exist = File::IsFileExist(vcardPath);
+       SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
+       SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
        File file;
        result r = file.Construct(vcardPath, "w");
        SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, E_ILLEGAL_ACCESS, E_ILLEGAL_ACCESS, "[%s] Access to the vcard file is denied due to insufficient permission.", GetErrorMessage(E_ILLEGAL_ACCESS));
+       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 recordHandle = _ContactImpl::GetInstance(contact)->GetContactRecordHandle();
@@ -1623,6 +2205,7 @@ _AddressbookManagerImpl::ExportContactToVcard(const Contact& contact, const Tize
 
        r = file.Write(pVcardStream, strlen(pVcardStream));
        free(pVcardStream);
+       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));
 
        return E_SUCCESS;
@@ -1631,7 +2214,9 @@ _AddressbookManagerImpl::ExportContactToVcard(const Contact& contact, const Tize
 result
 _AddressbookManagerImpl::ExportContactsToVcard(const Tizen::Base::Collection::IList& contactList, const Tizen::Base::String& vcardPath)
 {
-       SysTryReturn(NID_SCL, !File::IsFileExist(vcardPath), E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
+       bool exist = File::IsFileExist(vcardPath);
+       SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
+       SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
        SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
        int ret = CONTACTS_ERROR_NONE;
@@ -1641,11 +2226,12 @@ _AddressbookManagerImpl::ExportContactsToVcard(const Tizen::Base::Collection::IL
 
        result r = file.Construct(vcardPath, "w");
        SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, E_ILLEGAL_ACCESS, E_ILLEGAL_ACCESS, "[%s] Access to the vcard file is denied due to insufficient permission.", GetErrorMessage(E_ILLEGAL_ACCESS));
+       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 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)
@@ -1660,12 +2246,529 @@ _AddressbookManagerImpl::ExportContactsToVcard(const Tizen::Base::Collection::IL
 
                r = file.Write(pVcardStream, strlen(pVcardStream));
                free(pVcardStream);
+               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));
        }
 
        return E_SUCCESS;
 }
 
+ByteBuffer*
+_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;
+       int ret = CONTACTS_ERROR_NONE;
+
+       ret = contacts_vcard_make_from_contact(recordHandle, &pVcardStream);
+       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_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));
+
+       unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
+       if (pByteBuffer == null)
+       {
+               free(pVcardStream);
+               SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               return null;
+       }
+
+       result r = pByteBuffer->Construct(strlen(pVcardStream));
+       if (IsFailed(r))
+       {
+               free(pVcardStream);
+               SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               return null;
+       }
+
+       r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
+       free(pVcardStream);
+       SysTryReturn(NID_SCL, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+       SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
+
+       return pByteBuffer.release();
+}
+
+ByteBuffer*
+_AddressbookManagerImpl::ExportContactsToVcardStreamN(const Tizen::Base::Collection::IList& contactList)
+{
+       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;
+       result r = E_SUCCESS;
+       int capacity = 0;
+
+       contacts_record_h recordHandle = null;
+
+       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));
+
+       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);
+       SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       if (contactList.GetCount() == 0)
+       {
+               return pByteBuffer.release();
+       }
+
+       while (pEnum->MoveNext() == E_SUCCESS)
+       {
+               pContact = static_cast<Contact*>(pEnum->GetCurrent());
+
+               recordHandle = _ContactImpl::GetInstance(*pContact)->GetContactRecordHandle();
+
+               ret = contacts_vcard_make_from_contact(recordHandle, &pVcardStream);
+               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_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));
+
+               capacity += strlen(pVcardStream);
+               r = pByteBuffer->ExpandCapacity(capacity);
+               if (IsFailed(r))
+               {
+                       free(pVcardStream);
+                       SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+                       return null;
+               }
+
+               r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
+               free(pVcardStream);
+               pVcardStream = null;
+               SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.: capacity(%d), size(%d)", GetErrorMessage(E_SYSTEM));
+       }
+
+       return pByteBuffer.release();
+}
+
+ByteBuffer*
+_AddressbookManagerImpl::ExportPersonToVcardStreamN(const Person& person)
+{
+       SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+       ClearLastResult();
+
+       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;
+       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));
+
+       unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
+       if (pByteBuffer == null)
+       {
+               free(pVcardStream);
+               SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               return null;
+       }
+
+       result r = pByteBuffer->Construct(strlen(pVcardStream));
+       if (IsFailed(r))
+       {
+               free(pVcardStream);
+               SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               return null;
+       }
+
+       r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
+       free(pVcardStream);
+       SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
+
+       return pByteBuffer.release();
+}
+
+ByteBuffer*
+_AddressbookManagerImpl::ExportPersonsToVcardStreamN(const Tizen::Base::Collection::IList& personList)
+{
+       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;
+
+       unique_ptr<ContactRecord, ContactRecordDeleter> pPersonRecord(null);
+
+       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));
+
+       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);
+       SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       if (personList.GetCount() == 0)
+       {
+               return pByteBuffer.release();
+       }
+
+       while (pEnum->MoveNext() == E_SUCCESS)
+       {
+               pPerson = static_cast<Person*>(pEnum->GetCurrent());
+
+               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(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));
+
+               capacity += strlen(pVcardStream);
+               r = pByteBuffer->ExpandCapacity(capacity);
+               if (IsFailed(r))
+               {
+                       free(pVcardStream);
+                       SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+                       return null;
+               }
+
+               r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
+               free(pVcardStream);
+               pVcardStream = null;
+               SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
+       }
+
+       return pByteBuffer.release();
+}
+
+IList*
+_AddressbookManagerImpl::ParseVcardStreamN(const Tizen::Base::ByteBuffer& vcardStream)
+{
+       SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+       ClearLastResult();
+
+       contacts_list_h listHandle = null;
+       result r = E_SUCCESS;
+
+       int ret = contacts_vcard_parse_to_contacts(reinterpret_cast<char*>(const_cast<byte*>(vcardStream.GetPointer())), &listHandle);
+       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_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       unsigned int count = 0;
+       contacts_record_h recordHandle = null;
+       contacts_list_get_count(listHandle, &count);
+
+       unique_ptr<ArrayList, AllElementsDeleter> pList(new (std::nothrow) ArrayList());
+       if (pList == null)
+       {
+               contacts_list_destroy(listHandle, true);
+               SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               return null;
+       }
+
+       r = pList->Construct(count);
+       if (IsFailed(r))
+       {
+               contacts_list_destroy(listHandle, true);
+               SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               return null;
+       }
+
+       for (unsigned int i = 0; i < count; i++)
+       {
+               unique_ptr<Contact> pContact(new (std::nothrow) Contact());
+               if (pContact == null)
+               {
+                       contacts_list_destroy(listHandle, true);
+                       SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+                       return null;
+               }
+
+               r = pList->Add(pContact.get());
+               if (IsFailed(r))
+               {
+                       contacts_list_destroy(listHandle, true);
+                       SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+                       return null;
+               }
+
+               pContact.release();
+       }
+
+       unique_ptr<IEnumerator> pEnum(pList->GetEnumeratorN());
+
+       while (pEnum->MoveNext() == E_SUCCESS)
+       {
+               Contact* pContact = static_cast <Contact*> (pEnum->GetCurrent());
+
+               contacts_list_get_current_record_p(listHandle, &recordHandle);
+               _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(recordHandle);
+
+               ret = contacts_list_next(listHandle);
+       }
+
+       contacts_list_destroy(listHandle, false);
+
+       return pList.release();
+}
+
+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;
+
+       recordHandle = _UserProfileImpl::GetInstance(userProfile)->GetUserProfileHandle();
+
+       ret = contacts_vcard_make_from_my_profile(recordHandle, &pVcardStream);
+       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_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));
+
+       unique_ptr<ByteBuffer> pByteBuffer(new (std::nothrow) ByteBuffer);
+       if (pByteBuffer == null)
+       {
+               free(pVcardStream);
+               SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               return null;
+       }
+       SysTryReturn(NID_SCL, pByteBuffer != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       result r = pByteBuffer->Construct(strlen(pVcardStream));
+       if (IsFailed(r))
+       {
+               free(pVcardStream);
+               SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+               return null;
+       }
+
+       r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
+       free(pVcardStream);
+       SysTryReturn(NID_SCL, r != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+       SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
+
+       return pByteBuffer.release();
+}
+
+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;
+
+       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));
+
+       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);
+       SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       if (userProfileList.GetCount() == 0)
+       {
+               return pByteBuffer.release();
+       }
+
+       while (pEnum->MoveNext() == E_SUCCESS)
+       {
+               contacts_record_h recordHandle = null;
+
+               pProfile = static_cast<UserProfile*>(pEnum->GetCurrent());
+
+               recordHandle = _UserProfileImpl::GetInstance(*pProfile)->GetUserProfileHandle();
+
+               ret = contacts_vcard_make_from_my_profile(recordHandle, &pVcardStream);
+               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_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));
+
+               capacity += strlen(pVcardStream);
+               r = pByteBuffer->ExpandCapacity(capacity);
+               if (IsFailed(r))
+               {
+                       free(pVcardStream);
+                       SysLogException(NID_SCL, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+                       return null;
+               }
+
+               r = pByteBuffer->SetArray(reinterpret_cast<byte*>(pVcardStream), 0, strlen(pVcardStream));
+               free(pVcardStream);
+               SysTryReturn(NID_SCL, r == E_SUCCESS, null, E_SYSTEM, "[%s] A system error has been occurred.: capacity(%d), size(%d)", GetErrorMessage(E_SYSTEM));
+       }
+
+       return pByteBuffer.release();
+}
+
+result
+_AddressbookManagerImpl::ExportUserProfileToVcard(const UserProfile& userProfile, const Tizen::Base::String& vcardPath)
+{
+       bool exist = File::IsFileExist(vcardPath);
+       SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
+       SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
+       SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+       File file;
+       result r = file.Construct(vcardPath, "w");
+       SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, E_ILLEGAL_ACCESS, E_ILLEGAL_ACCESS, "[%s] Access to the vcard file is denied due to insufficient permission.", GetErrorMessage(E_ILLEGAL_ACCESS));
+       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));
+
+       char* pVcardStream = null;
+       contacts_record_h recordHandle = null;
+
+       recordHandle = _UserProfileImpl::GetInstance(userProfile)->GetUserProfileHandle();
+
+       int ret = contacts_vcard_make_from_my_profile(recordHandle, &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));
+
+       r = file.Write(pVcardStream, strlen(pVcardStream));
+       free(pVcardStream);
+       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));
+
+       return E_SUCCESS;
+}
+
+result
+_AddressbookManagerImpl::ExportUserProfilesToVcard(const Tizen::Base::Collection::IList& userProfileList, const Tizen::Base::String& vcardPath)
+{
+       bool exist = File::IsFileExist(vcardPath);
+       SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating..", GetErrorMessage(GetLastResult()));
+       SysTryReturn(NID_SCL, !exist, E_FILE_ALREADY_EXIST, E_FILE_ALREADY_EXIST, "[%s] The specified vcard file already exist.", GetErrorMessage(E_FILE_ALREADY_EXIST));
+       SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+       int ret = CONTACTS_ERROR_NONE;
+       char* pVcardStream = null;
+       File file;
+       UserProfile* pProfile = null;
+
+       result r = file.Construct(vcardPath, "w");
+       SysTryReturn(NID_SCL, r != E_ILLEGAL_ACCESS, E_ILLEGAL_ACCESS, E_ILLEGAL_ACCESS, "[%s] Access to the vcard file is denied due to insufficient permission.", GetErrorMessage(E_ILLEGAL_ACCESS));
+       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));
+
+       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)
+       {
+               contacts_record_h recordHandle = null;
+
+               pProfile = static_cast<UserProfile*>(pEnum->GetCurrent());
+
+               recordHandle = _UserProfileImpl::GetInstance(*pProfile)->GetUserProfileHandle();
+
+               ret = contacts_vcard_make_from_my_profile(recordHandle, &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));
+
+               r = file.Write(pVcardStream, strlen(pVcardStream));
+               free(pVcardStream);
+               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));
+       }
+
+       return E_SUCCESS;
+}
+
+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()));
+
+       return pUserProfilesList;
+}
+
+UserProfile*
+_AddressbookManagerImpl::GetUserProfileN(AddressbookId addressbookId) const
+{
+       SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+       SysTryReturn(NID_SCL, addressbookId >= 0, null, E_INVALID_ARG, "[%s] Invalid argument is used. Addressbook Id(%d).", GetErrorMessage(E_INVALID_ARG), addressbookId);
+
+       ClearLastResult();
+
+       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_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();
+       filter.AddInt(_contacts_my_profile.address_book_id, CONTACTS_MATCH_EQUAL, addressbookId);
+
+       __Query<__ContactsUserProfile> query;
+       query.Construct();
+       query.SetFilter(filter);
+
+       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));
+
+       UserProfile* pProfile = new (std::nothrow) UserProfile(*(static_cast<UserProfile*>(pUserProfilesList->GetAt(0))));
+       SysTryReturn(NID_SCL, pProfile != null, null, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       return pProfile;
+}
+
 _AddressbookManagerImpl*
 _AddressbookManagerImpl::GetInstance(AddressbookManager& addressbookManager)
 {