Update contrib.
     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".
 
     8 // Initial Contributors:
 
     9 // Nokia Corporation - initial contribution.
 
    16 #if !defined(__D32TABLE_H__)
 
    17 #define __D32TABLE_H__
 
    18 #if !defined(__D32DBAS_H__)
 
    21 #if !defined(__D32REC_H__)
 
    24 #if !defined(__D32CACHE_H__)
 
    28 // classes defined in this file
 
    29 class TDbGenerationMark;
 
    32 class CDbTableIndexDef;
 
    40 class CDbTableDatabase;
 
    42 // classes also referenced
 
    49 const TInt KDbTableMaxIndexes = 32;
 
    54 class CDbTableIndexDef : public CBase
 
    56 	friend class RDbIndexes;
 
    58 	IMPORT_C CDbTableIndexDef();
 
    59 	IMPORT_C ~CDbTableIndexDef();
 
    60 	IMPORT_C void ConstructL( const TDesC& aName );
 
    61 	inline const TDesC& Name() const;
 
    62 	inline const CDbKey& Key() const;
 
    75 	friend class CDbTableDef;
 
    77 	inline void Add( CDbTableIndexDef* aDef );
 
    78 	inline void Remove( CDbTableIndexDef* aDef );
 
    79 	inline const TSglQueBase& AsQue() const;
 
    80 	CDbTableIndexDef* Find( const TDesC& aName ) const;
 
    81 	CDbTableIndexDef& FindL( const TDesC& aName ) const;
 
    82 	IMPORT_C TInt Count() const;
 
    87 	TSglQue<CDbTableIndexDef> iRep;
 
    96 	IMPORT_C void SetL( const TDbCol& aCol );
 
    97 	IMPORT_C void SetL( const TDbColumnDef& aCol );
 
    98 	void AsTDbCol( TDbCol& aColumn ) const;
 
    99 	inline TDbColType Type() const;
 
   101 // don't allow copies
 
   102 	void operator=( const TDbColumnDef& );
 
   104 	// flags used by AlterTable
 
   105 	enum { EDropped = 0x1, EChangedType = 0x2, EChangedLen = 0x4, EAdded = 0x8 };
 
   121 	enum { ELongColumns = 0x1, EAutoIncrement = 0x2 };
 
   123 	typedef TDbColumnDef* TIterator;
 
   124 	typedef const TDbColumnDef* TIteratorC;
 
   126 	static HDbColumnSet* NewL( TInt aCount );
 
   129 	inline TIterator Begin();
 
   131 	IMPORT_C TInt Count() const;
 
   132 	inline TIteratorC Begin() const;
 
   133 	inline TIteratorC End() const;
 
   134 	inline const TDbColumnDef& operator[]( TDbColNo anIndex ) const;
 
   135 	IMPORT_C TIteratorC ColumnL( const TDesC& aColumn ) const;
 
   136 	inline TIterator ColumnL( const TDesC& aColumn );
 
   137 	IMPORT_C TDbColNo ColNoL( const TDesC& aColumn ) const;
 
   138 	inline TBool HasLongColumns() const;
 
   139 	inline TBool HasAutoIncrement() const;
 
   141 	HDbColumnSet( TInt aCount );
 
   142 	const TIteratorC* IndexL() const;
 
   146 	const TDbColumnDef* const iEnd;
 
   147 	TDbColumnDef iColumns[1];		// at least one
 
   153 class CDbTableDef : public CBase
 
   155 	friend class RDbTableSchema;
 
   157 	IMPORT_C ~CDbTableDef();
 
   158 	inline const TDesC& Name() const;
 
   159 	inline HDbColumnSet& Columns();
 
   160 	inline const HDbColumnSet& Columns() const;
 
   161 	inline RDbIndexes& Indexes();
 
   162 	inline const RDbIndexes& Indexes() const;
 
   163 	IMPORT_C virtual void Changed();
 
   165 	inline const CDbTableIndexDef* Key( const TDesC& aColumn ) const;
 
   166 	inline TBool IsIndexed( const TDesC& aColumn ) const;
 
   168 	virtual void AlteredColumnSetL( HDbColumnSet& aSet, const CDbColSet& aChange, const CDbColSet& aAdd ) = 0;
 
   169 	void ExchangeColumnSet( HDbColumnSet* aSet );
 
   171 	IMPORT_C CDbTableDef();
 
   172 	IMPORT_C void ConstructL( const TDesC& aName, TInt aColumnCount );
 
   174 	const CDbTableIndexDef* FindKey( const TDesC& aColumn, TBool aFirstColumn ) const;
 
   178 	HDbColumnSet* iColumns;
 
   187 	friend class CDbTableDatabase;
 
   189 	inline void Loaded();
 
   190 	inline operator TSglQueBase&();
 
   191 	inline void Add( CDbTableDef* aDef );
 
   193 	inline TBool IsEmpty() const;
 
   194 	CDbTableDef* Find( const TDesC& aTable );
 
   195 	CDbTableDef& FindL( const TDesC& aTable );
 
   197 	inline RDbTableSchema();
 
   200 	inline TBool IsLoaded() const;
 
   202 	inline void Remove( CDbTableDef* aDef );
 
   204 	TSglQue<CDbTableDef> iRep;
 
   211 typedef TUint TDbGeneration;
 
   216 class TDbGenerationMark
 
   219 	inline void Construct( const TDbGeneration& aGeneration );
 
   221 	inline TBool Changed() const;
 
   223 	const TDbGeneration* iGeneration;
 
   230 class CDbTable : public CBase
 
   232 	friend class RDbTables;
 
   236 	enum { EUnavailableSpan = -1, EFullIndexSpan = 100 };
 
   238 	IMPORT_C CDbTable( CDbTableDatabase& aDatabase, const CDbTableDef& aDef );
 
   239 	IMPORT_C ~CDbTable();
 
   248 	inline TBool IsActive() const;
 
   249 	inline TBool IsIdle() const;
 
   250 	inline const CDbTableDef& Def() const;
 
   251 	inline CDbTableDatabase& Database();
 
   253 	inline const TDbGeneration& Generation() const;
 
   254 	TBool ExistsL( TDbRecordId aRecordId );
 
   255 	void NewRowL( RDbRow& aRow );
 
   256 	void ReadRowL( RDbRow& aRow, TDbRecordId aRecordId );
 
   257 	void PrepareReplaceL( const RDbTableRow& aRow, TDbRecordId aRecordId );
 
   258 	void ReplaceRowL( RDbTableRow& aRow, TDbRecordId aRecordId );
 
   259 	void PrepareAppendL( const RDbTableRow& aRow );
 
   260 	TDbRecordId AppendRowL( const RDbTableRow& aRow );
 
   261 	void DeleteRowL( RDbTableRow& aRow, TDbRecordId aRecordId );
 
   262 	void DuplicateBlobsL( RDbRow& aRow );
 
   263 	IMPORT_C void DiscardBlobsL( RDbRow& aRow );
 
   265 	IMPORT_C CDbRecordSpace& RecordsL();
 
   266 	IMPORT_C CDbRecordIndex& IndexL( const CDbTableIndexDef& anIndex );
 
   267 	IMPORT_C CDbBlobSpace* BlobsL();
 
   268 	virtual CDbRecordIndex* RecordIndexL( const CDbTableIndexDef& anIndex ) = 0;
 
   270 	CDbRecordIter* IteratorL();
 
   271 	IMPORT_C virtual TInt IndexSpanL( const CDbTableIndexDef& aIndex, TUint aInclusion, const TDbLookupKey* aLowerBound, const TDbLookupKey* aUpperBound );
 
   272 	CDbRecordIter* IteratorL( const CDbTableIndexDef& aIndex, TUint aInclusion = 0, const TDbLookupKey* aLowerBound = 0, const TDbLookupKey* aUpperBound = 0 );
 
   273 	CDbRecordIter* IteratorL( const TDesC& aIndex );
 
   275 	typedef void ( *TBlobFuncL )( CDbBlobSpace& aBlobStore, TDbBlob& aBlob, TDbColType aType, CDbBlobCleanup* aCleanup );
 
   277 	inline void Discard();
 
   279 	inline TBool InUse() const;
 
   280 	inline RDbCache& Cache();
 
   282 	void ApplyToBlobsL( RDbRow& aRow, TBlobFuncL aFuncL, CDbBlobCleanup* aCleanup = 0 );
 
   283 	void ApplyToComponentsL( void ( *anOperationL )( CDbRecordBase* ) );
 
   284 	void EnsureIndexesL();
 
   285 	void ValidateL( const RDbRow& aRow );
 
   286 	void CheckInliningL( RDbRow& aRow );
 
   287 	void DoReplaceRowL( const RDbRow& aRow, TDbRecordId aRecordId );
 
   289 	virtual CDbRecordSpace* RecordSpaceL() = 0;
 
   290 	virtual CDbBlobSpace* BlobSpaceL() = 0;
 
   292 	virtual void CopyToRowL( RDbRow& aRow, const TDesC8& aRecord ) = 0;
 
   293 	virtual TInt RecordLength( const RDbRow& aRow ) = 0;
 
   294 	virtual void CopyFromRow( TUint8* aRecord, const RDbRow& aRow ) = 0;
 
   296 	enum { EIdle = -1, ECached = -2 };
 
   300 	CDbTableDatabase* iDatabase;
 
   301 	const CDbTableDef* iDef;
 
   302 	TDbGeneration iGeneration;
 
   303 	CDbRecordSpace* iRecords;
 
   304 	CDbBlobSpace* iBlobs;
 
   305 	CDbRecordIndex* iIndexes[KDbTableMaxIndexes];
 
   306 	CDbRecordIndex** iIndexesEnd;
 
   313 class RDbTableRow : public RDbRow
 
   316 	inline RDbTableRow();
 
   317 	void Open( CDbTable* aTable );
 
   320 	inline CDbTable& Table() const;
 
   321 	IMPORT_C void ReadL( TDbRecordId aRecordId );
 
   322 	void NewL( TDbRecordId aCopyRecord );
 
   323 	void PrepareAppendL();
 
   324 	TDbRecordId AppendL();
 
   325 	void PrepareReplaceL();
 
   326 	TDbRecordId ReplaceL();
 
   327 	void DeleteL( TDbRecordId aRecordId );
 
   329 	TDbGenerationMark iMark;
 
   344 	inline TBool IsEmpty() const;
 
   345 	inline void Add( CDbTable& aTable );
 
   346 	inline void Remove( CDbTable& aTable );
 
   347 	CDbTable* Find( const TDesC& aTable );
 
   348 	inline operator TSglQueBase&();
 
   350 	TSglQue<CDbTable> iRep;
 
   356 enum TDbLockType { EDbReadLock = 0, EDbXReadLock, EDbWriteLock, EDbCompactLock, EDbRecoveryLock, EDbSchemaLock };
 
   366 	friend class CNotifier;
 
   368 	inline RDbTransaction();
 
   369 	inline void Open( CDbTableDatabase& aDatabase );
 
   372 	inline const TDbGeneration& RollbackGeneration() const;
 
   373 	inline CDbTableDatabase& Database();
 
   375 	void BeginL( const CDbObject& aObject );
 
   376 	void CommitL( const CDbObject& aObject );
 
   377 	void Rollback( const CDbObject& aObject );
 
   379 	void ReadPrepareL( const CDbObject& aObject );
 
   380 	void ReadBegin( const CDbObject& aObject );
 
   381 	void ReadRelease( const CDbObject& aObject );
 
   384 	void DMLPrepareL( const CDbObject& aObject );
 
   391 	void DDLPrepareL( const CDbObject& aObject );
 
   397 	void UtilityPrepareL( const CDbObject& aObject );
 
   398 	void UtilityBegin( CDbDatabase::TUtility aType );
 
   399 	void UtilityCommitL();
 
   400 	void UtilityRollback();
 
   402 	inline TBool IsLocked() const;
 
   403 	inline void ReadyL() const;
 
   404 	TBool InTransaction( const CDbObject& aObject );
 
   406 	CDbNotifier* NotifierL();
 
   408 	void _Invariant() const;
 
   411 	typedef const CDbContext* THolder;
 
   417 	enum { ELockListGranularity = 4 };
 
   418 	enum { ETransactionLock = 0x80000000 };
 
   419 	enum { EState = 0x7f, EFailed = 0x80 };
 
   420 	enum { EMaxLock = 255 };
 
   422 	inline TDbLockType LockState() const;
 
   423 	void PrepareSLockL( const CDbObject& aObject, TUint aInitState );
 
   424 	void PrepareXLockL( const CDbObject& aObject );
 
   425 	void Unlock( RDbNotifier::TEvent aEvent );
 
   426 	void Unlock( TLock& aLock );
 
   427 	TLock* GetLock( const CDbObject& aObject );
 
   428 	void Event( RDbNotifier::TEvent aEvent );
 
   432 	static void DMLAbandon( TAny* aPtr );
 
   433 	static void DDLAbandon( TAny* aPtr );
 
   435 	CDbTableDatabase* iDatabase;
 
   443 	TDbGeneration iRollback;
 
   444 	CNotifier* iNotifier;
 
   450 class CDbTableDatabase : public CBase
 
   454 	class CIncrementalDDL;
 
   463 	friend class RDbTransaction;
 
   464 	friend class CInterface;
 
   465 	friend class CSource;
 
   466 	friend class CDbTable;
 
   467 	friend class CIncremental;
 
   472 	class CStepper : public CBase
 
   477 		virtual TInt StepL( TInt aStep ) = 0;
 
   483 	class CMultiStepper : public CStepper
 
   493 		IMPORT_C static CMultiStepper* NewL( TInt aStepperCount );
 
   494 		IMPORT_C void AddStepper( CStepper* aStepper, TInt aSteps );
 
   495 		IMPORT_C TInt TotalSteps();
 
   496 		TInt StepL( TInt aStep );
 
   498 		inline CMultiStepper( TInt aStepperCount );
 
   502 		SStepper iSteppers[1];		// one or more
 
   508 	class CBuildIndex : public CStepper
 
   511 		enum { ERecordsPerStep = 16 };
 
   513 		IMPORT_C static CBuildIndex* NewL( CDbTableDatabase& aDatabase, const CDbTableDef& aTable, const CDbTableIndexDef& anIndex );
 
   515 		IMPORT_C static TInt Steps( TInt aCardinality );
 
   516 		inline CDbRecordIndex& Index();
 
   517 		IMPORT_C TInt StepsL();
 
   519 		TInt StepL( TInt aStep );
 
   523 		CDbTableSource* iSource;
 
   525 		CDbRecordIndex* iIndex;
 
   528 	IMPORT_C CDbTableDatabase();
 
   529 	IMPORT_C ~CDbTableDatabase();
 
   531 	inline RDbTransaction& Transaction();
 
   533 	IMPORT_C CDbDatabase* InterfaceL();
 
   534 	IMPORT_C CDbSource* SourceL();
 
   536 	inline RDbTableSchema& Schema();
 
   537 	IMPORT_C RDbTableSchema& SchemaL();
 
   539 	CDbTableSource* TableSourceL( const TDesC& aTableName );
 
   540 	void Release( const CDbTableDef& aDef );
 
   541 // framework functions
 
   542 	virtual CStepper* TableAlterL( CDbTableDef& aTable, const HDbColumnSet& aNewSet, TInt& aStep ) = 0;
 
   543 	virtual CStepper* RecordDiscarderL( const CDbTableDef& aTable, TInt& aStep ) = 0;
 
   544 	virtual CStepper* IndexDiscarderL( const CDbTableDef& aTable, const CDbTableIndexDef& anIndex, TInt& aStep ) = 0;
 
   545 	IMPORT_C virtual CStepper* UtilityL( CDbDatabase::TUtility aType, TInt& aStep );
 
   548 	IMPORT_C virtual TInt Property( CDbDatabase::TProperty aProperty );
 
   551 	virtual void AuthenticateL() = 0;
 
   552 	IMPORT_C virtual void Idle();
 
   553 	virtual void LoadSchemaL() = 0;
 
   554 	virtual void SynchL( TDbLockType aLock ) = 0;
 
   555 	virtual void Revert( TDbLockType aLock ) = 0;
 
   556 	virtual CDbTable* TableL( const CDbTableDef& aDef ) = 0;
 
   557 	virtual CDbTableDef* CreateTableL( const TDesC& aName, const CDbColSet& aColSet, const CDbKey* aPrimaryKey ) = 0;
 
   558 	virtual CDbTableIndexDef* CreateIndexL( const CDbTableDef& aTable, const TDesC& aName, const CDbKey& aKey ) = 0;
 
   559 	virtual void DestroyL() = 0;
 
   563 	inline void AddTable( CDbTable& aTable );
 
   564 	void RemoveTable( CDbTable& aTable );
 
   567 	void FlushL( TDbLockType aLock );
 
   568 	void Abandon( TDbLockType aLock );
 
   571 	void DoCreateTableL( const TDesC& aName, const CDbColSet& aColSet, const CDbKey* aPrimaryKey );
 
   572 	CIncremental* OpenCreateIndexL( const TDesC& aName, const TDesC& aTable, const CDbKey& aKey, TInt& aStep );
 
   573 	CIncremental* OpenDropIndexL( const TDesC& aName, const TDesC& aTable, TInt& aStep );
 
   574 	CIncremental* OpenDropTableL( const TDesC& aTable, TInt& aStep );
 
   575 	CIncremental* OpenAlterTableL( const TDesC& aTable, const CDbColSet& aNewDef, TInt& aStep );
 
   576 	CDbCursor* PrepareViewL( const TDbQuery& aQuery, const TDbWindow& aWindow, RDbRowSet::TAccess anAccess );
 
   577 	CDbCursor* PrepareTableL( const TDesC& aTable, RDbRowSet::TAccess anAccess );
 
   578 // reserved virtual function space
 
   579 	IMPORT_C virtual void Reserved_1();
 
   580 	IMPORT_C virtual void Reserved_2();
 
   584 	RDbTransaction iTransaction;
 
   585 	RDbTableSchema iSchema;
 
   589 #include "D32TABLE.INL"