11 // Contributors: |
11 // Contributors: |
12 // |
12 // |
13 // Description: |
13 // Description: |
14 // |
14 // |
15 |
15 |
16 #include "SqlAssert.h" |
16 #include "SqlPanic.h" |
17 #include "SqlCompact.h" |
17 #include "SqlCompact.h" |
18 #include "SqlCompactEntry.h" |
18 #include "SqlCompactEntry.h" |
19 #include "SqlCompactTimer.h" |
19 #include "SqlCompactTimer.h" |
20 #include "SqlUtil.h" |
20 #include "SqlUtil.h" |
21 #include "OstTraceDefinitions.h" |
|
22 #ifdef OST_TRACE_COMPILER_IN_USE |
|
23 #include "SqlCompactTraces.h" |
|
24 #endif |
|
25 #include "SqlTraceDef.h" |
|
26 |
21 |
27 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
22 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
28 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
23 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
29 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
24 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
30 |
25 |
41 /** |
36 /** |
42 CSqlCompactSettings invariant. |
37 CSqlCompactSettings invariant. |
43 */ |
38 */ |
44 void TSqlCompactSettings::Invariant() const |
39 void TSqlCompactSettings::Invariant() const |
45 { |
40 { |
46 __ASSERT_DEBUG(iStepLength > 0, __SQLPANIC(ESqlPanicInternalError)); |
41 __SQLASSERT(iStepLength > 0, ESqlPanicInternalError); |
47 __ASSERT_DEBUG(iFreePageThresholdKb >= 0, __SQLPANIC(ESqlPanicInternalError)); |
42 __SQLASSERT(iFreePageThresholdKb >= 0, ESqlPanicInternalError); |
48 } |
43 } |
49 #endif//_DEBUG |
44 #endif//_DEBUG |
50 |
45 |
51 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
46 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
52 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
47 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
75 @panic SqlDb 4 In _DEBUG mode. NULL aConnFactoryL. |
70 @panic SqlDb 4 In _DEBUG mode. NULL aConnFactoryL. |
76 @panic SqlDb 4 In _DEBUG mode. Zero or negative aCompactStepInterval. |
71 @panic SqlDb 4 In _DEBUG mode. Zero or negative aCompactStepInterval. |
77 */ |
72 */ |
78 CSqlCompactor* CSqlCompactor::NewL(TSqlCompactConnFactoryL aConnFactoryL, TInt aCompactStepInterval) |
73 CSqlCompactor* CSqlCompactor::NewL(TSqlCompactConnFactoryL aConnFactoryL, TInt aCompactStepInterval) |
79 { |
74 { |
80 __ASSERT_DEBUG(aConnFactoryL != NULL, __SQLPANIC2(ESqlPanicBadArgument)); |
75 __SQLASSERT(aConnFactoryL != NULL, ESqlPanicBadArgument); |
81 __ASSERT_DEBUG(aCompactStepInterval > 0, __SQLPANIC2(ESqlPanicBadArgument)); |
76 __SQLASSERT(aCompactStepInterval > 0, ESqlPanicBadArgument); |
82 CSqlCompactor* self = new (ELeave) CSqlCompactor(aConnFactoryL); |
77 CSqlCompactor* self = new (ELeave) CSqlCompactor(aConnFactoryL); |
83 CleanupStack::PushL(self); |
78 CleanupStack::PushL(self); |
84 self->ConstructL(aCompactStepInterval); |
79 self->ConstructL(aCompactStepInterval); |
85 CleanupStack::Pop(self); |
80 CleanupStack::Pop(self); |
86 return self; |
81 return self; |
137 @panic SqlDb 4 In _DEBUG mode. Too short or too long database name (aFullName parameter) |
132 @panic SqlDb 4 In _DEBUG mode. Too short or too long database name (aFullName parameter) |
138 @panic SqlDb 7 In _DEBUG mode. An entry with the specified name has been found but the entry is NULL. |
133 @panic SqlDb 7 In _DEBUG mode. An entry with the specified name has been found but the entry is NULL. |
139 */ |
134 */ |
140 void CSqlCompactor::AddEntryL(const TDesC& aFullName, const TSqlCompactSettings& aSettings) |
135 void CSqlCompactor::AddEntryL(const TDesC& aFullName, const TSqlCompactSettings& aSettings) |
141 { |
136 { |
142 __ASSERT_DEBUG(aFullName.Length() > 0 && aFullName.Length() <= KMaxFileName, __SQLPANIC(ESqlPanicBadArgument)); |
137 __SQLASSERT(aFullName.Length() > 0 && aFullName.Length() <= KMaxFileName, ESqlPanicBadArgument); |
143 SQLCOMPACTOR_INVARIANT(); |
138 SQLCOMPACTOR_INVARIANT(); |
144 CSqlCompactEntry* entry = NULL; |
139 CSqlCompactEntry* entry = NULL; |
145 TInt idx = iEntries.FindInOrder(aFullName, &CSqlCompactor::Search); |
140 TInt idx = iEntries.FindInOrder(aFullName, &CSqlCompactor::Search); |
146 if(idx == KErrNotFound) |
141 if(idx == KErrNotFound) |
147 { |
142 { |
148 SQL_TRACE_COMPACT(OstTraceExt4(TRACE_INTERNALS, CSQLCOMPACTOR_ADDENTRYL1, "0x%X;CSqlCompactor::AddEntryL;New entry;aFullName=%S;iStepLength=%d;iFreePageThreashold=%d", (TUint)this, __SQLPRNSTR(aFullName), aSettings.iStepLength, aSettings.iFreePageThresholdKb)); |
|
149 entry = CSqlCompactEntry::NewLC(aFullName, iConnFactoryL, aSettings, *iTimer); |
143 entry = CSqlCompactEntry::NewLC(aFullName, iConnFactoryL, aSettings, *iTimer); |
150 TLinearOrder<CSqlCompactEntry> order(&CSqlCompactor::Compare); |
144 TLinearOrder<CSqlCompactEntry> order(&CSqlCompactor::Compare); |
151 __SQLLEAVE_IF_ERROR(iEntries.InsertInOrder(entry, order)); |
145 __SQLLEAVE_IF_ERROR(iEntries.InsertInOrder(entry, order)); |
152 CleanupStack::Pop(entry); |
146 CleanupStack::Pop(entry); |
153 } |
147 } |
154 else |
148 else |
155 { |
149 { |
156 SQL_TRACE_COMPACT(OstTraceExt4(TRACE_INTERNALS, CSQLCOMPACTOR_ADDENTRYL2, "0x%X;CSqlCompactor::AddEntryL;Reuse entry;aFullName=%S;iStepLength=%d;iFreePageThreashold=%d", (TUint)this, __SQLPRNSTR(aFullName), aSettings.iStepLength, aSettings.iFreePageThresholdKb)); |
|
157 entry = iEntries[idx]; |
150 entry = iEntries[idx]; |
158 __ASSERT_DEBUG(entry != NULL, __SQLPANIC(ESqlPanicInternalError)); |
151 __SQLASSERT(entry != NULL, ESqlPanicInternalError); |
159 (void)entry->AddRef(); |
152 (void)entry->AddRef(); |
160 } |
153 } |
161 SQLCOMPACTOR_INVARIANT(); |
154 SQLCOMPACTOR_INVARIANT(); |
162 } |
155 } |
163 |
156 |
168 |
161 |
169 @param aFullName The full database name, including the path. |
162 @param aFullName The full database name, including the path. |
170 */ |
163 */ |
171 void CSqlCompactor::ReleaseEntry(const TDesC& aFullName) |
164 void CSqlCompactor::ReleaseEntry(const TDesC& aFullName) |
172 { |
165 { |
173 SQL_TRACE_COMPACT(OstTraceExt2(TRACE_INTERNALS, CSQLCOMPACTOR_RELEASEENTRY1, "0x%X;CSqlCompactor::ReleaseEntry;aFullName=%S", (TUint)this, __SQLPRNSTR(aFullName))); |
|
174 SQLCOMPACTOR_INVARIANT(); |
166 SQLCOMPACTOR_INVARIANT(); |
175 TInt idx = iEntries.FindInOrder(aFullName, &CSqlCompactor::Search); |
167 TInt idx = iEntries.FindInOrder(aFullName, &CSqlCompactor::Search); |
176 __ASSERT_DEBUG(idx >= 0, __SQLPANIC(ESqlPanicInternalError)); |
168 __SQLASSERT(idx >= 0, ESqlPanicInternalError); |
177 if(idx >= 0) |
169 if(idx >= 0) |
178 { |
170 { |
179 CSqlCompactEntry* entry = iEntries[idx]; |
171 CSqlCompactEntry* entry = iEntries[idx]; |
180 __ASSERT_DEBUG(entry != NULL, __SQLPANIC(ESqlPanicInternalError)); |
172 __SQLASSERT(entry != NULL, ESqlPanicInternalError); |
181 if(entry) |
173 if(entry) |
182 { |
174 { |
183 if(entry->Release() == 0) |
175 if(entry->Release() == 0) |
184 { |
176 { |
185 iEntries.Remove(idx); |
177 iEntries.Remove(idx); |
229 @param aFullName The full database name, including the path. |
221 @param aFullName The full database name, including the path. |
230 @param aEntry CSqlCompactor reference. |
222 @param aEntry CSqlCompactor reference. |
231 */ |
223 */ |
232 /* static */TInt CSqlCompactor::Search(const TDesC* aFullName, const CSqlCompactEntry& aEntry) |
224 /* static */TInt CSqlCompactor::Search(const TDesC* aFullName, const CSqlCompactEntry& aEntry) |
233 { |
225 { |
234 __ASSERT_DEBUG(&aEntry != NULL, __SQLPANIC2(ESqlPanicInternalError)); |
226 __SQLASSERT(&aEntry != NULL, ESqlPanicInternalError); |
235 __ASSERT_DEBUG(aFullName != NULL, __SQLPANIC2(ESqlPanicInternalError)); |
227 __SQLASSERT(aFullName != NULL, ESqlPanicInternalError); |
236 const TDesC& fullName = *aFullName; |
228 const TDesC& fullName = *aFullName; |
237 __ASSERT_DEBUG(fullName.Length() > 0 && fullName.Length() <= KMaxFileName, __SQLPANIC2(ESqlPanicInternalError)); |
229 __SQLASSERT(fullName.Length() > 0 && fullName.Length() <= KMaxFileName, ESqlPanicInternalError); |
238 __ASSERT_DEBUG(aEntry.FullName().Length() > 0 && aEntry.FullName().Length() <= KMaxFileName, __SQLPANIC2(ESqlPanicInternalError)); |
230 __SQLASSERT(aEntry.FullName().Length() > 0 && aEntry.FullName().Length() <= KMaxFileName, ESqlPanicInternalError); |
239 return fullName.CompareF(aEntry.FullName()); |
231 return fullName.CompareF(aEntry.FullName()); |
240 } |
232 } |
241 |
233 |
242 /** |
234 /** |
243 Static method used internally for performing a search in the container using a CSqlCompactEntry reference as a key. |
235 Static method used internally for performing a search in the container using a CSqlCompactEntry reference as a key. |
244 */ |
236 */ |
245 /* static */TInt CSqlCompactor::Compare(const CSqlCompactEntry& aLeft, const CSqlCompactEntry& aRight) |
237 /* static */TInt CSqlCompactor::Compare(const CSqlCompactEntry& aLeft, const CSqlCompactEntry& aRight) |
246 { |
238 { |
247 __ASSERT_DEBUG(&aLeft != NULL, __SQLPANIC2(ESqlPanicInternalError)); |
239 __SQLASSERT(&aLeft != NULL, ESqlPanicInternalError); |
248 __ASSERT_DEBUG(&aRight != NULL, __SQLPANIC2(ESqlPanicInternalError)); |
240 __SQLASSERT(&aRight != NULL, ESqlPanicInternalError); |
249 __ASSERT_DEBUG(aLeft.FullName().Length() > 0 && aLeft.FullName().Length() <= KMaxFileName, __SQLPANIC2(ESqlPanicInternalError)); |
241 __SQLASSERT(aLeft.FullName().Length() > 0 && aLeft.FullName().Length() <= KMaxFileName, ESqlPanicInternalError); |
250 __ASSERT_DEBUG(aRight.FullName().Length() > 0 && aRight.FullName().Length() <= KMaxFileName, __SQLPANIC2(ESqlPanicInternalError)); |
242 __SQLASSERT(aRight.FullName().Length() > 0 && aRight.FullName().Length() <= KMaxFileName, ESqlPanicInternalError); |
251 return aLeft.FullName().CompareF(aRight.FullName()); |
243 return aLeft.FullName().CompareF(aRight.FullName()); |
252 } |
244 } |
253 |
245 |
254 #ifdef _DEBUG |
246 #ifdef _DEBUG |
255 /** |
247 /** |
256 CSqlCompactor invariant. |
248 CSqlCompactor invariant. |
257 */ |
249 */ |
258 void CSqlCompactor::Invariant() const |
250 void CSqlCompactor::Invariant() const |
259 { |
251 { |
260 __ASSERT_DEBUG(iConnFactoryL != NULL, __SQLPANIC(ESqlPanicInternalError)); |
252 __SQLASSERT(iConnFactoryL != NULL, ESqlPanicInternalError); |
261 __ASSERT_DEBUG(iTimer != NULL, __SQLPANIC(ESqlPanicInternalError)); |
253 __SQLASSERT(iTimer != NULL, ESqlPanicInternalError); |
262 iTimer->Invariant(); |
254 iTimer->Invariant(); |
263 for(TInt idx=iEntries.Count()-1;idx>=0;--idx) |
255 for(TInt idx=iEntries.Count()-1;idx>=0;--idx) |
264 { |
256 { |
265 __ASSERT_DEBUG(iEntries[idx] != NULL, __SQLPANIC(ESqlPanicInternalError)); |
257 __SQLASSERT(iEntries[idx] != NULL, ESqlPanicInternalError); |
266 iEntries[idx]->Invariant(); |
258 iEntries[idx]->Invariant(); |
267 } |
259 } |
268 } |
260 } |
269 #endif//_DEBUG |
261 #endif//_DEBUG |