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