sl@0: /* sl@0: * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * Defines a writable interface for UPS Decision Database sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @internalTechnology sl@0: @released sl@0: */ sl@0: sl@0: #ifndef UPSDBW_H sl@0: #define UPSDBW_H sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include "upslog.h" sl@0: sl@0: namespace UserPromptService sl@0: { sl@0: sl@0: //Database, table and index names sl@0: _LIT(KDecisionTable, "UPSDecisions"); sl@0: _LIT(KPrimaryIndex, "UPSPrimaryIndex"); sl@0: _LIT(KRecordIdIndex, "UPSRecordIdIndex"); sl@0: sl@0: //Column names of the decision table sl@0: _LIT(KColServerSid, "ServerSid"); sl@0: _LIT(KColServiceId, "ServiceId"); sl@0: _LIT(KColClientSid, "ClientSid"); sl@0: _LIT(KColEvaluatorId, "EvaluatorId"); sl@0: _LIT(KColFingerprint, "Fingerprint"); sl@0: _LIT(KColClientEntity, "ClientEntity"); sl@0: _LIT(KColDescription, "Description"); sl@0: _LIT(KColResult, "Result"); sl@0: _LIT(KColEvaluatorInfo, "EvaluatorInfo"); sl@0: _LIT(KColMajorPolicyVersion,"MajorPolicyVersion"); sl@0: _LIT(KColRecordId, "RecordId"); sl@0: sl@0: //Constant lengths sl@0: static const TInt KBaseSQLLength = 33; sl@0: static const TInt KMaxIntCondition = 26; //columnname_length(11) + equal_sign(1) + max_decimal_digit_length(9) + and_length(5) sl@0: static const TInt KMaxStringCondition = 52; //columnname_length(12) + equal_sign(1) + max_field_length(32) + two_singlequote(2) + and_length(5) sl@0: static const TInt KCompactionTreshold = 50; //a percentage which indicates at least how much of the size of the database must be live data sl@0: static const TInt KIndexColumnNumber = 7; //The number of columns constructing the decision index sl@0: sl@0: //Basic SQL statement parts sl@0: _LIT(KSQLQueryBase, "SELECT * FROM %S"); sl@0: _LIT(KSQLQueryString, "%S"); sl@0: _LIT(KSQLQueryConditionInt, "%u"); sl@0: _LIT(KSQLQueryConditionString, "'%S'"); sl@0: _LIT(KSQLQueryWhere, " WHERE "); sl@0: _LIT(KSQLQueryAnd, " AND "); sl@0: _LIT(KSQLQueryNull, " IS NULL"); sl@0: _LIT(KSQLQueryEqual, "="); sl@0: _LIT(KSQLQueryNotEqual, "<>"); sl@0: _LIT(KSQLQueryLessThan, "<"); sl@0: _LIT(KSQLQueryGreaterThan, ">"); sl@0: _LIT(KSQLQueryLessThanOrEqual, "<="); sl@0: _LIT(KSQLQueryGreaterThanOrEqual,">="); sl@0: sl@0: //Other classes used in UPS database sl@0: class CDecisionFilter; sl@0: class CDecisionRecord; sl@0: class CDecisionDb; sl@0: sl@0: NONSHARABLE_CLASS(CDecisionDbCompactor):public CActive sl@0: /** sl@0: Provides an interface to compact the decision database asynchronously. While the sl@0: compaction operation is in progress, the database cannot be used for any other sl@0: operations such as searching records or preparing views. sl@0: */ sl@0: { sl@0: friend class CDecisionDbW; sl@0: sl@0: public: sl@0: IMPORT_C void Compact(TRequestStatus& aStatus); sl@0: ~CDecisionDbCompactor(); sl@0: sl@0: protected: sl@0: static CDecisionDbCompactor *NewLC(); sl@0: CDecisionDbCompactor(); sl@0: sl@0: /** sl@0: From CActive. Handles incremental database compaction. sl@0: */ sl@0: void RunL(); sl@0: /** sl@0: From CActive. Cancels current database compaction. sl@0: */ sl@0: void DoCancel(); sl@0: /** sl@0: From CActive. Handles errors. sl@0: */ sl@0: TInt RunError(TInt aError); sl@0: sl@0: private: sl@0: /** sl@0: Handle to the interface used for performing database compaction in incremental steps sl@0: */ sl@0: RDbIncremental iDbIncremental; sl@0: /** sl@0: Contains the current step count for the incremental compaction operation sl@0: */ sl@0: TPckgBuf iStep; sl@0: /** sl@0: Copy of the status variable of the client which requested the compaction service sl@0: */ sl@0: TRequestStatus* iClientStatus; sl@0: }; sl@0: sl@0: sl@0: NONSHARABLE_CLASS(CDecisionDbW):public CDecisionDb sl@0: /** sl@0: A writable interface for UPS decision database. Connects to the database during construction. sl@0: Creates the decision database and table, if not exist. Performs querying, insertion and deletion sl@0: operations on the decision database. sl@0: */ sl@0: { sl@0: public: sl@0: IMPORT_C static CDecisionDbW *NewL(const TDesC& aDbName, RFs& aFs); sl@0: IMPORT_C static CDecisionDbW *NewLC(const TDesC& aDbName, RFs& aFs); sl@0: sl@0: ~CDecisionDbW(); sl@0: sl@0: IMPORT_C void CreateDecisionL(CDecisionRecord& aRecord); sl@0: IMPORT_C CDecisionRecord *GetDecisionL(CDecisionFilter& aFilter); sl@0: IMPORT_C TBool UpdateDecisionL(CDecisionFilter& aFilter, CDecisionRecord& aNewRecord); sl@0: IMPORT_C void RemoveDecisionsL(CDecisionFilter& aFilter); sl@0: IMPORT_C void DeleteDatabaseL(RFs& aFs); sl@0: IMPORT_C CDecisionDbCompactor *PrepareCompactionLC(); sl@0: sl@0: private: sl@0: CDecisionDbW(); sl@0: sl@0: void ConstructL(const TDesC& aDbName, RFs& aFs); sl@0: void OpenDatabaseL(RFs& aFs); sl@0: void CreateDatabaseL(RFs& aFs); sl@0: void CreateTableL(); sl@0: void CreateIndexL(); sl@0: void DoRemoveDecisionL(CDecisionFilter& aFilter); sl@0: void UpdateCurrentRowL(RDbTable& aTable, CDecisionRecord& aRecord); sl@0: void PrepareForSearchL(RDbTable& aTable, CDecisionFilter& aFilter,TDbSeekMultiKey& aSeekKey); sl@0: sl@0: private: sl@0: /** sl@0: * The fully qualified path of the database sl@0: */ sl@0: HBufC* iDbName; sl@0: }; sl@0: sl@0: }//namespace Ups sl@0: sl@0: #endif //UPSDBW_H