|
1 /* |
|
2 * Copyright (c) 2002-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: Add, update and remove items in DB.* |
|
15 */ |
|
16 |
|
17 #ifndef __MDSSQLOBJECTMANIPULATE_H__ |
|
18 #define __MDSSQLOBJECTMANIPULATE_H__ |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32base.h> |
|
22 #include <hash.h> |
|
23 |
|
24 #include "mdscommoninternal.h" |
|
25 |
|
26 #include "mdsclausebuffer.h" |
|
27 |
|
28 // FORWARD DECLARATION |
|
29 class CMdSSqLiteConnection; |
|
30 class CMdsSchema; |
|
31 class CMdCFolder; |
|
32 class RMdsStatement; |
|
33 class CMdsNamespaceDef; |
|
34 class CMdsObjectDef; |
|
35 class CMdsPropertyDef; |
|
36 class CMdCSerializationBuffer; |
|
37 class CMdsClauseBuffer; |
|
38 class RRowData; |
|
39 class TColumn; |
|
40 class CMdSObjectLockList; |
|
41 class CMdSServerSession; |
|
42 class RMdsStatement; |
|
43 |
|
44 // CLASS DECLARATION |
|
45 /** |
|
46 * |
|
47 */ |
|
48 class CMdSIdentifierGenerator: public CBase |
|
49 { |
|
50 public: // Constructors and destructor |
|
51 /** |
|
52 * Two-phased constructor. |
|
53 * @param aPool, reference to pool for reserve database connection. |
|
54 * @return Pointer to CMdSIdentifierGenerator object. |
|
55 */ |
|
56 static CMdSIdentifierGenerator* NewL(); |
|
57 |
|
58 /** |
|
59 * Two-phased constructor. |
|
60 * @param aPool, reference to pool for reserve database connection. |
|
61 * @return Pointer to CMdSIdentifierGenerator object. |
|
62 */ |
|
63 static CMdSIdentifierGenerator* NewLC(); |
|
64 |
|
65 /** |
|
66 * Destructor. |
|
67 */ |
|
68 virtual ~CMdSIdentifierGenerator(); |
|
69 |
|
70 /** |
|
71 * Set guid to generated ones if both are 0 |
|
72 */ |
|
73 void GenerateGuid( TInt64& aGuidHigh, TInt64& aGuidLow ); |
|
74 |
|
75 /** |
|
76 * Return unique uri |
|
77 * method require unique guid's |
|
78 */ |
|
79 HBufC* GenerateUriL( const CMdsObjectDef& aObjectDef, |
|
80 const TInt64& aGuidHigh, const TInt64& aGuidLow ) const; |
|
81 |
|
82 private: // Private constructors |
|
83 /** |
|
84 * CMdSIdentifierGenerator. |
|
85 * C++ default constructor. |
|
86 */ |
|
87 CMdSIdentifierGenerator( ) |
|
88 { |
|
89 iDigest = NULL; |
|
90 } |
|
91 |
|
92 /** |
|
93 * ConstructL. |
|
94 * 2nd phase constructor. |
|
95 */ |
|
96 void ConstructL( ); |
|
97 |
|
98 private: //Internal variables |
|
99 TInt64 iImei; |
|
100 TInt64 iLastTime; |
|
101 |
|
102 CMessageDigest* iDigest; |
|
103 }; |
|
104 |
|
105 |
|
106 /** |
|
107 * CMdSSqlObjectManipulate converts object handling |
|
108 * instructions to an SQL clause. |
|
109 */ |
|
110 class CMdSSqlObjectManipulate: public CBase |
|
111 { |
|
112 public: // Constructors and destructor |
|
113 |
|
114 /** |
|
115 * Two-phased constructor. |
|
116 * @param aPool, reference to pool for reserve database connection. |
|
117 * @return Pointer to CMdSSqlObjectManipulate object. |
|
118 */ |
|
119 static CMdSSqlObjectManipulate* NewL( const CMdsSchema& aSchema, |
|
120 CMdSObjectLockList& aLockList ); |
|
121 |
|
122 /** |
|
123 * Two-phased constructor. |
|
124 * @param aPool, reference to pool for reserve database connection. |
|
125 * @return Pointer to CMdSSqlObjectManipulate object. |
|
126 */ |
|
127 static CMdSSqlObjectManipulate* NewLC( const CMdsSchema& aSchema, |
|
128 CMdSObjectLockList& aLockList ); |
|
129 |
|
130 /** |
|
131 * Destructor. |
|
132 */ |
|
133 virtual ~CMdSSqlObjectManipulate(); |
|
134 |
|
135 |
|
136 private: // Private constructors |
|
137 |
|
138 /** |
|
139 * CSqlObjectManipulate. |
|
140 * C++ default constructor. |
|
141 */ |
|
142 CMdSSqlObjectManipulate( const CMdsSchema& aSchema, |
|
143 CMdSObjectLockList& aLockList ); |
|
144 |
|
145 /** |
|
146 * ConstructL. |
|
147 * 2nd phase constructor. |
|
148 */ |
|
149 void ConstructL( ); |
|
150 |
|
151 |
|
152 public: // Public functions |
|
153 |
|
154 /** |
|
155 * Add new object to DB (not using any transaction system) |
|
156 * |
|
157 * @param aBuffer serialized object with properties and freeText |
|
158 * @return new added object id |
|
159 */ |
|
160 TItemId AddObjectL( CMdSSqLiteConnection& aConnection, |
|
161 CMdCSerializationBuffer& aBuffer, |
|
162 RMdsStatement& aMdsBaseObjStatement, RMdsStatement& aMdsObjStatement, |
|
163 const CMdSServerSession* aServerSession = NULL ); |
|
164 |
|
165 /** |
|
166 * Really add freetext to DB |
|
167 * |
|
168 * @param aWord word to add |
|
169 * @param aObjectId owner of freetext object id |
|
170 * @param aPosition position |
|
171 * @param aSearch search for existing freetext in DB |
|
172 */ |
|
173 TUint32 AddFreeTextToDBL( TPtrC16& aWord, TItemId aObjectId, |
|
174 TInt32 aPosition, TBool aSearch = ETrue ); |
|
175 |
|
176 /** |
|
177 * Add new freeText to DB (not using any transaction system) |
|
178 * (check if FreeText is in DB and in this case don't add it) |
|
179 * |
|
180 * @param aBuffer serialized object with FreeText |
|
181 * @param aFreeTextCount freetext count |
|
182 * @param aObjectId freetext owner object ID |
|
183 * @return how many freeText was added to DB |
|
184 */ |
|
185 TInt AddFreeTextL( CMdCSerializationBuffer& aBuffer, TInt aFreeTextCount, TItemId aObjectId ); |
|
186 |
|
187 /** |
|
188 * remove object by URI - just for internal use! |
|
189 */ |
|
190 void RemoveObjectForceL( const TDesC16& aUri, TItemId aObjectId ); |
|
191 |
|
192 /** |
|
193 * USE RemoveObjectForceL WITH CAUTION !!! |
|
194 * THIS FUNCTION REMOVES OBJECT WITHOUT ANY CHECKING |
|
195 * ONLY FOR INTERNAL USE !!! |
|
196 */ |
|
197 void RemoveObjectForceL( TItemId aObjectId ); |
|
198 |
|
199 CMdCSerializationBuffer* CheckObjectL( TInt aResultBufferSize, |
|
200 const TDesC& aUri, TDefId aNamespaceDefId ); |
|
201 |
|
202 CMdCSerializationBuffer* CheckObjectL( TInt aResultBufferSize, |
|
203 TItemId aId, TDefId aNamespaceDefId ); |
|
204 |
|
205 CMdCSerializationBuffer* CheckObjectL( TInt aResultBufferSize, |
|
206 CMdCSerializationBuffer& aIds, TDefId aNamespaceDefId ); |
|
207 |
|
208 void CollectRemovedItemsL( RArray<TItemId>& aRemoveIds, |
|
209 RArray<TItemId>& aObjectIds, RArray<TItemId>& aRelationIds, |
|
210 RArray<TItemId>& aEventIds ); |
|
211 |
|
212 /** |
|
213 * Remove object using it's id |
|
214 * |
|
215 * @param aBuffer id's to remove |
|
216 * @param aCount id's count |
|
217 * @param aIdArray result id's |
|
218 * @param aUserLevel not used - delete |
|
219 * @param aLockList list of locked objects |
|
220 */ |
|
221 void RemoveObjectsByIdL( CMdCSerializationBuffer& aBuffer, TInt aCount, |
|
222 RArray<TItemId>& aIdArray, RArray<TItemId>& aRelationIds, |
|
223 RArray<TItemId>& aEventIds ); |
|
224 |
|
225 /** |
|
226 * Remove object using it's URI's |
|
227 * |
|
228 * @param aBuffer URI's to remove |
|
229 * @param aCount URI's count |
|
230 * @param aIdArray result id's |
|
231 * @param aUserLevel not used - delete |
|
232 * @param aLockList list of locked objects |
|
233 */ |
|
234 void RemoveObjectsByUriL( CMdCSerializationBuffer& aBuffer, TInt aCount, |
|
235 RArray<TItemId>& aIdArray, RArray<TItemId>& aRelationIds, |
|
236 RArray<TItemId>& aEventIds ); |
|
237 |
|
238 /** |
|
239 * search for object uri |
|
240 * |
|
241 * @param aUri object uri to search for |
|
242 * @param aFlags return found object flags |
|
243 * @return object id |
|
244 */ |
|
245 TItemId SearchObjectByUriL( const TDesC16& aUri, TUint32& aFlags ); |
|
246 |
|
247 /** |
|
248 * update freetext (add and remove) |
|
249 */ |
|
250 void UpdateFreeTextL( CMdCSerializationBuffer& aBuffer, TInt aCount, |
|
251 TItemId aObjectId ); |
|
252 |
|
253 /** |
|
254 * Update object |
|
255 * |
|
256 * @param aBuffer objects to update |
|
257 * @param aLockList list of locked objects |
|
258 */ |
|
259 TItemId UpdateObjectL( CMdSSqLiteConnection& aConnection, |
|
260 CMdCSerializationBuffer& aBuffer ); |
|
261 |
|
262 /** |
|
263 * Runs garbage collection to database |
|
264 * @param aDb The database connection |
|
265 * @return next garbage collection start is needed? |
|
266 */ |
|
267 TBool GarbageCollectionL(); |
|
268 |
|
269 /** |
|
270 * Set namespace for processing functions |
|
271 */ |
|
272 void SetNamespace( const CMdsNamespaceDef* aNamespaceDef ); |
|
273 |
|
274 TItemId AddEventL( CMdSSqLiteConnection& aConnection, |
|
275 CMdCSerializationBuffer& aBuffer ); |
|
276 |
|
277 TItemId AddRelationL( CMdSSqLiteConnection& aConnection, |
|
278 CMdCSerializationBuffer& aBuffer ); |
|
279 |
|
280 void RemoveEventsL( CMdCSerializationBuffer& aBuffer, TInt aCount, |
|
281 RArray<TItemId>& aIdArray ); |
|
282 |
|
283 void RemoveRelationsL( CMdCSerializationBuffer& aBuffer, TInt aCount, |
|
284 RArray<TItemId>& aIdArray ); |
|
285 |
|
286 TItemId UpdateRelationsL( CMdSSqLiteConnection& aConnection, |
|
287 CMdCSerializationBuffer& aBuffer ); |
|
288 |
|
289 /** |
|
290 * Add memory card media ID |
|
291 * @param aDb The database connection |
|
292 * @param aMediaId Memory card's media ID |
|
293 */ |
|
294 void AddMemoryCardL(TUint32 aMediaId); |
|
295 |
|
296 /** |
|
297 * Get the latest memory card's media ID |
|
298 * @param aDb The database connection |
|
299 * @param aMediaId Returns the latest memory card's media ID |
|
300 * @leave KErrNotFound Not memory cards exist at all |
|
301 */ |
|
302 void GetMemoryCardL(TUint32& aMediaId); |
|
303 |
|
304 /** |
|
305 * Checks if memory card's with given media ID exists |
|
306 * @param aMediaId memory card's media ID |
|
307 * @return memory card exists or not |
|
308 */ |
|
309 TBool CheckMemoryCardL(TUint32 aMediaId); |
|
310 |
|
311 /** |
|
312 * Set media's media ID, drive and present state to DB. |
|
313 * |
|
314 * @param aMediaId media ID |
|
315 * @param aMediaId drive |
|
316 * @param aMediaId present state |
|
317 */ |
|
318 void SetMediaL(TUint32 aMediaId, TChar aDrive, TBool aPresentState); |
|
319 |
|
320 /** |
|
321 * Check if the media's with given media ID exist in DB and return |
|
322 * drive and present state. |
|
323 * |
|
324 * @param aMediaId given media ID |
|
325 * @param aMediaId drive |
|
326 * @param aMediaId present state |
|
327 * |
|
328 * @return does media exist |
|
329 */ |
|
330 TBool GetMediaL(TUint32 aMediaId, TChar& aDrive, TBool& aPresentState); |
|
331 |
|
332 /** |
|
333 * Get present medias' media IDs and drives. |
|
334 * |
|
335 * @param aMediaInfoBuffer buffer where media infos are written |
|
336 * |
|
337 * @return present media count |
|
338 */ |
|
339 TInt32 GetPresentMediasL(TDes8& aMediaInfoBuffer); |
|
340 |
|
341 /** |
|
342 * Search file object which is in not present state. |
|
343 * |
|
344 * @param aDb The database connection |
|
345 * @param aMediaId Memory card's media ID |
|
346 * @param aUri File's URI |
|
347 * @param aFileInfo File information |
|
348 * |
|
349 * @leave KErrNotFound If not present state file object doesn't exist |
|
350 * with given URI and media ID |
|
351 */ |
|
352 TItemId SearchNotPresentFileL(TUint32 aMediaId, TDesC16& aUri, |
|
353 TMdSFileInfo& aFileInfo, |
|
354 TFilePresentStates& aPlaceHolder, TBool& aNotPresentState); |
|
355 |
|
356 /** from MMdSObjectManipulate */ |
|
357 void SetFilesToPresentL(const RArray<TItemId>& aObjectIds); |
|
358 |
|
359 /** |
|
360 * Sets object's relation to present state. |
|
361 * @param aObjectId object ID |
|
362 * @param aIdArray marked relations ID's |
|
363 */ |
|
364 void SetRelationsToPresentL(TItemId aObjectId, |
|
365 RArray<TItemId>& aIdArray); |
|
366 |
|
367 /** |
|
368 * Sets all file objects from last memory card to not present state. |
|
369 * @param aMediaId Memory card's media ID |
|
370 * @param aObjectIds Object IDs of those object which are set to not |
|
371 * present state |
|
372 */ |
|
373 void SetFilesToNotPresentL(TUint32 aMediaId, TBool aStartUp, RArray<TItemId>& aObjectIds); |
|
374 |
|
375 /** |
|
376 * Sets file objects relations from last memory card to not present |
|
377 * state. |
|
378 * |
|
379 * @param aMediaId Memory card's media ID |
|
380 * @param aRelationIds changed relation id's |
|
381 */ |
|
382 void SetRelationsToNotPresentL(TUint32 aMediaId, |
|
383 RArray<TItemId>& aRelationIds); |
|
384 |
|
385 /** |
|
386 * Removes all file objects which has given media ID and are in not |
|
387 * present. |
|
388 * |
|
389 * @param aMediaId Memory card's media ID |
|
390 */ |
|
391 void RemoveFilesNotPresentL(TUint32 aMediaId, RArray<TItemId>* aObjectIds); |
|
392 |
|
393 /** |
|
394 * Get schema version from DB |
|
395 * @param aConnection The database connection |
|
396 * @param aMajorVersion schema major version |
|
397 * @param aMinorVersion schema minor version |
|
398 */ |
|
399 void GetSchemaVersionL(TInt& aMajorVersion, TInt& aMinorVersion); |
|
400 |
|
401 /** |
|
402 * Set object to "present" state bu GUID |
|
403 * |
|
404 * @leave KErrNotFound MdE can't find object in "not present" state |
|
405 * with matching GUID |
|
406 */ |
|
407 void SetObjectToPresentByGuidL( |
|
408 const TInt64& aGuidHigh, const TInt64& aGuidLow ); |
|
409 |
|
410 /** |
|
411 * Change path of objects, which match to the old path, to the new |
|
412 * path. |
|
413 * |
|
414 * @param aOldPath the old path |
|
415 * @param aNewPath the new path |
|
416 * @param aObjectIds IDs of the change objects |
|
417 */ |
|
418 void ChangePathL(const TDesC& aOldPath, const TDesC& aNewPath, |
|
419 RArray<TItemId>& aObjectIds); |
|
420 |
|
421 /** |
|
422 * Change C-drive media id and update it to all objects that have the old id. |
|
423 */ |
|
424 void ChangeMediaIdL(); |
|
425 |
|
426 /** |
|
427 * Get removed relation items |
|
428 * |
|
429 * @param aBuffer buffer to fill with returned items |
|
430 * @param aRemovedRelations removed relations |
|
431 * @param aAdditionalRemovedRelations possible additional removed relations |
|
432 */ |
|
433 void GetRemovedRelationItemsL( CMdCSerializationBuffer& aBuffer, |
|
434 const RArray<TItemId>& aRemovedRelations, |
|
435 const RArray<TItemId>& aAdditionalRemovedRelations ); |
|
436 |
|
437 /** |
|
438 * Set/reset "binary composing to file" pending flag to objects |
|
439 * |
|
440 * @param aObjectIds object IDs |
|
441 * @param aReset when EFalse flags are setted and when ETrue flags are |
|
442 * resetted |
|
443 */ |
|
444 void SetPendingL(const RArray<TItemId>& aObjectIds, TBool aReset); |
|
445 |
|
446 /** |
|
447 * Get count of objects with "binary composing to file" pending flag |
|
448 * |
|
449 * @param aObjectDefId object def ID |
|
450 * |
|
451 * @return if >= 0, object count is returned, otherwise error code is |
|
452 * returned |
|
453 */ |
|
454 TInt GetPendingCountL(TDefId aObjectDefId); |
|
455 |
|
456 /** |
|
457 * Get objects with "binary composing to file" pending flag |
|
458 * |
|
459 * @param aObjectDefId object def ID |
|
460 * @param aBufferSize maximum ID count of buffer |
|
461 * @param aObjectIds returned object IDs |
|
462 * |
|
463 * @return if > 0, there was not enough space in buffer, otherwise |
|
464 * error code is returned |
|
465 */ |
|
466 TInt GetPendingL(TDefId aObjectDefId, TInt aBufferSize, |
|
467 RArray<TItemId>& aObjectIds); |
|
468 |
|
469 protected: // personal methods |
|
470 |
|
471 /** |
|
472 * Add single property from aBuffer and adds it to proper clause and |
|
473 * row data. |
|
474 * |
|
475 * @param aBuffer serialized property |
|
476 * @param aObjectDef definition of current object |
|
477 * @param aBaseObjectClause clause describing base object |
|
478 * @param aObjectClause clause describing current object |
|
479 * @param aBaseObjectDataRow data row contains base object values |
|
480 * @param aObjectDataRow data row contains current object values |
|
481 * @return new property definition |
|
482 */ |
|
483 const CMdsPropertyDef& ReadPropertyL( |
|
484 CMdCSerializationBuffer& aBuffer, |
|
485 const CMdsObjectDef& aObjectDef, |
|
486 CMdsClauseBuffer& aBaseObjectClause, |
|
487 CMdsClauseBuffer& aObjectClause, |
|
488 RRowData& aBaseObjectDataRow, RRowData& aObjectDataRow, |
|
489 TUint8& aFlags ); |
|
490 |
|
491 /** |
|
492 * Search in DB for freeText |
|
493 * |
|
494 * @param aFreeText freetext to search for |
|
495 * @return if find ETrue, else EFalse |
|
496 */ |
|
497 TItemId FindFreeTextInDbL( TPtrC16 aFreeText ); |
|
498 |
|
499 /** |
|
500 * Deletes BaseObject. |
|
501 */ |
|
502 TBool DoGarbageCollectionL(); |
|
503 |
|
504 private: // Member data |
|
505 struct TLockBuffer |
|
506 { |
|
507 CMdsClauseBuffer* iBuffer; |
|
508 TBool iLock; |
|
509 }; |
|
510 |
|
511 TRequestStatus iTextSearcherDeleteFreeTextStatus; |
|
512 |
|
513 TItemId iTextSearcherDeleteFreeTextObjectId; |
|
514 |
|
515 TRequestStatus iTextSearcherAddFreeTextStatus; |
|
516 |
|
517 TItemId iTextSearcherAddFreeTextObjectId; |
|
518 |
|
519 TItemId iCreationEventId; |
|
520 |
|
521 TItemId iDeletionEventId; |
|
522 |
|
523 /** |
|
524 * pointer to actual processing namespace |
|
525 */ |
|
526 const CMdsNamespaceDef* iNamespaceDef; |
|
527 |
|
528 /** |
|
529 * common usage buffers (initial size = 1024) |
|
530 * NOT THREAD SAFE! |
|
531 */ |
|
532 RArray<TLockBuffer> iBuffers; |
|
533 |
|
534 /** |
|
535 * BaseObject definition, used in addobject and addproperty |
|
536 */ |
|
537 const CMdsObjectDef* iBaseObjectDef; |
|
538 |
|
539 /** |
|
540 * Store every namespace read from schema file. |
|
541 */ |
|
542 const CMdsSchema& iSchema; |
|
543 |
|
544 /** |
|
545 * guid generator |
|
546 */ |
|
547 CMdSIdentifierGenerator* iGenerator; |
|
548 |
|
549 CMdSObjectLockList& iLockList; |
|
550 |
|
551 TBuf<256> iLastAddedObjName; |
|
552 |
|
553 private: |
|
554 class RClauseBuffer |
|
555 // NOT THREAD SAFE !!!!! |
|
556 { |
|
557 public: |
|
558 RClauseBuffer(CMdSSqlObjectManipulate& aSOM, TInt aSize = 1024); |
|
559 |
|
560 CMdsClauseBuffer& BufferL(); |
|
561 |
|
562 void Close(); |
|
563 |
|
564 private: |
|
565 RArray<TLockBuffer>& iBuffers; |
|
566 CMdsClauseBuffer* iBuffer; |
|
567 TInt iNr; |
|
568 const TInt iSize; |
|
569 }; |
|
570 }; |
|
571 |
|
572 #include "mdssqlobjectmanipulate.inl" |
|
573 |
|
574 #endif // __MDSSQLOBJECTMANIPULATE_H__ |