37 * Constructor for performing 1st stage construction |
37 * Constructor for performing 1st stage construction |
38 * @param session - initialized session to file system |
38 * @param session - initialized session to file system |
39 */ |
39 */ |
40 CAfStorage::CAfStorage(RFs& session) |
40 CAfStorage::CAfStorage(RFs& session) |
41 : |
41 : |
42 mFsSession(session) |
42 iFsSession(session) |
43 { |
43 { |
44 // No implementation required |
44 // No implementation required |
45 } |
45 } |
46 |
46 |
47 // ----------------------------------------------------------------------------- |
47 // ----------------------------------------------------------------------------- |
48 /** |
48 /** |
49 * Destructor. |
49 * Destructor. |
50 */ |
50 */ |
51 CAfStorage::~CAfStorage() |
51 CAfStorage::~CAfStorage() |
52 { |
52 { |
53 delete mDatabaseCleaner; |
53 delete iDatabaseCleaner; |
54 mActDb.Close(); |
54 iActDb.Close(); |
55 delete mFileStore; |
55 delete iFileStore; |
56 } |
56 } |
57 |
57 |
58 // ----------------------------------------------------------------------------- |
58 // ----------------------------------------------------------------------------- |
59 /** |
59 /** |
60 * Two-phased constructor. |
60 * Two-phased constructor. |
61 * @param session - initialized session to file system |
61 * @param session - initialized session to file system |
62 */ |
62 */ |
63 CAfStorage* CAfStorage::NewL(RFs& session) |
63 CAfStorage* CAfStorage::NewL(RFs& session) |
64 { |
64 { |
65 CAfStorage* self = new (ELeave) CAfStorage(session); |
65 CAfStorage* self = new (ELeave) CAfStorage(session); |
66 CleanupStack::PushL(self); |
66 CleanupStack::PushL(self); |
67 self->ConstructL(); |
67 self->ConstructL(); |
68 CleanupStack::Pop(); // self; |
68 CleanupStack::Pop(); // self; |
69 return self; |
69 return self; |
70 } |
70 } |
71 |
71 |
72 // ----------------------------------------------------------------------------- |
72 // ----------------------------------------------------------------------------- |
73 /** |
73 /** |
74 * EPOC default constructor for performing 2nd stage construction |
74 * EPOC default constructor for performing 2nd stage construction |
75 */ |
75 */ |
76 void CAfStorage::ConstructL() |
76 void CAfStorage::ConstructL() |
77 { |
77 { |
78 RBuf path; |
78 RBuf path; |
79 CleanupClosePushL( path ); |
79 CleanupClosePushL( path ); |
80 path.CreateL(KMaxPathLength); |
80 path.CreateL(KMaxPathLength); |
81 User::LeaveIfError(mFsSession.PrivatePath(path )); |
81 User::LeaveIfError(iFsSession.PrivatePath(path )); |
82 path.Append(KDbName); |
82 path.Append(KDbName); |
83 path.Insert(0, KDbDrive); |
83 path.Insert(0, KDbDrive); |
84 BaflUtils::EnsurePathExistsL(mFsSession, path); |
84 BaflUtils::EnsurePathExistsL(iFsSession, path); |
85 BaflUtils::FileExists(mFsSession, path) ? OpenDbL(path) : CreateDbL(path); |
85 BaflUtils::FileExists(iFsSession, path) ? OpenDbL(path) : CreateDbL(path); |
86 CleanupStack::PopAndDestroy(&path); |
86 CleanupStack::PopAndDestroy(&path); |
87 |
87 |
88 mDatabaseCleaner = new (ELeave) CAfDatabaseCleaner(mActDb); |
88 iDatabaseCleaner = new (ELeave) CAfDatabaseCleaner(iActDb); |
89 |
89 |
90 DeleteNonPersistentActivitiesL(); |
90 DeleteNonPersistentActivitiesL(); |
91 RequestCleanup(); |
91 RequestCleanup(); |
92 } |
92 } |
93 |
93 |
94 // ----------------------------------------------------------------------------- |
94 // ----------------------------------------------------------------------------- |
95 /** |
95 /** |
96 * Create database and its structure |
96 * Create database and its structure |
97 * @param databaseFile - database file path |
97 * @param databaseFile - database file path |
98 */ |
98 */ |
99 void CAfStorage::CreateDbL(const TDesC& databaseFile) |
99 void CAfStorage::CreateDbL(const TDesC& databaseFile) |
100 { |
100 { |
101 mFileStore = CPermanentFileStore::ReplaceL(mFsSession, |
101 iFileStore = CPermanentFileStore::ReplaceL(iFsSession, |
102 databaseFile, |
102 databaseFile, |
103 EFileRead|EFileWrite); |
103 EFileRead|EFileWrite); |
104 mFileStore->SetTypeL(mFileStore->Layout());// Set file store type |
104 iFileStore->SetTypeL(iFileStore->Layout());// Set file store type |
105 TStreamId id = mActDb.CreateL(mFileStore);// Create stream object |
105 TStreamId id = iActDb.CreateL(iFileStore);// Create stream object |
106 mFileStore->SetRootL(id);// Keep database id as root of store |
106 iFileStore->SetRootL(id);// Keep database id as root of store |
107 mFileStore->CommitL();// Complete creation by commiting |
107 iFileStore->CommitL();// Complete creation by commiting |
108 CreateTableL(); |
108 CreateTableL(); |
109 } |
109 } |
110 |
110 |
111 // ----------------------------------------------------------------------------- |
111 // ----------------------------------------------------------------------------- |
112 /** |
112 /** |
113 * Open database |
113 * Open database |
114 * @param databaseFile - database file path |
114 * @param databaseFile - database file path |
115 */ |
115 */ |
116 void CAfStorage::OpenDbL(const TDesC& databaseFile) |
116 void CAfStorage::OpenDbL(const TDesC& databaseFile) |
|
117 { |
|
118 TRAPD( errNo, |
|
119 iFileStore = CPermanentFileStore::OpenL( iFsSession, |
|
120 databaseFile, |
|
121 EFileRead|EFileWrite ); |
|
122 iFileStore->SetTypeL( iFileStore->Layout() ); /* Set file store type*/ |
|
123 iActDb.OpenL( iFileStore, iFileStore->Root() ); |
|
124 VerifyTableL(); ) |
|
125 if( KErrNone != errNo ) |
|
126 { |
|
127 //database is corrupted. recreate |
|
128 iActDb.Close(); |
|
129 delete iFileStore; |
|
130 iFileStore = 0; |
|
131 CreateDbL( databaseFile ); |
|
132 } |
|
133 } |
|
134 |
|
135 // ----------------------------------------------------------------------------- |
|
136 /** |
|
137 * Verify database structure |
|
138 */ |
|
139 void CAfStorage::VerifyDbL() |
117 { |
140 { |
118 mFileStore = CPermanentFileStore::OpenL(mFsSession, |
141 TInt errNo(KErrCorrupt); |
119 databaseFile, |
142 CDbTableNames* tables = iActDb.TableNamesL(); |
120 EFileRead|EFileWrite); |
143 CleanupStack::PushL( tables ); |
121 mFileStore->SetTypeL(mFileStore->Layout()); /* Set file store type*/ |
144 for( TInt iter(0); iter < tables->Count() && KErrNone != errNo; ++iter ) |
122 mActDb.OpenL(mFileStore,mFileStore->Root()); |
145 { |
|
146 if( 0 == (*tables)[iter].Compare( KActivityTableName() ) ) |
|
147 { |
|
148 VerifyTableL(); |
|
149 errNo = KErrNone; |
|
150 } |
|
151 } |
|
152 CleanupStack::PopAndDestroy( tables ); |
|
153 User::LeaveIfError( errNo ); |
123 } |
154 } |
124 |
155 |
125 // ----------------------------------------------------------------------------- |
156 // ----------------------------------------------------------------------------- |
126 /** |
157 CDbColSet* CAfStorage::ExpectedTableLC() |
127 * Create database structure |
158 { |
128 */ |
|
129 void CAfStorage::CreateTableL() |
|
130 { |
|
131 // Add the columns to column set |
|
132 CDbColSet* actColSet = CDbColSet::NewLC(); |
159 CDbColSet* actColSet = CDbColSet::NewLC(); |
133 |
160 |
134 TDbCol appName(KApplicationColumnName, EDbColInt64); |
161 TDbCol appName(KApplicationColumnName, EDbColInt64); |
135 appName.iAttributes = TDbCol::ENotNull; |
162 appName.iAttributes = TDbCol::ENotNull; |
136 actColSet->AddL(appName); |
163 actColSet->AddL( appName ); |
137 |
164 |
138 TDbCol actName(KActivityColumnName, EDbColText16);// Using default length |
165 TDbCol actName( KActivityColumnName, EDbColText16 );// Using default length |
139 actName.iAttributes = TDbCol::ENotNull; |
166 actName.iAttributes = TDbCol::ENotNull; |
140 actColSet->AddL(actName); |
167 actColSet->AddL( actName ); |
141 |
168 |
142 TDbCol actFlags(KFlagsColumnName, EDbColInt32); |
169 // custom name |
|
170 actColSet->AddL( TDbCol( KCustomNameColumnName, EDbColText16 ) ); |
|
171 |
|
172 TDbCol actFlags( KFlagsColumnName, EDbColInt32 ); |
143 actFlags.iAttributes = TDbCol::ENotNull; |
173 actFlags.iAttributes = TDbCol::ENotNull; |
144 actColSet->AddL(actFlags); |
174 actColSet->AddL(actFlags); |
145 |
175 |
146 actColSet->AddL(TDbCol(KDataColumnName, EDbColLongBinary));// Stream Data |
176 TDbCol actTimestamp( KTimestampColumnName, EDbColDateTime ); |
147 |
177 actTimestamp.iAttributes = TDbCol::ENotNull; |
|
178 actColSet->AddL(actTimestamp); |
|
179 |
|
180 actColSet->AddL( TDbCol( KDataColumnName, EDbColLongBinary ) );// Stream Data |
|
181 |
|
182 return actColSet; |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 /** |
|
187 * Create database structure |
|
188 */ |
|
189 void CAfStorage::CreateTableL() |
|
190 { |
|
191 CDbColSet* actColSet(ExpectedTableLC()); |
148 // Create the table |
192 // Create the table |
149 User::LeaveIfError(mActDb.CreateTable(KActivityTableName, |
193 User::LeaveIfError(iActDb.CreateTable(KActivityTableName, |
150 *actColSet)); |
194 *actColSet)); |
151 |
|
152 CleanupStack::PopAndDestroy(actColSet); |
195 CleanupStack::PopAndDestroy(actColSet); |
153 } |
196 } |
154 |
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 /** |
|
200 * Verify table structure |
|
201 */ |
|
202 void CAfStorage::VerifyTableL() |
|
203 { |
|
204 CDbColSet *currentTable(iActDb.ColSetL(KActivityTableName)); |
|
205 CleanupStack::PushL(currentTable); |
|
206 CDbColSet *expectedTable(ExpectedTableLC()); |
|
207 for( TInt iter(1); iter <= expectedTable->Count(); ++iter ) |
|
208 { |
|
209 const TDbCol& expectedColumn((*expectedTable)[iter]); |
|
210 const TDbCol* currentColumn(currentTable->Col(expectedColumn.iName)); |
|
211 if( 0 == currentColumn || |
|
212 expectedColumn.iAttributes != currentColumn->iAttributes || |
|
213 expectedColumn.iMaxLength != currentColumn->iMaxLength || |
|
214 expectedColumn.iType != currentColumn->iType ) |
|
215 { |
|
216 User::Leave(KErrCorrupt); |
|
217 } |
|
218 } |
|
219 CleanupStack::PopAndDestroy( expectedTable ); |
|
220 CleanupStack::PopAndDestroy( currentTable ); |
|
221 } |
155 // ----------------------------------------------------------------------------- |
222 // ----------------------------------------------------------------------------- |
156 /** |
223 /** |
157 * Delete non-persistent activities |
224 * Delete non-persistent activities |
158 */ |
225 */ |
159 void CAfStorage::DeleteNonPersistentActivitiesL() |
226 void CAfStorage::DeleteNonPersistentActivitiesL() |
160 { |
227 { |
161 HBufC *query(BuildQueryLC(KDeleteNonPersistentActivities(), CAfEntry::Persistent, KNullDesC)); |
228 HBufC *query(BuildQueryLC(KDeleteNonPersistentActivities(), |
162 User::LeaveIfError(mActDb.Execute(*query)); |
229 CAfEntry::Persistent, |
|
230 KNullDesC)); |
|
231 User::LeaveIfError(iActDb.Execute(*query)); |
163 RBuf privatePath; |
232 RBuf privatePath; |
164 CleanupClosePushL(privatePath); |
233 CleanupClosePushL(privatePath); |
165 privatePath.CreateL(KMaxPathLength); |
234 privatePath.CreateL(KMaxPathLength); |
166 StoragePathL(privatePath, Fs(), FALSE); |
235 StoragePathL(privatePath, Fs(), FALSE); |
167 CFileMan *fileMan = CFileMan::NewL(Fs()); |
236 CFileMan *fileMan = CFileMan::NewL(Fs()); |
168 TInt i = fileMan->RmDir(privatePath); |
237 TInt i = fileMan->RmDir(privatePath); |
169 delete fileMan; |
238 delete fileMan; |
170 CleanupStack::PopAndDestroy(&privatePath); |
239 CleanupStack::PopAndDestroy(&privatePath); |
171 CleanupStack::PopAndDestroy(query); |
240 CleanupStack::PopAndDestroy(query); |
172 } |
241 } |
173 |
242 |
174 // ----------------------------------------------------------------------------- |
243 // ----------------------------------------------------------------------------- |
175 /** |
244 /** |
176 * Register new activity |
245 * Register new activity |
177 * @param appId - application id |
246 * @param appId - application id |
180 * @param imgSrc - activity thumbnail source |
249 * @param imgSrc - activity thumbnail source |
181 * @param privateData - activity private data |
250 * @param privateData - activity private data |
182 * @param publicData - activity public data |
251 * @param publicData - activity public data |
183 */ |
252 */ |
184 void CAfStorage::AddActivityL(CAfEntry& entry) |
253 void CAfStorage::AddActivityL(CAfEntry& entry) |
185 { |
254 { |
186 //verify if row already exists |
255 //verify if row already exists |
187 TInt errNo(KErrNone); |
256 TInt errNo(KErrNone); |
188 RDbView view; |
257 RDbView view; |
189 CleanupClosePushL(view); |
258 CleanupClosePushL(view); |
190 TRAP( errNo, GetActivityForUpdateL(view, entry.ApplicationId(), entry.ActivityId())); |
259 TRAP( errNo, GetActivityForUpdateL(view, entry.ApplicationId(), entry.ActivityId())); |
191 if (KErrNone == errNo) { |
260 if( KErrNone == errNo ) |
|
261 { |
192 User::Leave(KErrAlreadyExists); |
262 User::Leave(KErrAlreadyExists); |
193 } |
263 } |
194 CleanupStack::PopAndDestroy(&view); |
264 CleanupStack::PopAndDestroy(&view); |
195 |
265 |
196 //write table |
266 //write table |
197 RDbTable table; |
267 RDbTable table; |
198 CleanupClosePushL(table); |
268 CleanupClosePushL(table); |
199 User::LeaveIfError(table.Open(mActDb, KActivityTableName, table.EUpdatable)); |
269 User::LeaveIfError(table.Open(iActDb, KActivityTableName, table.EUpdatable)); |
200 CDbColSet *row = table.ColSetL(); |
270 CDbColSet *row = table.ColSetL(); |
201 CleanupStack::PushL(row); |
271 CleanupStack::PushL(row); |
202 |
272 |
|
273 TTime time; |
|
274 time.UniversalTime(); |
|
275 |
203 table.InsertL(); |
276 table.InsertL(); |
204 TRAP(errNo, |
277 TRAP(errNo, |
205 table.SetColL(row->ColNo(KApplicationColumnName), TInt64(entry.ApplicationId())); |
278 table.SetColL(row->ColNo(KApplicationColumnName), TInt64(entry.ApplicationId())); |
206 table.SetColL(row->ColNo(KActivityColumnName), entry.ActivityId()); |
279 table.SetColL(row->ColNo(KActivityColumnName), entry.ActivityId()); |
|
280 table.SetColL(row->ColNo(KCustomNameColumnName), entry.CustomActivityName()); |
207 table.SetColL(row->ColNo(KFlagsColumnName), entry.Flags()); |
281 table.SetColL(row->ColNo(KFlagsColumnName), entry.Flags()); |
208 ExternalizeDataL(table, entry, row->ColNo(KDataColumnName)); |
282 table.SetColL(row->ColNo(KTimestampColumnName), time.DateTime()); |
|
283 ExternalizeDataL(table, entry, row->ColNo(KDataColumnName) ); |
|
284 |
209 table.PutL();) |
285 table.PutL();) |
210 if (KErrNone != errNo) { |
286 if( KErrNone != errNo ) |
|
287 { |
211 table.Cancel(); |
288 table.Cancel(); |
212 User::Leave(errNo); |
289 User::Leave(errNo); |
213 } |
290 } |
214 CleanupStack::PopAndDestroy(row); |
291 CleanupStack::PopAndDestroy(row); |
215 CleanupStack::PopAndDestroy(&table); |
292 CleanupStack::PopAndDestroy(&table); |
216 } |
293 } |
217 |
294 |
218 // ----------------------------------------------------------------------------- |
295 // ----------------------------------------------------------------------------- |
219 /** |
296 /** |
220 * Update activity |
297 * Update activity |
221 * @param entry - activity data |
298 * @param entry - activity data |
222 */ |
299 */ |
223 void CAfStorage::UpdateActivityL(CAfEntry& entry) |
300 void CAfStorage::UpdateActivityL(CAfEntry& entry) |
224 { |
301 { |
|
302 TTime time; |
|
303 time.UniversalTime(); |
225 RDbView view; |
304 RDbView view; |
226 CleanupClosePushL(view); |
305 CleanupClosePushL(view); |
227 GetActivityForUpdateL(view, entry.ApplicationId(), entry.ActivityId()); |
306 GetActivityForUpdateL(view, entry.ApplicationId(), entry.ActivityId()); |
228 view.UpdateL(); |
307 view.UpdateL(); |
229 TRAPD(errNo, |
308 TRAPD(errNo, |
230 CDbColSet* colSet = view.ColSetL(); |
309 CDbColSet* colSet = view.ColSetL(); |
231 CleanupStack::PushL(colSet); |
310 CleanupStack::PushL(colSet); |
232 |
311 |
233 view.SetColL(colSet->ColNo(KFlagsColumnName), entry.Flags()); |
312 view.SetColL(colSet->ColNo(KFlagsColumnName), entry.Flags()); |
|
313 view.SetColL(colSet->ColNo(KTimestampColumnName), time.DateTime()); |
|
314 view.SetColL(colSet->ColNo(KCustomNameColumnName), entry.CustomActivityName()); |
234 ExternalizeDataL(view, entry, colSet->ColNo(KDataColumnName)); |
315 ExternalizeDataL(view, entry, colSet->ColNo(KDataColumnName)); |
235 |
316 |
236 view.PutL(); |
317 view.PutL(); |
237 CleanupStack::PopAndDestroy(colSet);) |
318 CleanupStack::PopAndDestroy(colSet);) |
238 |
319 |
239 if (KErrNone != errNo) { |
320 if(KErrNone != errNo) |
|
321 { |
240 view.Cancel(); |
322 view.Cancel(); |
241 User::Leave(errNo); |
323 User::Leave(errNo); |
242 } |
324 } |
243 CleanupStack::PopAndDestroy(&view); |
325 CleanupStack::PopAndDestroy(&view); |
244 } |
326 } |
245 |
327 |
246 // ----------------------------------------------------------------------------- |
328 // ----------------------------------------------------------------------------- |
247 /** |
329 /** |
248 * Save activity |
330 * Save activity |
249 * @param entry - activity data |
331 * @param entry - activity data |
250 */ |
332 */ |
251 void CAfStorage::SaveActivityL(CAfEntry &entry) |
333 void CAfStorage::SaveActivityL(CAfEntry &entry) |
252 { |
334 { |
|
335 TTime time; |
|
336 time.UniversalTime(); |
253 // @todo check if this can be tidied up |
337 // @todo check if this can be tidied up |
254 //verify if row already exists |
338 //verify if row already exists |
255 TInt errNo(KErrNone); |
339 TInt errNo(KErrNone); |
256 RDbView view; |
340 RDbView view; |
257 CleanupClosePushL(view); |
341 CleanupClosePushL(view); |
258 TRAP(errNo, GetActivityForUpdateL(view, entry.ApplicationId(), entry.ActivityId())); |
342 TRAP(errNo, GetActivityForUpdateL(view, entry.ApplicationId(), entry.ActivityId())); |
259 if (KErrNone == errNo) { |
343 if( KErrNone == errNo ) |
|
344 { |
260 // update |
345 // update |
261 view.UpdateL(); |
346 view.UpdateL(); |
262 TRAPD(errNo, |
347 TRAPD(errNo, |
263 CDbColSet* colSet = view.ColSetL(); |
348 CDbColSet* colSet = view.ColSetL(); |
264 CleanupStack::PushL(colSet); |
349 CleanupStack::PushL(colSet); |
265 |
350 |
266 view.SetColL(colSet->ColNo(KFlagsColumnName), entry.Flags()); |
351 view.SetColL(colSet->ColNo(KFlagsColumnName), entry.Flags()); |
|
352 view.SetColL(colSet->ColNo(KTimestampColumnName), time.DateTime()); |
|
353 view.SetColL(colSet->ColNo(KCustomNameColumnName), entry.CustomActivityName()); |
267 ExternalizeDataL(view, entry, colSet->ColNo(KDataColumnName)); |
354 ExternalizeDataL(view, entry, colSet->ColNo(KDataColumnName)); |
268 |
355 |
269 view.PutL(); |
356 view.PutL(); |
270 CleanupStack::PopAndDestroy(colSet);) |
357 CleanupStack::PopAndDestroy(colSet);) |
271 |
358 |
272 if (KErrNone != errNo) { |
359 if (KErrNone != errNo) |
|
360 { |
273 view.Cancel(); |
361 view.Cancel(); |
274 User::Leave(errNo); |
362 User::Leave(errNo); |
275 } |
363 } |
276 } else { |
364 } |
|
365 else |
|
366 { |
277 // insert |
367 // insert |
278 |
368 |
279 //write table |
369 //write table |
280 RDbTable table; |
370 RDbTable table; |
281 CleanupClosePushL(table); |
371 CleanupClosePushL(table); |
282 User::LeaveIfError(table.Open(mActDb, KActivityTableName, table.EUpdatable)); |
372 User::LeaveIfError(table.Open(iActDb, KActivityTableName, table.EUpdatable)); |
283 CDbColSet *row = table.ColSetL(); |
373 CDbColSet *row = table.ColSetL(); |
284 CleanupStack::PushL(row); |
374 CleanupStack::PushL(row); |
285 |
375 |
286 table.InsertL(); |
376 table.InsertL(); |
287 TRAP(errNo, |
377 TRAP(errNo, |
288 table.SetColL(row->ColNo(KApplicationColumnName), TInt64(entry.ApplicationId())); |
378 table.SetColL(row->ColNo(KApplicationColumnName), TInt64(entry.ApplicationId())); |
289 table.SetColL(row->ColNo(KActivityColumnName), entry.ActivityId()); |
379 table.SetColL(row->ColNo(KActivityColumnName), entry.ActivityId()); |
|
380 table.SetColL(row->ColNo(KCustomNameColumnName), entry.CustomActivityName()); |
290 table.SetColL(row->ColNo(KFlagsColumnName), entry.Flags()); |
381 table.SetColL(row->ColNo(KFlagsColumnName), entry.Flags()); |
|
382 table.SetColL(row->ColNo(KTimestampColumnName), time.DateTime()); |
291 ExternalizeDataL(table, entry, row->ColNo(KDataColumnName)); |
383 ExternalizeDataL(table, entry, row->ColNo(KDataColumnName)); |
292 table.PutL();) |
384 table.PutL();) |
293 if (KErrNone != errNo) { |
385 if (KErrNone != errNo) { |
294 table.Cancel(); |
386 table.Cancel(); |
295 User::Leave(errNo); |
387 User::Leave(errNo); |
296 } |
388 } |
297 CleanupStack::PopAndDestroy(row); |
389 CleanupStack::PopAndDestroy(row); |
298 CleanupStack::PopAndDestroy(&table); |
390 CleanupStack::PopAndDestroy(&table); |
299 } |
391 } |
300 |
|
301 CleanupStack::PopAndDestroy(&view); |
392 CleanupStack::PopAndDestroy(&view); |
302 } |
393 } |
303 |
394 |
304 // ----------------------------------------------------------------------------- |
395 // ----------------------------------------------------------------------------- |
305 /** |
396 /** |
306 * Delete activity |
397 * Delete activity |
307 * @param appId - application id |
398 * @param appId - application id |
308 * @param actId - activity id |
399 * @param actId - activity id |
309 */ |
400 */ |
310 void CAfStorage::DeleteActivityL(CAfEntry& entry) |
401 void CAfStorage::DeleteActivityL(CAfEntry& entry) |
311 { |
402 { |
312 HBufC *query(DeleteRowLC(entry.ApplicationId(), entry.ActivityId())); |
403 HBufC *query(DeleteRowLC(entry.ApplicationId(), entry.ActivityId())); |
313 User::LeaveIfError(mActDb.Execute(*query)); |
404 User::LeaveIfError(iActDb.Execute(*query)); |
314 CleanupStack::PopAndDestroy(query); |
405 CleanupStack::PopAndDestroy(query); |
315 } |
406 } |
316 |
407 |
317 // ----------------------------------------------------------------------------- |
|
318 // |
|
319 // ----------------------------------------------------------------------------- |
408 // ----------------------------------------------------------------------------- |
320 // |
409 // |
321 void CAfStorage::DeleteActivitiesL(CAfEntry& entry) |
410 void CAfStorage::DeleteActivitiesL(CAfEntry& entry) |
322 { |
411 { |
323 HBufC *query(DeleteRowsLC(entry.ApplicationId())); |
412 HBufC *query(DeleteRowsLC(entry.ApplicationId())); |
324 User::LeaveIfError(mActDb.Execute(*query)); |
413 User::LeaveIfError(iActDb.Execute(*query)); |
325 RBuf privatePath; |
414 RBuf privatePath; |
326 CleanupClosePushL(privatePath); |
415 CleanupClosePushL(privatePath); |
327 privatePath.CreateL(KMaxPathLength); |
416 privatePath.CreateL(KMaxPathLength); |
328 AppStoragePathL(privatePath, Fs(), entry.ApplicationId(), FALSE); |
417 AppStoragePathL(privatePath, Fs(), entry.ApplicationId(), FALSE); |
329 CFileMan *fileMan = CFileMan::NewL(Fs()); |
418 CFileMan *fileMan = CFileMan::NewL(Fs()); |
335 fileMan->RmDir(privatePath); |
424 fileMan->RmDir(privatePath); |
336 |
425 |
337 CleanupStack::PopAndDestroy(fileMan); |
426 CleanupStack::PopAndDestroy(fileMan); |
338 CleanupStack::PopAndDestroy(&privatePath); |
427 CleanupStack::PopAndDestroy(&privatePath); |
339 CleanupStack::PopAndDestroy(query); |
428 CleanupStack::PopAndDestroy(query); |
340 } |
429 } |
341 |
430 |
342 // ----------------------------------------------------------------------------- |
431 // ----------------------------------------------------------------------------- |
343 // |
432 // |
344 // ----------------------------------------------------------------------------- |
433 // ----------------------------------------------------------------------------- |
345 // |
434 // |
346 void CAfStorage::ActivitiesL(RPointerArray<CAfEntry>& dst) |
435 void CAfStorage::AllActivitiesL(RPointerArray<CAfEntry>& dst, TInt aLimit) |
347 { |
436 { |
348 ActivitiesL(dst, KSelectRows(), CAfEntry::Public); |
437 ActivitiesL(dst, KSelectRows(), CAfEntry::Public, aLimit); |
349 } |
438 } |
350 |
439 |
351 // ----------------------------------------------------------------------------- |
440 // ----------------------------------------------------------------------------- |
352 /** |
441 /** |
353 * Serialize application activity into the buffer |
442 * Serialize application activity into the buffer |
354 * @param dst - destination buffer |
443 * @param dst - destination buffer |
355 * @param appId - application id |
444 * @param appId - application id |
356 */ |
445 */ |
357 void CAfStorage::ActivitiesL(RPointerArray<CAfEntry>& dst,TInt appId) |
446 void CAfStorage::ActivitiesL(RPointerArray<CAfEntry>& dst,TInt appId) |
358 { |
447 { |
359 HBufC *query(SelectRowsLC(appId)); |
448 HBufC *query(SelectRowsLC(appId)); |
360 ActivitiesL(dst, *query, CAfEntry::Private); |
449 ActivitiesL(dst, *query, CAfEntry::Private); |
361 CleanupStack::PopAndDestroy(query); |
450 CleanupStack::PopAndDestroy(query); |
362 } |
451 } |
363 |
452 |
364 // ----------------------------------------------------------------------------- |
453 // ----------------------------------------------------------------------------- |
365 /** |
454 /** |
366 * Serialize application activity into the buffer |
455 * Serialize application activity into the buffer |
367 * @param dst - destination entry |
456 * @param dst - destination entry |
368 * @param src - condition pattern |
457 * @param src - condition pattern |
369 */ |
458 */ |
370 void CAfStorage::ActivityL(RPointerArray<CAfEntry> &dst, CAfEntry& src) |
459 void CAfStorage::ActivityL(RPointerArray<CAfEntry> &dst, CAfEntry& src) |
371 { |
460 { |
372 HBufC *query = SelectRowLC(src.ApplicationId(), src.ActivityId()); |
461 HBufC *query = SelectRowLC(src.ApplicationId(), src.ActivityId()); |
373 ActivitiesL(dst, *query, CAfEntry::Private, 1); |
462 ActivitiesL(dst, *query, CAfEntry::Private, 1, ETrue); |
374 if (0 >= dst.Count()) { |
463 if( 0 >= dst.Count() ) |
|
464 { |
375 User::Leave(KErrNotFound); |
465 User::Leave(KErrNotFound); |
376 } |
466 } |
377 CleanupStack::PopAndDestroy(query); |
467 CleanupStack::PopAndDestroy(query); |
378 } |
468 } |
379 |
469 |
380 // ----------------------------------------------------------------------------- |
470 // ----------------------------------------------------------------------------- |
381 /** |
471 /** |
382 * Provide initialized file system session |
472 * Provide initialized file system session |
383 * @return file system session |
473 * @return file system session |
384 */ |
474 */ |
385 RFs& CAfStorage::Fs() |
475 RFs& CAfStorage::Fs() |
386 { |
476 { |
387 return mFsSession; |
477 return iFsSession; |
388 } |
478 } |
389 |
479 |
390 // ----------------------------------------------------------------------------- |
480 // ----------------------------------------------------------------------------- |
391 /** |
481 /** |
392 * Format query to select activity row |
482 * Format query to select activity row |
393 * @param appId - application id |
483 * @param appId - application id |
394 * @param actId - activity id |
484 * @param actId - activity id |
395 * @return formated sql query |
485 * @return formated sql query |
396 */ |
486 */ |
397 HBufC* CAfStorage::SelectRowLC(TInt appId, const TDesC& actId) const |
487 HBufC* CAfStorage::SelectRowLC(TInt appId, const TDesC& actId) const |
398 { |
488 { |
399 return BuildQueryLC(KSelectRow(),appId, actId); |
489 return BuildQueryLC(KSelectRow(),appId, actId); |
400 } |
490 } |
401 |
491 |
402 // ----------------------------------------------------------------------------- |
492 // ----------------------------------------------------------------------------- |
403 /** |
493 /** |
404 * Format query to select activities for application |
494 * Format query to select activities for application |
405 * @param appId - application id |
495 * @param appId - application id |
406 * @return formated sql query |
496 * @return formated sql query |
407 */ |
497 */ |
408 HBufC* CAfStorage::SelectRowsLC(TInt appId) const |
498 HBufC* CAfStorage::SelectRowsLC(TInt appId) const |
409 { |
499 { |
410 return BuildQueryLC(KSelectAppRows(), appId, KNullDesC); |
500 return BuildQueryLC(KSelectAppRows(), appId, KNullDesC); |
411 } |
501 } |
412 |
502 |
413 // ----------------------------------------------------------------------------- |
503 // ----------------------------------------------------------------------------- |
414 /** |
504 /** |
415 * Format query to delete activity |
505 * Format query to delete activity |
416 * @param appId - application id |
506 * @param appId - application id |
417 * @param actId - activity id |
507 * @param actId - activity id |
418 * @return formated sql query |
508 * @return formated sql query |
419 */ |
509 */ |
420 HBufC* CAfStorage::DeleteRowLC(TInt appId, const TDesC& actId) const |
510 HBufC* CAfStorage::DeleteRowLC(TInt appId, const TDesC& actId) const |
421 { |
511 { |
422 return BuildQueryLC(KDeleteRow(),appId, actId); |
512 return BuildQueryLC(KDeleteRow(),appId, actId); |
423 } |
513 } |
424 |
514 |
425 // ----------------------------------------------------------------------------- |
515 // ----------------------------------------------------------------------------- |
426 /** |
516 /** |
427 * Format query to delete activities for application |
517 * Format query to delete activities for application |
428 * @param appId - application id |
518 * @param appId - application id |
429 * @return formated sql query |
519 * @return formated sql query |
430 */ |
520 */ |
431 HBufC* CAfStorage::DeleteRowsLC(TInt appId) const |
521 HBufC* CAfStorage::DeleteRowsLC(TInt appId) const |
432 { |
522 { |
433 return BuildQueryLC(KDeleteRows(),appId, KNullDesC); |
523 return BuildQueryLC(KDeleteRows(),appId, KNullDesC); |
434 } |
524 } |
435 |
525 |
436 // ----------------------------------------------------------------------------- |
526 // ----------------------------------------------------------------------------- |
437 /** |
527 /** |
438 * Format sql query |
528 * Format sql query |
439 * @format - sql format string |
529 * @format - sql format string |
456 actName.Length() ); |
546 actName.Length() ); |
457 query->Des().AppendFormat(format, &appName, &actName); |
547 query->Des().AppendFormat(format, &appName, &actName); |
458 CleanupStack::PopAndDestroy(&actName); |
548 CleanupStack::PopAndDestroy(&actName); |
459 CleanupStack::PushL(query); |
549 CleanupStack::PushL(query); |
460 return query; |
550 return query; |
461 } |
551 } |
462 |
552 |
463 // ----------------------------------------------------------------------------- |
553 // ----------------------------------------------------------------------------- |
464 /** |
554 /** |
465 * Execute sql query and result serialize into buffer |
555 * Execute sql query and result serialize into buffer |
466 * @param dst - destination result buffer |
556 * @param dst - destination result buffer |
467 * @param query - sql activity query |
557 * @param query - sql activity query |
468 */ |
558 */ |
469 void CAfStorage::ActivitiesL(RPointerArray<CAfEntry>& dst, const TDesC& query, CAfEntry::AccessRights rights, TInt limit) |
559 void CAfStorage::ActivitiesL(RPointerArray<CAfEntry>& dst, const TDesC& query, CAfEntry::AccessRights rights, TInt limit, TBool deserializeAllData) |
470 { |
560 { |
471 RDbView view;// Create a view on the database |
561 RDbView view;// Create a view on the database |
472 CleanupClosePushL(view); |
562 CleanupClosePushL(view); |
473 User::LeaveIfError(view.Prepare(mActDb, TDbQuery(query), view.EReadOnly)); |
563 User::LeaveIfError(view.Prepare(iActDb, TDbQuery(query), view.EReadOnly)); |
474 User::LeaveIfError(view.EvaluateAll()); |
564 User::LeaveIfError(view.EvaluateAll()); |
475 ActivitiesL(dst, view, rights, limit); |
565 ActivitiesL(dst, view, rights, limit, deserializeAllData); |
476 CleanupStack::PopAndDestroy(&view); |
566 CleanupStack::PopAndDestroy(&view); |
477 } |
567 } |
478 |
568 |
479 // ----------------------------------------------------------------------------- |
569 // ----------------------------------------------------------------------------- |
480 /** |
570 /** |
481 * Return view deserialisd into entries array |
571 * Return view deserialisd into entries array |
482 * @param dst - destination result |
572 * @param dst - destination result |
483 * @param query - view |
573 * @param query - view |
484 * @param rights - acess rights |
574 * @param rights - acess rights |
485 */ |
575 */ |
486 void CAfStorage::ActivitiesL(RPointerArray<CAfEntry>& dst, RDbView& src, CAfEntry::AccessRights rights, TInt limit) |
576 void CAfStorage::ActivitiesL(RPointerArray<CAfEntry>& dst, |
487 { |
577 RDbView& src, |
|
578 CAfEntry::AccessRights rights, |
|
579 TInt limit, |
|
580 TBool deserializeAllData) |
|
581 { |
488 CDbColSet* row = src.ColSetL(); |
582 CDbColSet* row = src.ColSetL(); |
489 CleanupStack::PushL(row); |
583 CleanupStack::PushL(row); |
490 |
584 |
491 const TInt flagsOffset(row->ColNo(KFlagsColumnName)), |
585 const TInt flagsOffset(row->ColNo(KFlagsColumnName)), |
492 applicationOffset(row->ColNo(KApplicationColumnName)), |
586 applicationOffset(row->ColNo(KApplicationColumnName)), |
493 activityOffset(row->ColNo(KActivityColumnName)), |
587 activityOffset(row->ColNo(KActivityColumnName)), |
|
588 customNameOffset(row->ColNo(KCustomNameColumnName)), |
494 dataOffset(row->ColNo(KDataColumnName)); |
589 dataOffset(row->ColNo(KDataColumnName)); |
495 |
590 |
496 RBuf activityName; |
591 RBuf activityName; |
497 CleanupClosePushL(activityName); |
592 CleanupClosePushL(activityName); |
498 |
593 |
499 for (src.FirstL(); src.AtRow(); src.NextL()) { |
594 RBuf customName; |
500 if(0 < limit && dst.Count() >= limit) { |
595 CleanupClosePushL(customName); |
|
596 |
|
597 |
|
598 for (src.FirstL(); src.AtRow(); src.NextL()) |
|
599 { |
|
600 if ( 0 < limit && dst.Count() >= limit ) |
|
601 { |
501 break; |
602 break; |
502 } |
603 } |
503 src.GetL(); |
604 src.GetL(); |
504 ReadDataL(activityName, src, activityOffset); |
605 ReadDataL(activityName, src, activityOffset); |
|
606 ReadDataL(customName, src, customNameOffset); |
505 |
607 |
506 CAfEntry *entry = CAfEntry::NewLC(src.ColInt32(flagsOffset), |
608 CAfEntry *entry = CAfEntry::NewLC(src.ColInt32(flagsOffset), |
507 src.ColInt64(applicationOffset), |
609 src.ColInt64(applicationOffset), |
508 activityName, |
610 activityName, |
|
611 customName, |
509 KNullDesC, |
612 KNullDesC, |
510 KNullDesC8, |
613 KNullDesC8, |
511 KNullDesC8); |
614 KNullDesC8); |
512 if (CAfEntry::Public == rights && (entry->Flags() & CAfEntry::Invisible)) { |
615 if( CAfEntry::Public == rights && |
|
616 (entry->Flags() & CAfEntry::Invisible) ) |
|
617 { |
513 CleanupStack::PopAndDestroy(entry); |
618 CleanupStack::PopAndDestroy(entry); |
514 continue; |
619 continue; |
515 } |
620 } |
516 InternalizeDataL(*entry, src, dataOffset); |
621 InternalizeDataL(*entry, src, dataOffset); |
517 |
622 |
518 if (CAfEntry::Public == rights || 0 >= limit) { |
623 if (!deserializeAllData) { |
|
624 entry->SetDataL(KNullDesC8(), CAfEntry::Public); |
519 entry->SetDataL(KNullDesC8(), CAfEntry::Private); |
625 entry->SetDataL(KNullDesC8(), CAfEntry::Private); |
520 } |
626 } else { |
|
627 if (CAfEntry::Public == rights) { |
|
628 entry->SetDataL(KNullDesC8(), CAfEntry::Private); |
|
629 } |
|
630 } |
|
631 |
521 dst.AppendL(entry); |
632 dst.AppendL(entry); |
522 CleanupStack::Pop(entry); |
633 CleanupStack::Pop(entry); |
523 } |
634 } |
524 |
635 CleanupStack::PopAndDestroy(&customName); |
525 CleanupStack::PopAndDestroy(&activityName); |
636 CleanupStack::PopAndDestroy(&activityName); |
526 CleanupStack::PopAndDestroy(row); |
637 CleanupStack::PopAndDestroy(row); |
527 } |
638 } |
528 |
639 |
529 // ----------------------------------------------------------------------------- |
640 // ----------------------------------------------------------------------------- |
530 /** |
641 /** |
531 * Get activity for update |
642 * Get activity for update |
532 * @param query - destination query result |
643 * @param query - destination query result |
533 * @param appId - application id |
644 * @param appId - application id |
534 * @param actId - activity id |
645 * @param actId - activity id |
535 */ |
646 */ |
536 void CAfStorage::GetActivityForUpdateL(RDbView& view, TInt appId, const TDesC& actId) |
647 void CAfStorage::GetActivityForUpdateL(RDbView& view, TInt appId, const TDesC& actId) |
537 { |
648 { |
538 HBufC* query(SelectRowLC(appId, actId)); |
649 HBufC* query(SelectRowLC(appId, actId)); |
539 User::LeaveIfError(view.Prepare(mActDb, TDbQuery(*query), view.EUpdatable)); |
650 User::LeaveIfError(view.Prepare(iActDb, TDbQuery(*query), view.EUpdatable)); |
540 CleanupStack::PopAndDestroy(query); |
651 CleanupStack::PopAndDestroy(query); |
541 User::LeaveIfError(view.EvaluateAll()); |
652 User::LeaveIfError(view.EvaluateAll()); |
542 if (!view.FirstL()) { |
653 if( !view.FirstL() ) |
|
654 { |
543 User::Leave(KErrNotFound); |
655 User::Leave(KErrNotFound); |
544 } |
656 } |
545 } |
657 } |
546 |
658 |
547 // ----------------------------------------------------------------------------- |
659 // ----------------------------------------------------------------------------- |
548 void CAfStorage::ReadDataL(RBuf& dst, RDbRowSet& src, TInt offset) const |
660 void CAfStorage::ReadDataL(RBuf& dst, RDbRowSet& src, TInt offset) const |
549 { |
661 { |
550 const TInt length(src.ColLength(offset)); |
662 const TInt length(src.ColLength(offset)); |
551 CAfEntry::ReallocL(dst, length); |
663 CAfEntry::ReallocL(dst, length); |
552 RDbColReadStream srcStream; |
664 RDbColReadStream srcStream; |
553 srcStream.OpenLC(src,offset); |
665 srcStream.OpenLC(src,offset); |
554 srcStream.ReadL(dst, src.ColLength(offset)); |
666 srcStream.ReadL(dst, src.ColLength(offset)); |
555 CleanupStack::PopAndDestroy(&srcStream); |
667 CleanupStack::PopAndDestroy(&srcStream); |
556 } |
668 } |
557 |
669 |
558 // ----------------------------------------------------------------------------- |
670 // ----------------------------------------------------------------------------- |
559 void CAfStorage::ExternalizeDataL(RDbRowSet& dst,const CAfEntry &src, TInt offset) const |
671 void CAfStorage::ExternalizeDataL(RDbRowSet& dst,const CAfEntry &src, TInt offset) const |
560 { |
672 { |
561 RDbColWriteStream dbStream; |
673 RDbColWriteStream dbStream; |
562 CleanupClosePushL(dbStream); |
674 CleanupClosePushL(dbStream); |
563 dbStream.OpenL(dst, offset); |
675 dbStream.OpenL(dst, offset); |
564 src.ExternalizeDataOnlyL(dbStream); |
676 src.ExternalizeDataOnlyL(dbStream); |
565 CleanupStack::PopAndDestroy(&dbStream); |
677 CleanupStack::PopAndDestroy(&dbStream); |
566 } |
678 } |
567 |
679 |
568 // ----------------------------------------------------------------------------- |
680 // ----------------------------------------------------------------------------- |
569 void CAfStorage::InternalizeDataL(CAfEntry & dst, RDbRowSet& src, TInt offset) const |
681 void CAfStorage::InternalizeDataL(CAfEntry & dst, RDbRowSet& src, TInt offset) const |
570 { |
682 { |
571 RDbColReadStream dbStream; |
683 RDbColReadStream dbStream; |
572 CleanupClosePushL(dbStream); |
684 CleanupClosePushL(dbStream); |
573 dbStream.OpenL(src, offset); |
685 dbStream.OpenL(src, offset); |
574 dst.InternalizeDataOnlyL(dbStream); |
686 dst.InternalizeDataOnlyL(dbStream); |
575 CleanupStack::PopAndDestroy(&dbStream); |
687 CleanupStack::PopAndDestroy(&dbStream); |
576 } |
688 } |
577 |
689 |
578 // ----------------------------------------------------------------------------- |
690 // ----------------------------------------------------------------------------- |
579 // |
691 // |
580 // ----------------------------------------------------------------------------- |
692 // ----------------------------------------------------------------------------- |
581 // |
693 // |
582 void CAfStorage::StoragePathL(RBuf &dst, |
694 void CAfStorage::StoragePathL(RBuf &dst, |
583 RFs& fileSystem, |
695 RFs& fileSystem, |
584 TBool persistent) |
696 TBool persistent) |
585 { |
697 { |
586 if (dst.MaxLength() < KMaxPathLength) { |
698 if (dst.MaxLength() < KMaxPathLength) |
|
699 { |
587 dst.ReAllocL(KMaxPathLength); |
700 dst.ReAllocL(KMaxPathLength); |
588 } |
701 } |
589 dst.Zero(); |
702 dst.Zero(); |
590 User::LeaveIfError(fileSystem.PrivatePath(dst)); |
703 User::LeaveIfError(fileSystem.PrivatePath(dst)); |
591 if(persistent) { |
704 if(persistent) |
|
705 { |
592 dst.Append(KPersistent); |
706 dst.Append(KPersistent); |
593 } |
707 } |
594 else { |
708 else |
|
709 { |
595 dst.Append(KNonPersistent); |
710 dst.Append(KNonPersistent); |
596 } |
711 } |
597 } |
712 } |
598 |
713 |
599 // ----------------------------------------------------------------------------- |
714 // ----------------------------------------------------------------------------- |
600 // |
715 // |
601 // ----------------------------------------------------------------------------- |
716 // ----------------------------------------------------------------------------- |
602 // |
717 // |
603 void CAfStorage::AppStoragePathL(RBuf &dst, |
718 void CAfStorage::AppStoragePathL(RBuf &dst, |
604 RFs& fileSystem, |
719 RFs& fileSystem, |
605 TInt uid, |
720 TInt uid, |
606 TBool persistent) |
721 TBool persistent) |
607 { |
722 { |
608 StoragePathL(dst, fileSystem, persistent); |
723 StoragePathL(dst, fileSystem, persistent); |
609 |
724 |
610 //Format activity path |
725 //Format activity path |
611 dst.AppendFormat( KUidFormat, uid); |
726 dst.AppendFormat( KUidFormat, uid); |
612 } |
727 } |