metadataengine/server/inc/mdssqlfindoperation.h
changeset 0 c53acadfccc6
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Manages object search from database using SQL,*
       
    15 */
       
    16 
       
    17 #ifndef __MDSSQLFINDOPERATION_H__
       
    18 #define __MDSSQLFINDOPERATION_H__
       
    19 
       
    20 #include <e32base.h>
       
    21 
       
    22 #include "mdccommon.h"
       
    23 #include "mdssqliteconnection.h"
       
    24 
       
    25 // FORWARD DECLARATIONS
       
    26 class CMdSSqLiteConnection;
       
    27 class CMdSFindSqlClause;
       
    28 class CMdSFindSequence;
       
    29 class CMdCSerializationBuffer;
       
    30 class CDesC16Array;
       
    31 class RRowData;
       
    32 
       
    33 
       
    34 /**
       
    35 * Find operation class represents a single synchronous
       
    36 * or asynchronous find.
       
    37 */
       
    38 class CMdSSqlFindOperation: public CBase
       
    39     {
       
    40     public:
       
    41 	    /** state of operation */
       
    42 	    enum TOperationState
       
    43 	    	{
       
    44 	        EStateIdle,     // not working
       
    45 	        EStateRunning,  // active state
       
    46 	        EStateStop,     // stop instructed
       
    47 	        EStateDead,     // find stopped
       
    48 	        };
       
    49 
       
    50         /**
       
    51         * constructs a find operation        
       
    52         * @param aFind the master class that runs this operation        
       
    53         * @param aSetSize maximum size of a single result set
       
    54         */
       
    55         static CMdSSqlFindOperation* NewL(            
       
    56             CMdSFindSequence& aFind,            
       
    57             TUint aSetSize
       
    58              );
       
    59 
       
    60         /**
       
    61         * constructs a find operation, leaves in cleanup stack.
       
    62         */
       
    63         static CMdSSqlFindOperation* NewLC(            
       
    64             CMdSFindSequence& aFind,            
       
    65             TUint aSetSize
       
    66              );
       
    67 
       
    68         virtual ~CMdSSqlFindOperation();
       
    69 
       
    70         /**
       
    71         * from MMdSFindOperation
       
    72         */
       
    73         TInt ExecuteL();
       
    74 
       
    75         /**
       
    76         * from MMdSFindOperation
       
    77         */
       
    78         TInt ContinueL();
       
    79 
       
    80         /**
       
    81         * from MMdSFindOperation
       
    82         */
       
    83         TInt State();
       
    84 
       
    85         /**
       
    86         * from MMdSFindOperation
       
    87         */
       
    88         void Cancel();
       
    89 
       
    90         /**
       
    91         * from MMdSFindOperation
       
    92         */
       
    93         CMdSFindSqlClause& FindCriteria();
       
    94 
       
    95         /**
       
    96         * Moves ownership of the result buffer to caller
       
    97         */
       
    98         CMdCSerializationBuffer* Results();
       
    99 
       
   100 		void SetLimit(TUint32 aLimit);
       
   101 
       
   102 		void SetOffset(TUint32 aOffset);
       
   103 
       
   104         /**
       
   105          * Returns query freetext array from CMdSFindSqlClause
       
   106          * @return freetext array
       
   107          */
       
   108         RPointerArray<HBufC>& QueryFreeText();
       
   109 
       
   110     private: // private construction for friends only
       
   111 
       
   112         /**
       
   113         * Construction
       
   114         */
       
   115         CMdSSqlFindOperation(            
       
   116             CMdSFindSequence& aFind,
       
   117             TUint aSetSize = KMaxTUint
       
   118              );
       
   119 
       
   120         /** 2nd phase constructor */
       
   121         void ConstructL();
       
   122 
       
   123     private: // Private functions
       
   124 
       
   125         /**
       
   126         * iterates results from database,
       
   127         * places them in results container
       
   128         * @return error code, KErrNone or KSetReady
       
   129         */
       
   130         TInt FetchResultsL();
       
   131 
       
   132 		TInt EstimateBaseResultSize();
       
   133 
       
   134 		TInt EstimateResultRowSizeL( RRowData& aRow );
       
   135 
       
   136         /**
       
   137         * Gets query results from the rowbuffer, creates
       
   138         * corresponding object structure and adds into the
       
   139         * results container.
       
   140         * @param aDb database connection
       
   141         * @param aRow database row to add into container
       
   142         * @return true, if data was added to container
       
   143         */
       
   144 	    void AddToContainerL();
       
   145 
       
   146         /**
       
   147         * Special treatment for Object, which is complicated
       
   148         * because of heavy optimization
       
   149         * @param aRow database row to add into container
       
   150         * @param aFreespaceOffset offset to free space in buffer
       
   151         */
       
   152 	    TMdCOffset AddObjectToContainerL( RRowData& aRow, TMdCOffset aFreespaceOffset );
       
   153 
       
   154         /**
       
   155         * Marks the current database rows consumed
       
   156         */
       
   157         void ConsumeRows();
       
   158         
       
   159         /**
       
   160         * Add data to container 
       
   161         * @param aRow database row to add into container
       
   162         * @param aFreespaceOffset offset to free space in buffer
       
   163         */
       
   164         TMdCOffset AddItemToContainerL( RRowData &aRow, TMdCOffset aFreespaceOffset );
       
   165     
       
   166         /**
       
   167         * Add data to container 
       
   168         * @param aId item ID to add into container
       
   169         */
       
   170         void AddIdToContainerL( TItemId aId );
       
   171     
       
   172         /**
       
   173         * Creates Item for serialization
       
   174         */
       
   175         void CreateItemL();
       
   176     
       
   177         /**
       
   178         * Creates count for serialization
       
   179         */
       
   180         void CreateCountL();
       
   181     
       
   182         /**
       
   183         * Creates Id for serialization
       
   184         */
       
   185         void CreateIdL();
       
   186                 
       
   187         /**
       
   188         * Creates distinct properties for serialization
       
   189         */
       
   190         void CreateDistinctL();
       
   191     
       
   192     private: // Member data
       
   193     
       
   194         /** Find type */
       
   195         TQueryType iQueryType;
       
   196 
       
   197 		/** Result mode */
       
   198 		TQueryResultMode iResultMode;
       
   199 
       
   200         /**
       
   201         * Data row in find.
       
   202         * Note: RRowData constructor cannot leave, since it is initialized (aInStack==EFalse)
       
   203         */
       
   204 		RRowData* iResultRow;
       
   205 
       
   206         /**
       
   207         * Fetched result rows. Used when result mode is items or distinct.
       
   208         * Note: RRowData constructor cannot leave, since it is initialized (aInStack==EFalse)
       
   209         */
       
   210         RPointerArray<RRowData> iResultRows;
       
   211 
       
   212         /**
       
   213         * Fetched result IDs. Used when result mode is IDs.
       
   214         */
       
   215         RArray<TItemId> iResultIds;
       
   216 
       
   217         /**
       
   218         * Fetched result count. Used when result mode is count.
       
   219         */
       
   220         TUint32 iResultCount;
       
   221 
       
   222         /** container for result objects */
       
   223         CMdCSerializationBuffer* iResults;
       
   224 
       
   225         /** the object find back reference */
       
   226         CMdSFindSequence& iFind;
       
   227 
       
   228         /** the find SQL clause */
       
   229         CMdSFindSqlClause* iFindClause;
       
   230 
       
   231         /** asynchronous run state */
       
   232         TOperationState iState;
       
   233 
       
   234         /** the query ID */
       
   235         RMdsStatement iQueryId;
       
   236 
       
   237         /** maximum size of a single set */
       
   238         const TUint32 iSetSize;
       
   239 
       
   240         /** counter for results in this set */
       
   241         TUint iSetCounter;
       
   242 
       
   243         /** maximum size of the whole search */
       
   244         TUint iLimit;
       
   245 
       
   246         /** maximum size of the whole search */
       
   247         TUint iLimitCounter;
       
   248 
       
   249         /** offset from beginning of the sequence */
       
   250         TUint iOffset;
       
   251 
       
   252         /** used memory from set buffer */
       
   253         TInt iMemoryLimit;
       
   254         
       
   255         /** harvesting prioritization URI count */
       
   256         TInt iHarvestingPrioritizationCount;
       
   257     };
       
   258 
       
   259 #endif // __MDSSQLFINDOPERATION_H__