|
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "U32STD.H" |
|
17 #include "D32REC.H" |
|
18 #include "D32STOR.H" |
|
19 #include <s32buf.h> |
|
20 #include <s32crypt.h> |
|
21 #include <s32btree.h> |
|
22 #include <s32ucmp.h> |
|
23 #include <e32hal.h> |
|
24 #include <e32math.h> |
|
25 |
|
26 // classes defined |
|
27 class TDbStoreIndexStats; |
|
28 class CDbStoreIndexDef; |
|
29 class TRecordSize; |
|
30 class CDbStoreDef; |
|
31 class RClusterMap; |
|
32 class TClusterLinkCache; |
|
33 struct TClusterDes; |
|
34 class CCluster; |
|
35 class CClusterCache; |
|
36 class CDbStoreRecords; |
|
37 class CDbStoreBlobs; |
|
38 class CDbStoreIndex; |
|
39 class CDbStoreTable; |
|
40 class RDbStoreReadStream; |
|
41 class RDbStoreWriteStream; |
|
42 class MDbStreamFilter; |
|
43 class CDbStoreCompression; |
|
44 |
|
45 /** |
|
46 @internalComponent |
|
47 */ |
|
48 enum TStorePanic |
|
49 { |
|
50 EDbUnimplemented, |
|
51 EDbNoStore, |
|
52 EDbCannotSeek, |
|
53 EDbNotFixedFieldType, |
|
54 EDbWrongType |
|
55 }; |
|
56 |
|
57 /** |
|
58 @internalComponent |
|
59 */ |
|
60 GLREF_C void Panic(TStorePanic aPanic); |
|
61 |
|
62 /** |
|
63 @internalComponent |
|
64 */ |
|
65 GLREF_D const TDbDriver KBuiltinDriver; |
|
66 |
|
67 /** |
|
68 @internalComponent |
|
69 */ |
|
70 const TUid KDbmsStoreDatabase={268435561}; |
|
71 |
|
72 /** |
|
73 @internalComponent |
|
74 */ |
|
75 const TInt KDbStoreMaxRecordLength=0x200A; // v5.10 32 nullable longtext columns |
|
76 const TInt KClusterLimit=0x1000; |
|
77 const TInt KMaxClustering=16; |
|
78 const TInt KBlobRefSize=sizeof(TDbBlobId)+sizeof(TInt32); |
|
79 const TInt KMinInlineLimit=16; |
|
80 const TInt KMaxIndexKeySize=248; |
|
81 |
|
82 /** |
|
83 @internalComponent |
|
84 */ |
|
85 class TDbStoreIndexStats |
|
86 { |
|
87 public: |
|
88 /** |
|
89 @internalComponent |
|
90 */ |
|
91 class TBound |
|
92 { |
|
93 public: |
|
94 inline void Set(TReal64 aBound); |
|
95 void Set(const TInt64& aBound); |
|
96 void Set(const TText8* aPtr,TInt aLen,const TTextOps& aConv); |
|
97 void Set(const TText16* aPtr,TInt aLen,const TTextOps& aConv); |
|
98 void Set(const TDbLookupKey::SColumn& aBound,const TTextOps& aConv); |
|
99 public: |
|
100 TReal64 iValue; |
|
101 }; |
|
102 enum TType {EContinuous,EDiscrete}; |
|
103 public: |
|
104 inline TDbStoreIndexStats(); |
|
105 // |
|
106 void InternalizeL(RReadStream& aStream); |
|
107 void ExternalizeL(RWriteStream& aStream) const; |
|
108 // |
|
109 inline void Reset(TInt aCardinality=0); |
|
110 inline void Inc(); |
|
111 inline void Dec(); |
|
112 inline void Refresh(TType aType); |
|
113 // |
|
114 inline TBool IsValid() const; |
|
115 inline TBool NeedsRefresh() const; |
|
116 inline TInt Cardinality() const; |
|
117 TInt Span(TUint aInclusion,const TDbLookupKey* aLower,const TDbLookupKey* aUpper,const TTextOps& aConv) const; |
|
118 private: |
|
119 inline void Touch(); |
|
120 TInt ReverseSpan(TUint aInclusion,const TDbLookupKey* aLower,const TDbLookupKey* aUpper,const TTextOps& aConv) const; |
|
121 private: |
|
122 enum {ERefreshFactor=3}; |
|
123 enum {EInvalid=-1,ERefresh=0}; |
|
124 enum {ERefreshShift=2+ERefreshFactor,EFlagsMask=(1<<ERefreshShift)-1}; |
|
125 enum {EFlgDiscrete=0x1,EFlgClustering=0x2}; |
|
126 private: |
|
127 TInt iCardinality; |
|
128 TInt iRefresh; |
|
129 TUint iFlags; |
|
130 public: |
|
131 TBound iLower; |
|
132 TBound iUpper; |
|
133 }; |
|
134 |
|
135 /** |
|
136 @internalComponent |
|
137 */ |
|
138 class CDbStoreIndexDef : public CDbTableIndexDef |
|
139 { |
|
140 public: |
|
141 static CDbStoreIndexDef* NewLC(const TDesC& aName,const CDbKey& aKey,const HDbColumnSet& aColumns); |
|
142 static CDbStoreIndexDef* NewL(RReadStream& aStream); |
|
143 void ExternalizeL(RWriteStream& aStream) const; |
|
144 inline void SetTokenId(TStreamId anId); |
|
145 inline TStreamId TokenId() const; |
|
146 // |
|
147 static TInt KeySize(const TDbKeyCol& aKeyCol,const TDbColumnDef& aColumn); |
|
148 static void CheckSizeL(const CDbKey& aKey,const HDbColumnSet& aColSet); |
|
149 private: |
|
150 CDbStoreIndexDef(); |
|
151 static CDbStoreIndexDef* NewLC(const TDesC& aName); |
|
152 private: |
|
153 TStreamId iTokenId; |
|
154 public: |
|
155 __MUTABLE TDbStoreIndexStats iStats; // cache the statistics here |
|
156 }; |
|
157 |
|
158 /** |
|
159 @internalComponent |
|
160 */ |
|
161 class TRecordSize |
|
162 { |
|
163 public: |
|
164 TBool Set(const HDbColumnSet& aColumns); |
|
165 inline TInt Clustering() const; |
|
166 inline TInt InlineLimit() const; |
|
167 // |
|
168 static void CheckSizeL(const HDbColumnSet& aColumns); |
|
169 static TInt InlineLimit(const HDbColumnSet& aColumns); |
|
170 // |
|
171 static inline TInt FixedFieldSize(TDbColType aType); |
|
172 private: |
|
173 TInt iClustering; |
|
174 TInt iInlineLimit; |
|
175 private: |
|
176 static TUint8 const FieldSizes[]; |
|
177 }; |
|
178 |
|
179 /** |
|
180 @internalComponent |
|
181 */ |
|
182 NONSHARABLE_CLASS(CDbStoreDef) : public CDbTableDef |
|
183 { |
|
184 public: |
|
185 static CDbStoreDef* NewLC(const TDesC& aName,const CDbColSet& aColSet); |
|
186 static CDbStoreDef* NewL(RReadStream& aStream); |
|
187 void ExternalizeL(RWriteStream& aStream) const; |
|
188 inline void SetTokenId(TStreamId anId); |
|
189 inline TStreamId TokenId() const; |
|
190 inline TInt Clustering() const; |
|
191 inline TInt InlineLimit() const; |
|
192 void Changed(); |
|
193 private: |
|
194 void AlteredColumnSetL(HDbColumnSet& aSet,const CDbColSet& aChange,const CDbColSet& aAdd); |
|
195 protected: |
|
196 CDbStoreDef(); |
|
197 private: |
|
198 static CDbStoreDef* NewLC(const TDesC& aName,TInt aColumnCount); |
|
199 private: |
|
200 TStreamId iTokenId; |
|
201 TRecordSize iInfo; |
|
202 }; |
|
203 |
|
204 /** |
|
205 @internalComponent |
|
206 */ |
|
207 typedef TUint32 TClusterId; |
|
208 |
|
209 /** |
|
210 @internalComponent |
|
211 */ |
|
212 const TClusterId KNullClusterId=0; |
|
213 |
|
214 /** |
|
215 @internalComponent |
|
216 */ |
|
217 inline TClusterId ClusterId(TDbRecordId aRecordId); |
|
218 inline TInt RecordIndex(TDbRecordId aRecordId); |
|
219 inline TDbRecordId RecordId(TClusterId aId,TInt aIndex); |
|
220 inline TClusterId ClusterId(TStreamId aStreamId); |
|
221 |
|
222 /** |
|
223 @internalComponent |
|
224 */ |
|
225 class RClusterMap |
|
226 { |
|
227 private: |
|
228 enum {EGranularity=8}; |
|
229 class TIdPair |
|
230 { |
|
231 public: |
|
232 TClusterId iId; |
|
233 TClusterId iPreviousId; |
|
234 }; |
|
235 public: |
|
236 enum {ESeparation=16}; |
|
237 public: |
|
238 inline RClusterMap(); |
|
239 inline void Close(); |
|
240 // |
|
241 void ResetL(TClusterId aHeadCluster); |
|
242 inline void BindL(TClusterId aPrevious,TClusterId aCluster); |
|
243 void DropL(TClusterId aCluster,TClusterId aNext); |
|
244 TBool At(TClusterId aCluster,TClusterId& aPrevious); |
|
245 inline TClusterId LastBound() const; |
|
246 inline void Complete(TClusterId aLastCluster); |
|
247 inline TBool IsComplete() const; |
|
248 private: |
|
249 void AddL(TClusterId aCluster); |
|
250 void InsertL(TClusterId aCluster,TClusterId aPrevious); |
|
251 TIdPair* At(TClusterId aCluster); |
|
252 private: |
|
253 TIdPair* iMap; |
|
254 TInt iEntries; |
|
255 TInt iAlloc; |
|
256 TClusterId iLastBound; |
|
257 TClusterId iLastMapped; |
|
258 TInt iSkipped; |
|
259 TBool iComplete; |
|
260 }; |
|
261 |
|
262 /** |
|
263 @internalComponent |
|
264 */ |
|
265 class TClusterLinkCache |
|
266 { |
|
267 public: |
|
268 inline void Invalidate(); |
|
269 inline void Reset(TClusterId aBaseId); |
|
270 inline void Bind(TClusterId aPrevious,TClusterId aCluster,RClusterMap& aMap); |
|
271 void Add(const TClusterId* aFirst,const TClusterId* aLast); |
|
272 void Drop(TClusterId aCluster,TClusterId aNext); |
|
273 TBool Has(TClusterId aCluster) const; |
|
274 TBool At(TClusterId aCluster,TClusterId& aPrevious) const; |
|
275 private: |
|
276 void Add(TClusterId aCluster,RClusterMap& aMap); |
|
277 private: |
|
278 TClusterId iMap[RClusterMap::ESeparation+1]; |
|
279 TClusterId* iEnd; |
|
280 }; |
|
281 |
|
282 /** |
|
283 @internalComponent |
|
284 */ |
|
285 struct TClusterDes |
|
286 { |
|
287 public: |
|
288 void InternalizeL(RReadStream& aStream); |
|
289 void ExternalizeL(RWriteStream& aStream) const; |
|
290 public: |
|
291 TClusterId iNext; |
|
292 TUint32 iMembership; |
|
293 }; |
|
294 |
|
295 /** |
|
296 @internalComponent |
|
297 */ |
|
298 NONSHARABLE_CLASS(CCluster) : public CBase |
|
299 { |
|
300 friend class CClusterCache; |
|
301 private: |
|
302 enum {EGranularity=0x200}; |
|
303 enum {EExpandBuffer=0x40}; |
|
304 public: |
|
305 /** |
|
306 @internalComponent |
|
307 */ |
|
308 NONSHARABLE_CLASS(MAlter) |
|
309 { |
|
310 public: |
|
311 virtual TInt RecordExpansion(const TUint8* aRec,TInt aLength); |
|
312 virtual TUint8* AlterRecordL(TUint8* aWPtr,const TUint8* aRPtr,TInt aLength) =0; |
|
313 }; |
|
314 public: |
|
315 static CCluster* NewL(CDbStoreDatabase& aDatabase); |
|
316 ~CCluster(); |
|
317 // |
|
318 void FlushL(); |
|
319 void Discard(); |
|
320 // |
|
321 void Create(TClusterId aClusterId); |
|
322 void ReadL(TClusterId aCluster); |
|
323 void Relink(TClusterId aNextClusterId); |
|
324 void AlterL(MAlter& anAlterer); |
|
325 // |
|
326 TPtrC8 RecordL(TInt aIndex); |
|
327 TUint8* UpdateL(TInt aIndex,TInt aNewSize); |
|
328 TBool DeleteL(TInt aIndex); |
|
329 inline TBool IsFull() const; |
|
330 // |
|
331 inline TClusterId Id() const; |
|
332 inline const TClusterDes& Des() const; |
|
333 private: |
|
334 CCluster(CDbStoreDatabase& aDatabase); |
|
335 // |
|
336 TInt SetSizeL(TInt aSize); |
|
337 void AdjustMap(TUint8** aMapEntry,TInt aAdjust); |
|
338 void SetRecordL(TInt aIndex,TInt aNewSize); |
|
339 void AdjustL(TUint8** aMapEntry,TInt aAdjust,TUint8* aData); |
|
340 private: |
|
341 TDblQueLink iLink; |
|
342 CDbStoreDatabase& iDatabase; |
|
343 TInt iSize; |
|
344 TClusterId iCluster; |
|
345 TClusterDes iDes; |
|
346 TBool iModified; |
|
347 TUint8* iMap[KMaxClustering+1]; |
|
348 }; |
|
349 |
|
350 /** |
|
351 @internalComponent |
|
352 */ |
|
353 NONSHARABLE_CLASS(CClusterCache) : public CBase |
|
354 { |
|
355 #ifndef MAX_CLUSTER_CACHE_SIZE |
|
356 #define MAX_CLUSTER_CACHE_SIZE 8 |
|
357 #else |
|
358 #if MAX_CLUSTER_CACHE_SIZE < 4 |
|
359 #error "MAX_CLUSTER_CACHE_SIZE macro value can't be less than 4" |
|
360 #endif |
|
361 #endif |
|
362 enum {EMaxClusters=MAX_CLUSTER_CACHE_SIZE}; |
|
363 public: |
|
364 static CClusterCache* NewL(CDbStoreDatabase& aDatabase); |
|
365 ~CClusterCache(); |
|
366 // |
|
367 void FlushL(); |
|
368 void Discard(); |
|
369 // |
|
370 CCluster* Cluster(TClusterId aCluster); |
|
371 CCluster& ClusterL(TClusterId aCluster); |
|
372 CCluster& ClusterL(); |
|
373 // |
|
374 inline CDbStoreDatabase& Database(); |
|
375 inline CStreamStore& Store(); |
|
376 private: |
|
377 inline CClusterCache(CDbStoreDatabase& aDatabase); |
|
378 // |
|
379 void Apply(void (*aFunc)(CCluster*)); |
|
380 CCluster& AddClusterL(); |
|
381 CCluster& NewClusterL(); |
|
382 CCluster& Touch(CCluster& aCluster); |
|
383 private: |
|
384 CDbStoreDatabase& iDatabase; |
|
385 TClusterId iCachePlus1; |
|
386 TClusterId iCachePlus2; |
|
387 TUint8 iFollowOnHits; |
|
388 TUint8 iClusters; |
|
389 TDblQue<CCluster> iCache; |
|
390 }; |
|
391 |
|
392 /** |
|
393 @internalComponent |
|
394 */ |
|
395 NONSHARABLE_CLASS(CDbStoreRecords) : public CDbRecordSpace |
|
396 { |
|
397 public: |
|
398 class TIteratorC; |
|
399 class CIter; |
|
400 public: |
|
401 static TStreamId CreateL(CClusterCache& aCache); |
|
402 static CDbStoreRecords* NewL(CClusterCache& aCache,const CDbStoreDef& aDef); |
|
403 // |
|
404 static TInt CardinalityL(CStreamStore& aStore,const CDbStoreDef& aDef); |
|
405 // |
|
406 TBool GotoL(TDbPosition aPosition,TIteratorC& anIterator); |
|
407 TBool GotoL(TDbRecordId aRecordId,TIteratorC& anIterator); |
|
408 TBool DeletedL(TDbPosition aPosition,TIteratorC& anIterator); |
|
409 // |
|
410 inline TClusterId Head() const; |
|
411 inline TInt Count() const; |
|
412 TInt DiscardL(TClusterId& aCluster); |
|
413 TClusterId AlterL(TClusterId aCluster,CCluster::MAlter& anAlterer); |
|
414 void DestroyL(); |
|
415 // providing for CDbRecordSpace |
|
416 TBool ExistsL(TDbRecordId aRecordId); |
|
417 TPtrC8 ReadL(TDbRecordId aRecordId) const; |
|
418 TUint8* DoReplaceL(TDbRecordId aRecordId,TInt aRecordSize); |
|
419 TUint AutoIncrementL(); |
|
420 TUint8* DoNewL(TInt aRecordSize); |
|
421 TDbRecordId AppendL(); |
|
422 void DoEraseL(TDbRecordId aRecordId); |
|
423 CDbRecordIter* IteratorL(); |
|
424 TBool RestoreL(); |
|
425 void SynchL(); |
|
426 private: |
|
427 CDbStoreRecords(CClusterCache& aCache); |
|
428 ~CDbStoreRecords(); |
|
429 // |
|
430 TUint8* UpdateRecordL(TDbRecordId aRecordId,TInt aNewSize); |
|
431 void DesL(TClusterDes& aDes,TClusterId aCluster); |
|
432 void CompleteMapL(); |
|
433 TClusterId NextClusterL(TClusterDes& aDes,TClusterId aCluster); |
|
434 TClusterId PreviousClusterL(TClusterDes& aDes,TClusterId aCluster); |
|
435 TBool LocateL(TClusterId aCluster); |
|
436 private: |
|
437 class TToken |
|
438 { |
|
439 public: |
|
440 void InternalizeL(RReadStream& aStream); |
|
441 void ExternalizeL(RWriteStream& aStream) const; |
|
442 public: |
|
443 TClusterId iHead; |
|
444 TDbRecordId iNext; |
|
445 TInt iCount; |
|
446 TUint iAutoIncrement; |
|
447 }; |
|
448 private: |
|
449 CClusterCache& iCache; |
|
450 TStreamId iTokenId; |
|
451 TToken iToken; |
|
452 TInt iClustering; |
|
453 TClusterLinkCache iLinks; |
|
454 RClusterMap iMap; |
|
455 }; |
|
456 |
|
457 /** |
|
458 @internalComponent |
|
459 */ |
|
460 NONSHARABLE_CLASS(CDbStoreBlobs) : public CDbBlobSpace |
|
461 { |
|
462 public: |
|
463 CDbStoreBlobs(CDbStoreDatabase& aDatabase,TInt aInlineLimit); |
|
464 // |
|
465 MStreamBuf* DoCreateL(TDbBlobId &aBlobId,TDbColType aType); |
|
466 MStreamBuf* ReadL(TDbBlobId aBlobId,TDbColType aType) const; |
|
467 void DoDeleteL(TDbBlobId aBlobId); |
|
468 private: |
|
469 CDbStoreDatabase& iDatabase; |
|
470 }; |
|
471 |
|
472 /** |
|
473 @internalComponent |
|
474 */ |
|
475 NONSHARABLE_CLASS(CDbStoreIndex) : public CDbRecordIndex |
|
476 { |
|
477 public: |
|
478 class HKey; |
|
479 class HDupKey; |
|
480 class CIter; |
|
481 class CDiscarder; |
|
482 class CRecover; |
|
483 class CRepair; |
|
484 public: |
|
485 static CDbStoreIndex* NewL(CDbStoreDatabase& aDatabase,const CDbStoreIndexDef& aDef,const CDbTableDef& aTable); |
|
486 ~CDbStoreIndex(); |
|
487 // |
|
488 static TStreamId CreateL(CDbStoreDatabase& aDatabase,const CDbStoreIndexDef& aDef); |
|
489 static TBool IsDamagedL(CDbStoreDatabase& aDatabase,const CDbStoreIndexDef& aDef); |
|
490 // |
|
491 inline HKey& Key() const; |
|
492 inline const TBtree& Tree() const; |
|
493 inline TInt Count() const; |
|
494 void RepairL(); |
|
495 void DiscardL(); |
|
496 void DestroyL(); |
|
497 private: |
|
498 CDbStoreIndex(CDbStoreDatabase& aDatabase,const CDbStoreIndexDef& aDef); |
|
499 // |
|
500 void RefreshStatsL(); |
|
501 // CDbTableIndex framework |
|
502 TFind FindL(TDbRecordId aRecordId,const RDbTableRow& aRow); |
|
503 TBool DoInsertL(TDbRecordId aRecordId,const RDbTableRow& aRow); |
|
504 void DoDeleteL(TDbRecordId aRecordId,const RDbTableRow& aRow); |
|
505 CDbRecordIter* IteratorL(TUint aInclusion,const TDbLookupKey* aLowerBound,const TDbLookupKey* aUpperBound); |
|
506 TBool RestoreL(); |
|
507 void AboutToModifyL(); |
|
508 void SynchL(); |
|
509 private: |
|
510 CDbStoreDatabase& iDatabase; |
|
511 TStreamId iTokenId; |
|
512 TBtree iTree; |
|
513 HKey* iKey; |
|
514 TBtreeInlineLeafOrg iLeafOrg; |
|
515 TBtreeInlineIndexOrg iIndexOrg; |
|
516 TDbStoreIndexStats& iStats; |
|
517 }; |
|
518 |
|
519 /** |
|
520 @internalComponent |
|
521 */ |
|
522 NONSHARABLE_CLASS(CDbStoreIndex::CDiscarder) : public CDbTableDatabase::CStepper |
|
523 { |
|
524 public: |
|
525 CDiscarder(); |
|
526 ~CDiscarder(); |
|
527 TInt Open(CDbStoreIndex* anIndex); |
|
528 private: |
|
529 TInt StepL(TInt aStep); |
|
530 private: |
|
531 CDbStoreIndex* iIndex; |
|
532 }; |
|
533 |
|
534 /** |
|
535 @internalComponent |
|
536 */ |
|
537 NONSHARABLE_CLASS(CDbStoreTable) : public CDbTable |
|
538 { |
|
539 public: |
|
540 class CDiscarder; |
|
541 class CAlter; |
|
542 class CCompressor; |
|
543 friend class CDiscarder; |
|
544 friend class CAlter; |
|
545 friend class CCompressor; |
|
546 public: |
|
547 CDbStoreTable(CDbStoreDatabase& aDatabase,const CDbTableDef& aDef); |
|
548 private: |
|
549 inline const CDbStoreDef& Def() const; |
|
550 inline CDbStoreDatabase& Database(); |
|
551 inline CDbStoreRecords& StoreRecordsL(); |
|
552 // |
|
553 TInt RowSize(const TUint8* aRec,TInt aLength); |
|
554 const TUint8* CopyToRowL(TDbCell* aCell,TInt aSize,const TUint8* aRec); |
|
555 TUint8* AlterRecordL(TUint8* aWPtr,const TUint8* aRPtr,TInt aLength,TInt aInlineLimit); |
|
556 // providing for CDbTable framework |
|
557 TInt IndexSpanL(const CDbTableIndexDef& aIndex,TUint aInclusion,const TDbLookupKey* aLowerBound,const TDbLookupKey* aUpperBound); |
|
558 CDbRecordSpace* RecordSpaceL(); |
|
559 CDbBlobSpace* BlobSpaceL(); |
|
560 CDbRecordIndex* RecordIndexL(const CDbTableIndexDef& anIndex); |
|
561 void CopyToRowL(RDbRow& aRow,const TDesC8& aRecord); |
|
562 TInt RecordLength(const RDbRow& aRow); |
|
563 TInt OptimizedRowLength(const RDbRow& aRow); |
|
564 void CopyFromRow(TUint8* aRecord,const RDbRow& aRow); |
|
565 }; |
|
566 |
|
567 /** |
|
568 @internalComponent |
|
569 */ |
|
570 NONSHARABLE_CLASS(CDbStoreTable::CDiscarder) : public CDbTableDatabase::CStepper, public CCluster::MAlter |
|
571 { |
|
572 private: |
|
573 enum {EDiscardClusters=32,EBlobDiscardClusters=2}; |
|
574 public: |
|
575 CDiscarder(); |
|
576 ~CDiscarder(); |
|
577 TInt OpenL(CDbStoreTable* aTable); |
|
578 private: |
|
579 TInt StepL(TInt aStep); |
|
580 TUint8* AlterRecordL(TUint8* aWPtr,const TUint8* aRPtr,TInt aLength); |
|
581 private: |
|
582 CDbStoreTable* iTable; |
|
583 CDbStoreRecords* iRecords; |
|
584 TClusterId iCluster; |
|
585 RDbRow iRow; |
|
586 }; |
|
587 |
|
588 /** |
|
589 @internalComponent |
|
590 */ |
|
591 NONSHARABLE_CLASS(CDbStoreTable::CAlter) : public CDbTableDatabase::CStepper, public CCluster::MAlter |
|
592 { |
|
593 public: |
|
594 CAlter(); |
|
595 ~CAlter(); |
|
596 void OpenL(CDbStoreTable* aTable,const HDbColumnSet& aNewSet); |
|
597 private: |
|
598 TUint8* AlterRecordL(TUint8* aWPtr,const TUint8* aRPtr,TInt aLength); |
|
599 TInt RecordExpansion(const TUint8* aRec,TInt aLength); |
|
600 TInt StepL(TInt aStep); |
|
601 private: |
|
602 TInt iExpansion; |
|
603 TInt iInlineLimit; |
|
604 CDbStoreTable* iTable; |
|
605 CDbStoreRecords* iRecords; |
|
606 TClusterId iCluster; |
|
607 TInt iStep; |
|
608 }; |
|
609 |
|
610 /** |
|
611 @internalComponent |
|
612 */ |
|
613 class RDbStoreReadStream : public RStoreReadStream |
|
614 { |
|
615 public: |
|
616 enum TType {EMixed,EBinary,EText}; |
|
617 public: |
|
618 inline RDbStoreReadStream(CDbStoreDatabase& aDatabase) |
|
619 :iDatabase(aDatabase) |
|
620 {} |
|
621 void FilterL(TType aType,TUint32 aInit); |
|
622 private: |
|
623 CDbStoreDatabase& iDatabase; |
|
624 }; |
|
625 |
|
626 /** |
|
627 @internalComponent |
|
628 */ |
|
629 class RDbStoreWriteStream : public RStoreWriteStream |
|
630 { |
|
631 public: |
|
632 enum TType {EMixed,EBinary,EText}; |
|
633 public: |
|
634 inline RDbStoreWriteStream(CDbStoreDatabase& aDatabase) |
|
635 :iDatabase(aDatabase) |
|
636 {} |
|
637 void FilterL(TType aType,TUint32 aInit); |
|
638 private: |
|
639 CDbStoreDatabase& iDatabase; |
|
640 }; |
|
641 |
|
642 /** |
|
643 @internalComponent |
|
644 */ |
|
645 class MDbStreamFilter |
|
646 { |
|
647 public: |
|
648 virtual MStreamBuf* FilterL(MStreamBuf* aHost,TUint32 aInit,RDbStoreReadStream::TType aType) =0; |
|
649 virtual MStreamBuf* FilterL(MStreamBuf* aHost,TUint32 aInit,RDbStoreWriteStream::TType aType) =0; |
|
650 }; |
|
651 |
|
652 |
|
653 /** |
|
654 @internalComponent |
|
655 */ |
|
656 NONSHARABLE_CLASS(CDbStoreCompression) : public CBase, public MDbStreamFilter |
|
657 { |
|
658 public: |
|
659 /** |
|
660 @internalComponent |
|
661 */ |
|
662 class TEncoding |
|
663 { |
|
664 public: |
|
665 enum {ELiterals=256,ELengths=28,ESpecials=1,EDistances=44}; |
|
666 enum {ELitLens=ELiterals+ELengths+ESpecials}; |
|
667 enum {EEos=ELiterals+ELengths}; |
|
668 public: |
|
669 TUint32 iLitLen[ELitLens]; |
|
670 TUint32 iDistance[EDistances]; |
|
671 }; |
|
672 public: |
|
673 static CDbStoreCompression* NewL(); |
|
674 // |
|
675 void EncodeL(); |
|
676 inline void Inflate(); |
|
677 void ExternalizeL(RWriteStream& aStream) const; |
|
678 void InternalizeL(RReadStream& aStream); |
|
679 // for MDbStreamFilter |
|
680 MStreamBuf* FilterL(MStreamBuf* aHost,TUint32 aInit,RDbStoreReadStream::TType aType); |
|
681 MStreamBuf* FilterL(MStreamBuf* aHost,TUint32 aInit,RDbStoreWriteStream::TType aType); |
|
682 private: |
|
683 inline CDbStoreCompression(); |
|
684 private: |
|
685 enum TState {EAnalysis,EEncoding,EDecoding,EInflating}; |
|
686 private: |
|
687 TState iState; |
|
688 TEncoding iEncoding[3]; |
|
689 }; |
|
690 |
|
691 #include "US_STD.INL" |