phonebookengines/contactsmodel/cntplsql/inc/pplcontactitemmanager.h
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Thu, 19 Aug 2010 09:41:07 +0300
branchRCL_3
changeset 58 d4f567ce2e7c
parent 0 e686773b3f54
child 24 0ba2181d7c28
permissions -rw-r--r--
Revision: 201031 Kit: 201033

/**
* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:
*
*/



/**
 @file
 @internalComponent
 @released
*/

#ifndef __PPLCONTACTITEMMANAGER_H__
#define __PPLCONTACTITEMMANAGER_H__

#include <e32base.h>
#include <sqldb.h>
#include "cntsqlprovider.h"
#include "clplcontactproperties.h" 
#include "persistencelayer.h"
#include "rpplicccontactstore.h"

class CPplTableBase;
class CPplPreferencesPersistor;

/**
The CPplContactItemManager implements the MLplPersistenceBroker.

MLplPersistenceBroker is a public interface responsible for carrying out the
basic crud operations (Create, Read, Update, Delete). It is exposed to the users 
of Persistence Layer making the CPplContactItemManager an entry point for these 
operations.

CPplContactItemManager is responsible to forward the Create, Delete and Update calls
to the CPplTableBase based object representing actual tables in the contact database.
CPplContactItemManager holds the knowledge of the database structure: how many tables
and what tables compose the contact database.

The Read operation is managed inside CPplContactItemManager and not passed to the table
classes.
*/
NONSHARABLE_CLASS(CPplContactItemManager): public CBase, public MLplPersistenceBroker, public MLplFieldMatcher
{
public:
	static CPplContactItemManager* NewL(RSqlDatabase& aDatabase, MLplTransactionManager& aTransactionManager, CLplContactProperties&  aContactProperties, RPplIccContactStore& aIccContactStore);
	~CPplContactItemManager();
	TContactItemId CreateL(CContactItem& aItem, TUint aSessionId);
	CContactItem* ReadLC(TContactItemId aItemId, const CContactItemViewDef& aView, TInt aInfoToRead, TUint aSessionId, TBool aIccOpenCheck = EFalse) const;
	void UpdateL(CContactItem& aItem, TUint aSessionId, TBool aSpeeDailUpdate = EFalse);
	CContactItem* DeleteLC(TContactItemId  aItemId, TUint aSessionId, TCntSendEventAction aEventType);	
	void ChangeTypeL(TContactItemId aItemId, TUid aNewType);
	void SetConnectionId(TInt aConnectionId);
	void CreateTablesL();
	CContactIdArray* MatchPhoneNumberL(const TDesC& aNumber, TInt aMatchLengthFromRight);
	TBool IsDatabaseEmptyL();
	CPplPreferencesPersistor& PreferencesPersitor();
	CContactIdArray* GroupIdListL();	
    CContactIdArray& CardTemplateIdsL();
    TContactItemId OwnCardIdL();
    void SetOwnCardIdL(TContactItemId aId);
    TInt CardTemplatePrefIdL() const;
    void SetCardTemplatePrefIdL(TInt aCardTemplatePrefId);
    
private:
	CPplContactItemManager(RSqlDatabase& aDatabase, MLplTransactionManager& aTransactionManager, CLplContactProperties&  aContactProperties, RPplIccContactStore& aIccContactStore);
	void ConstructL();
	static void CleanupOperationRollbackL(TAny* aDatabase);
	
	void StartTransactionL(TUint aSessionId);
	void CommitTransactionL();
	
	TInt NameFieldIndex(const CContactItemField& aNameField) const;
	void DeleteInLowDiskConditionL(CPplTableBase* aTable, CContactItem* aContactItem);
	
private:
	RSqlDatabase&				iDatabase;				// CPplContactItemManager does not own the RSqlDatabase object
	MLplTransactionManager& 	iTransactionManager;
	TUint						iSessionId;
	CCntSqlStatement* 			iSelectStatement;
	CLplContactProperties&  	iContactProperties;
	CPplTableBase* 				iContactTable;
	CPplTableBase* 				iGroupTable;	
	CPplTableBase* 				iCommAddrTable;
	CPplPreferencesPersistor*	iPreferencePersistor;
	RPplIccContactStore&        iIccContactStore; 
};

#endif // __PPLCONTACTITEMMANAGER_H__