phonebookengines/contactsmodel/cntplsql/inc/pltables.h
changeset 46 efe85016a067
parent 40 b46a585f6909
equal deleted inserted replaced
40:b46a585f6909 46:efe85016a067
    39 #include <e32hashtab.h>
    39 #include <e32hashtab.h>
    40 #include <QList>
    40 #include <QList>
    41 #include <QStringList>
    41 #include <QStringList>
    42 
    42 
    43 class CPcsKeyMap;
    43 class CPcsKeyMap;
       
    44 
    44 
    45 
    45 /**
    46 /**
    46 The CPplTableBase class forms the base class for all SQLite tables in the
    47 The CPplTableBase class forms the base class for all SQLite tables in the
    47 Persistence Layer. It implements default behaviour for some basic operations.
    48 Persistence Layer. It implements default behaviour for some basic operations.
    48 
    49 
   303 	RSqlDatabase&  iDatabase;
   304 	RSqlDatabase&  iDatabase;
   304 	};
   305 	};
   305 
   306 
   306 
   307 
   307 /**
   308 /**
   308 The CPplPredictiveSearchTable class contains numeric representation of the
   309 The CPplPredictiveSearchTableBase is a base class for keymap-specific predictive
   309 fields that are checked in predictive search.
   310 search tables that contain numeric representation of the fields that are checked
   310 */
   311 in predictive search.
   311 NONSHARABLE_CLASS(CPplPredictiveSearchTable) : public CPplTableBase
   312 */
   312 	{
   313 NONSHARABLE_CLASS(CPplPredictiveSearchTableBase) : public CPplTableBase
   313 public:
   314 	{
   314 	static CPplPredictiveSearchTable* NewL(RSqlDatabase& aDatabase);
   315 public:
   315 	static CPplPredictiveSearchTable* NewLC(RSqlDatabase& aDatabase);
   316 	virtual ~CPplPredictiveSearchTableBase();
   316 	~CPplPredictiveSearchTable();
       
   317 
   317 
   318 public: // From CPplTableBase
   318 public: // From CPplTableBase
   319 	void CreateInDbL(CContactItem& aItem);
   319 	void CreateInDbL(CContactItem& aItem);
   320 	void UpdateL(const CContactItem& aItem);
   320 	void UpdateL(const CContactItem& aItem);
   321 	void DeleteL(const CContactItem& aItem, TBool& aLowDiskErrorOccurred);
   321 	void DeleteL(const CContactItem& aItem, TBool& aLowDiskErrorOccurred);
   322 	void CreateTableL();
   322 	virtual void CreateTableL() = 0;
   323 
   323 
   324 private:
   324 public: // New pure virtual functions
       
   325 	virtual QList<QChar> FillAllTables() const = 0;
       
   326 
       
   327 private: // New pure virtual functions
       
   328 	virtual HBufC* TableNameL(const QChar aCh) const = 0;
       
   329 	virtual TBool IsValidChar(const QChar aChar) const = 0;
       
   330 
       
   331 	virtual void FillKeyboardSpecificFieldsL(RSqlStatement& aSqlStatement,
       
   332 											 QStringList aTokens) = 0;
       
   333 
       
   334 private: // New virtual functions
       
   335 	virtual QStringList
       
   336 		GetTableSpecificFields(const CContactItem& aItem,
       
   337 							   TBool& aMandatoryFieldsPresent) const;
       
   338 
       
   339 public:
       
   340 	// Return next table's name, ownership is transferred
       
   341 	HBufC* GetNextTableNameL(QList<QChar>& aTables) const;
       
   342 
       
   343 protected:
   325 	void ConstructL();
   344 	void ConstructL();
   326 	CPplPredictiveSearchTable(RSqlDatabase& aDatabase);
   345 	CPplPredictiveSearchTableBase(RSqlDatabase& aDatabase,
       
   346 								  TInt aMaxTokens,
       
   347 								  TInt aMaxTokenLength);
       
   348 
       
   349 	QList<QChar> DetermineTables(QStringList aTokens) const;
       
   350 
       
   351 	// aFirstName ownership is not transferred
       
   352 	// aLastName ownership is not transferred
       
   353 	QStringList GetTokens(QStringList aNonTokenizedFields,
       
   354 						  HBufC* aFirstName,
       
   355 						  HBufC* aLastName) const;
       
   356 
       
   357 private:
   327 	void WriteToDbL(const CContactItem& aItem);
   358 	void WriteToDbL(const CContactItem& aItem);
   328 
   359 
   329 	// aFirstNameAsNbr OUT: Pointer to first name converted to numbers,
   360 	// aFirstNameAsNbr OUT: Pointer to first name converted to numbers,
   330 	//				  		pushed to cleanupstack. Ownership is transferred.
   361 	//				  		pushed to cleanupstack. Ownership is transferred.
   331 	// aLastNameAsNbr OUT: Pointer to last name converted to numbers,
   362 	// aLastNameAsNbr OUT: Pointer to last name converted to numbers,
   338 					 HBufC** aFirstNameAsNbr,
   369 					 HBufC** aFirstNameAsNbr,
   339 					 HBufC** aLastNameAsNbr,
   370 					 HBufC** aLastNameAsNbr,
   340 					 HBufC** aFirstName,
   371 					 HBufC** aFirstName,
   341 					 HBufC** aLastName) const;
   372 					 HBufC** aLastName) const;
   342 
   373 
   343 	QList<TChar> DetermineTables(QStringList aTokens) const;
       
   344 
       
   345 	// aString ownership is not transferred
   374 	// aString ownership is not transferred
   346 	void AddTokens(HBufC* aString, QStringList& aTokens) const;
   375 	void AddTokens(HBufC* aString, QStringList& aTokens) const;
   347 
   376 
   348 	TBool IsValidChar(QChar aChar) const;
       
   349 
       
   350 	// aFirstName ownership is not transferred
       
   351 	// aLastName ownership is not transferred
       
   352 	QStringList GetNumericTokens(HBufC* aFirstName, HBufC* aLastName) const;
       
   353 	void GetNextToken(QStringList& aSource, QStringList& aDestination) const;
   377 	void GetNextToken(QStringList& aSource, QStringList& aDestination) const;
   354 	void DeleteFromAllTablesL(TContactItemId aContactId,
   378 	void DeleteFromAllTablesL(TContactItemId aContactId,
   355 							  TBool& aLowDiskErrorOccurred) const;
   379 							  TBool& aLowDiskErrorOccurred) const;
   356 
   380 
   357 	QList<TChar> FillAllTables() const;
   381 protected:
   358 
       
   359 	// Return next table's name, ownership is transferred
       
   360 	HBufC* GetNextTableNameL(QList<TChar>& aTables) const;
       
   361 	const TDesC& TableNameL(TChar aCh) const;
       
   362 
       
   363 	quint64 ConvertToHex(QString aToken) const;
       
   364 
       
   365 private:
       
   366 	// Owned
   382 	// Owned
   367 	CCntSqlStatement* iInsertStmnt;
   383 	CCntSqlStatement* iInsertStmnt;
   368 	// Owned
   384 	// Owned
   369 	CCntSqlStatement* iDeleteStmnt;
   385 	CCntSqlStatement* iDeleteStmnt;
   370 	// Owned
   386 	// Owned
   371 	CPcsKeyMap*		  iKeyMap;
   387 	CPcsKeyMap*		  iKeyMap;
   372 
   388 
   373 	RSqlDatabase&	  iDatabase;
   389 	RSqlDatabase&	  iDatabase;
   374 	
   390 
   375 	// For unit testing
   391 	// Max amount of tokens that can be stored into predictive search table
   376 	friend class UT_CPplPredictiveSearchTable;
   392 	const TInt		  iMaxTokens;
   377 	};
   393 
       
   394 	// Max length of a single token that can be stored into predictive search table
       
   395 	const TInt		  iMaxTokenLength;
       
   396 	};
       
   397 
   378 
   398 
   379 NONSHARABLE_CLASS(CPplPresenceTable) : public CPplTableBase
   399 NONSHARABLE_CLASS(CPplPresenceTable) : public CPplTableBase
   380     {
   400     {
   381 public:
   401 public:
   382     static CPplPresenceTable* NewL(RSqlDatabase& aDatabase);
   402     static CPplPresenceTable* NewL(RSqlDatabase& aDatabase);