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.
18 // Class CDbStoreIndex::CRecover
20 NONSHARABLE_CLASS(CDbStoreIndex::CRecover) : public CDbTableDatabase::CStepper
25 CRecover(CDbStoreDatabase& aDatabase,const CDbStoreDef& aTable,const CDbStoreIndexDef& anIndex);
27 static inline TInt Steps(TInt aCardinality);
29 TInt StepL(TInt aStep);
31 CDbStoreDatabase& iDatabase;
32 const CDbStoreDef& iTable;
33 const CDbStoreIndexDef& iIndex;
34 CDbTableDatabase::CBuildIndex* iBuild;
37 inline TInt CDbStoreIndex::CRecover::Steps(TInt aCardinality)
38 {return CDbTableDatabase::CBuildIndex::Steps(aCardinality)+EClearStep;}
40 CDbStoreIndex::CRecover::CRecover(CDbStoreDatabase& aDatabase,const CDbStoreDef& aTable,const CDbStoreIndexDef& anIndex)
41 : iDatabase(aDatabase),iTable(aTable),iIndex(anIndex)
44 CDbStoreIndex::CRecover::~CRecover()
49 TInt CDbStoreIndex::CRecover::StepL(TInt aStep)
53 iBuild=CDbTableDatabase::CBuildIndex::NewL(iDatabase,iTable,iIndex);
54 ((CDbStoreIndex&)iBuild->Index()).DiscardL();
55 return aStep-EClearStep;
57 aStep=iBuild->StepL(aStep);
60 iDatabase.IndexRecoveredL();
67 // Class CDbStoreIndex::CRepair
69 NONSHARABLE_CLASS(CDbStoreIndex::CRepair) : public CDbTableDatabase::CStepper
74 CRepair(CDbStoreDatabase& aDatabase,const CDbStoreDef& aTable,const CDbStoreIndexDef& anIndex);
75 static inline TInt Steps();
77 TInt StepL(TInt aStep);
79 CDbStoreDatabase& iDatabase;
80 const CDbStoreDef& iTable;
81 const CDbStoreIndexDef& iIndex;
84 inline TInt CDbStoreIndex::CRepair::Steps()
87 CDbStoreIndex::CRepair::CRepair(CDbStoreDatabase& aDatabase,const CDbStoreDef& aTable,const CDbStoreIndexDef& anIndex)
88 : iDatabase(aDatabase),iTable(aTable),iIndex(anIndex)
91 TInt CDbStoreIndex::CRepair::StepL(TInt)
93 CDbStoreIndex* index=CDbStoreIndex::NewL(iDatabase,iIndex,iTable);
94 CleanupStack::PushL(index);
97 CleanupStack::PopAndDestroy();
101 // Class CDbStoreDatabase
103 CDbTableDatabase::CStepper* CDbStoreDatabase::RecoverL(TInt& aStep)
105 TSglQueIterC<CDbStoreDef> iter(SchemaL()); // ensure we have the schema
107 const CDbStoreDef* tDef;
108 while ((tDef=iter++)!=NULL)
109 count+=tDef->Indexes().Count();
110 CMultiStepper* mStepper=CMultiStepper::NewL(count);
111 CleanupStack::PushL(mStepper);
112 // damaged ones first (as they are invoked last
115 while ((tDef=iter++)!=NULL)
117 TInt records=CDbStoreRecords::CardinalityL(Store(),*tDef);
118 TSglQueIterC<CDbStoreIndexDef> xIter(tDef->Indexes().AsQue());
119 for (const CDbStoreIndexDef* xDef;(xDef=xIter++)!=NULL;)
121 if (!CDbStoreIndex::IsDamagedL(*this,*xDef))
123 // rebuild from scratch
124 CDbStoreIndex::CRecover* rebuild=new(ELeave) CDbStoreIndex::CRecover(*this,*tDef,*xDef);
125 mStepper->AddStepper(rebuild,rebuild->Steps(records));
130 { // no indexes are actually damaged
132 CleanupStack::PopAndDestroy();
135 // repair the other ones after a reclaim
137 while ((tDef=iter++)!=NULL)
139 TSglQueIterC<CDbStoreIndexDef> xIter(tDef->Indexes().AsQue());
140 for (const CDbStoreIndexDef* xDef;(xDef=xIter++)!=NULL;)
142 if (CDbStoreIndex::IsDamagedL(*this,*xDef))
144 // repair from sequence set
145 CDbStoreIndex::CRepair* repair=new(ELeave) CDbStoreIndex::CRepair(*this,*tDef,*xDef);
146 mStepper->AddStepper(repair,repair->Steps());
149 iPagePool->Discard();
150 iPagePool->ReclaimAllL(); // recover all page pool space
151 aStep=mStepper->TotalSteps();