|
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 |
|
18 #ifndef __MDSFINDSEQUENCE_H__ |
|
19 #define __MDSFINDSEQUENCE_H__ |
|
20 |
|
21 #include <e32base.h> |
|
22 #include <badesca.h> |
|
23 |
|
24 #include "mdscommoninternal.h" |
|
25 |
|
26 // FORWARD DECLARATIONS |
|
27 class CMdsSchema; |
|
28 class CMdSServer; |
|
29 class CMdSSqLiteConnection; |
|
30 class CMdSFindEngine; |
|
31 class CMdSSqlFindOperation; |
|
32 class CMdCSerializationBuffer; |
|
33 |
|
34 // CONSTANTS |
|
35 const TInt KFindSetReady = 1; |
|
36 |
|
37 /** |
|
38 * CMdSFindSequence. |
|
39 * Handles on sequence of find. |
|
40 * A sequence is a logical operation, which may consist |
|
41 * of several parallel physical operations from different |
|
42 * physical entities (tables) |
|
43 */ |
|
44 class CMdSFindSequence : public CActive |
|
45 { |
|
46 public: // Constructors and destructor |
|
47 |
|
48 /** |
|
49 * NewL. |
|
50 * Two-phased constructor. |
|
51 * @param aServer reference to server |
|
52 * @param aSchema the schema |
|
53 * @param aObserver reference to find engine observer |
|
54 * @return Pointer to created CMdSManipulationEngine object. |
|
55 */ |
|
56 static CMdSFindSequence* NewL( |
|
57 CMdSServer& aServer, CMdsSchema& aSchema, CMdSFindEngine& aObserver ); |
|
58 |
|
59 /** |
|
60 * NewLC. |
|
61 * Two-phased constructor. |
|
62 * @param aServer reference to server |
|
63 * @param aSchema the schema |
|
64 * @param aObserver reference to find engine observer |
|
65 * @return Pointer to created CMdSManipulationEngine object. |
|
66 */ |
|
67 static CMdSFindSequence* NewLC( |
|
68 CMdSServer& aServer, CMdsSchema& aSchema, CMdSFindEngine& aObserver ); |
|
69 |
|
70 /** |
|
71 * Destructor. |
|
72 */ |
|
73 virtual ~CMdSFindSequence(); |
|
74 |
|
75 private: // Private constructors |
|
76 |
|
77 /** |
|
78 * 2nd phase constructor |
|
79 */ |
|
80 void ConstructL(); |
|
81 |
|
82 /** |
|
83 * C++ default constructor. |
|
84 * @param aServer reference to server |
|
85 * @param aSchema the schema |
|
86 * @param aObserve reference to find engine observer |
|
87 */ |
|
88 CMdSFindSequence( |
|
89 CMdSServer& aServer, CMdsSchema& aSchema, CMdSFindEngine& aObserve ); |
|
90 |
|
91 public: |
|
92 |
|
93 void SetFindParams( TUint32 aNotifyCount ); |
|
94 |
|
95 /** |
|
96 * Finds objects synchronously |
|
97 * @param aConnection database connection to use in find |
|
98 * @param aSerializedCriteria serialized criteria buffer |
|
99 * @param aUserLevel client's access level |
|
100 * @return KErrNone or KSetReady |
|
101 */ |
|
102 TInt FindL( CMdCSerializationBuffer& aSerializedCriteria, |
|
103 TUserLevel aUserLevel ); |
|
104 |
|
105 /** |
|
106 * Continues ongoing synchronous find with the next set |
|
107 * @param aConnection database connection to use in find |
|
108 * @return KErrNone or KSetReady |
|
109 */ |
|
110 TInt ContinueL(); |
|
111 |
|
112 /** |
|
113 * Start Find objects asynchronously |
|
114 * @param aSerializedCriteria serialized criteria buffer |
|
115 */ |
|
116 void FindAsync( CMdCSerializationBuffer& aSerializedCriteria, |
|
117 TUserLevel aUserLevel ); |
|
118 |
|
119 /** |
|
120 * Continues ongoing asynchronous find with the next set |
|
121 */ |
|
122 void ContinueAsync(); |
|
123 |
|
124 /** |
|
125 * Returns whether find sequence is complete or not. |
|
126 * Completed sequence can be safely delete. |
|
127 */ |
|
128 TBool IsComplete() const; |
|
129 |
|
130 /** |
|
131 * Returns whether find sequence's query is complete or not. |
|
132 */ |
|
133 TBool IsQueryComplete() const; |
|
134 |
|
135 public: // methods called by CMdSFindOperation |
|
136 |
|
137 /** access to the schema */ |
|
138 const CMdsSchema& Schema() const; |
|
139 |
|
140 /** access to the server */ |
|
141 CMdSServer& Server() const; |
|
142 |
|
143 /** access to the result buffer */ |
|
144 CMdCSerializationBuffer& ResultsL() const; |
|
145 |
|
146 void SetResultMode( TBool aResultModeItems ); |
|
147 |
|
148 protected: // From CActive |
|
149 |
|
150 /** |
|
151 * Handles an active object’s request completion event. |
|
152 * CMdEFindSequence calls this methot by itself. |
|
153 */ |
|
154 void RunL(); |
|
155 |
|
156 /** |
|
157 * Handles a leave occurring in the RunL(). The active |
|
158 * scheduler calls this function RunL() function leaves. |
|
159 * @param aError leave code |
|
160 * @return KErrNone. Returning any other value results |
|
161 * in the active scheduler function CActiveScheduler::Error() |
|
162 * being called. |
|
163 */ |
|
164 TInt RunError( TInt aError ); |
|
165 |
|
166 /** |
|
167 * Implementation of asynchronous loop canceling. |
|
168 * calls Cancel method in FindOperation and then |
|
169 * ExecuteL (or ContinueL) should finish pretty soon. |
|
170 */ |
|
171 void DoCancel(); |
|
172 |
|
173 protected: // Find sequence's new methods |
|
174 /** |
|
175 * creates the find operation |
|
176 * @param aResults find results container |
|
177 * @param aCriteria find criteria |
|
178 * @param aRules find rules |
|
179 * @param aConnection the database connection reserved for the find |
|
180 * @return the created operation |
|
181 */ |
|
182 CMdSSqlFindOperation* CreateOperationLC( |
|
183 CMdCSerializationBuffer& aSerializedCriteria ); |
|
184 |
|
185 /** |
|
186 * creates the find operation |
|
187 */ |
|
188 CMdSSqlFindOperation* CreateOperationL( |
|
189 CMdCSerializationBuffer& aSerializedCriteria ); |
|
190 |
|
191 /** |
|
192 * Helper function for PostProcessL |
|
193 * return freetext which belongs to object(id) |
|
194 */ |
|
195 void GetFreeTextForObjectL( CDesCArray& aResultWordBuffer, |
|
196 TDefId aNamespaceDefId, TItemId aObjectId ); |
|
197 |
|
198 |
|
199 /** |
|
200 * Post-processing of found objects. |
|
201 * This routine may launch sub-operations based on the results. |
|
202 * @param aSerializedResultBuffer found objects serialized in buffer |
|
203 */ |
|
204 void PostProcessL( CMdCSerializationBuffer& aSerializedResultBuffer ); |
|
205 |
|
206 /** |
|
207 * Deletes iFindOperation and iFindResults. |
|
208 */ |
|
209 void CleanUp(); |
|
210 |
|
211 private: |
|
212 |
|
213 /** |
|
214 * Sort objects by free text hit count if no text search plug-in found |
|
215 * @param aFreeTextArray array which contains all free texts in criteria |
|
216 * @param aObjGroup found object by criterias |
|
217 */ |
|
218 TUint32 GetFreeTextHitCountL(const CDesCArray& aObjectFreeText, |
|
219 const RPointerArray<HBufC>& aSearchFreeText); |
|
220 |
|
221 private: |
|
222 |
|
223 /** |
|
224 * server |
|
225 */ |
|
226 CMdSServer& iServer; |
|
227 |
|
228 /** |
|
229 * the schema |
|
230 */ |
|
231 CMdsSchema& iSchema; |
|
232 |
|
233 TUint32 iNotifyCount; |
|
234 |
|
235 /** |
|
236 * the find results |
|
237 */ |
|
238 CMdCSerializationBuffer* iFindResults; |
|
239 |
|
240 /** |
|
241 * Serialized criteria buffer. Not owned by CMdSFindSequence. |
|
242 */ |
|
243 CMdCSerializationBuffer* iSerializedCriteria; |
|
244 |
|
245 /** |
|
246 * asynchronous operation observer |
|
247 */ |
|
248 CMdSFindEngine* iObserver; |
|
249 |
|
250 /** |
|
251 * Database connection for asynchronous use |
|
252 */ |
|
253 CMdSSqlFindOperation* iFindOperation; |
|
254 |
|
255 TDesC8* iFindSqlClauseBuffer; |
|
256 |
|
257 // if last query result was Items result |
|
258 TBool iLastResultModeItems; |
|
259 |
|
260 // client application's user level |
|
261 TUserLevel iUserLevel; |
|
262 }; |
|
263 |
|
264 |
|
265 #endif //__MDSFINDSEQUENCE_H__ |
|
266 |