3307 return extraRows; |
3307 return extraRows; |
3308 } |
3308 } |
3309 |
3309 |
3310 TBool CMdSSqlObjectManipulate::DoGarbageCollectionL() |
3310 TBool CMdSSqlObjectManipulate::DoGarbageCollectionL() |
3311 { |
3311 { |
3312 _LIT( KDeleteObject, "DELETE FROM Object%u WHERE Flags&?;" ); |
3312 _LIT( KDeleteObject, "DELETE FROM Object%u WHERE ObjectId IN (SELECT ObjectId FROM Object%u WHERE Flags&? LIMIT 100);" ); |
3313 _LIT( KUpdateDeleteObject, "UPDATE Object%u SET Flags=Flags|? WHERE Flags&?;" ); |
3313 _LIT( KUpdateDeleteObject, "UPDATE Object%u SET Flags=Flags|? WHERE Flags&?;" ); |
3314 _LIT( KDeleteRelations, "DELETE FROM Relations%u WHERE Flags&?;" ); |
3314 _LIT( KDeleteRelations, "DELETE FROM Relations%u WHERE Flags&?;" ); |
3315 _LIT( KUpdateDeleteRelations, "UPDATE Relations%u SET Flags=Flags|? WHERE Flags&?;" ); |
3315 _LIT( KUpdateDeleteRelations, "UPDATE Relations%u SET Flags=Flags|? WHERE Flags&?;" ); |
3316 _LIT( KUpdateDeleteContextObjects, "UPDATE Object%u SET Flags=Flags|? WHERE ObjectId IN ( SELECT ObjectId FROM Object%u AS O WHERE Flags&? AND UsageCount=0 AND ( SELECT count(*) FROM Relations%u WHERE NOT Flags&? AND ( LeftObjectId = O.ObjectId OR RightObjectId = O.ObjectId ) )= 0 );" ); |
3316 _LIT( KUpdateDeleteContextObjects, "UPDATE Object%u SET Flags=Flags|? WHERE ObjectId IN ( SELECT ObjectId FROM Object%u AS O WHERE Flags&? AND UsageCount=0 AND ( SELECT count(*) FROM Relations%u WHERE NOT Flags&? AND ( LeftObjectId = O.ObjectId OR RightObjectId = O.ObjectId ) )= 0 );" ); |
3317 _LIT( KDeleteWordFromTextSearchDict, "DELETE FROM TextSearchDictionary%u WHERE NOT EXISTS(SELECT WordId FROM TextSearch%u WHERE WordId = TextSearchDictionary%u.WordId);"); |
3317 _LIT( KDeleteWordFromTextSearchDict, "DELETE FROM TextSearchDictionary%u WHERE NOT EXISTS(SELECT WordId FROM TextSearch%u WHERE WordId = TextSearchDictionary%u.WordId);"); |
3318 |
3318 |
3319 |
|
3320 RClauseBuffer commonClauseOne(*this, KUpdateDeleteContextObjects().Length() + 3 * KMaxUintValueLength); |
3319 RClauseBuffer commonClauseOne(*this, KUpdateDeleteContextObjects().Length() + 3 * KMaxUintValueLength); |
3321 CleanupClosePushL( commonClauseOne ); |
3320 CleanupClosePushL( commonClauseOne ); |
3322 CMdsClauseBuffer& buffer = commonClauseOne.BufferL(); |
3321 CMdsClauseBuffer& buffer = commonClauseOne.BufferL(); |
3323 |
3322 |
3324 RRowData rowDataDel; |
3323 RRowData rowDataDel; |
3325 CleanupClosePushL( rowDataDel ); |
3324 CleanupClosePushL( rowDataDel ); |
3326 rowDataDel.AppendL( TColumn( EMdEObjectFlagGarbage ) ); |
3325 rowDataDel.AppendL( TColumn( EMdEObjectFlagGarbage ) ); |
3327 |
3326 |
3328 RRowData rowDataUpd; |
|
3329 CleanupClosePushL( rowDataUpd ); |
|
3330 rowDataUpd.AppendL( TColumn( EMdEObjectFlagGarbage ) ); |
|
3331 rowDataUpd.AppendL( TColumn( EMdEObjectFlagRemoved ) ); |
|
3332 |
|
3333 RRowData rowDataDelRel; |
|
3334 CleanupClosePushL( rowDataDelRel ); |
|
3335 rowDataDelRel.AppendL( TColumn( EMdERelationFlagGarbageDeleted ) ); |
|
3336 |
|
3337 RRowData rowDataUpdRel; |
|
3338 CleanupClosePushL( rowDataUpdRel ); |
|
3339 rowDataUpdRel.AppendL( TColumn( EMdERelationFlagGarbageDeleted ) ); |
|
3340 rowDataUpdRel.AppendL( TColumn( EMdERelationFlagDeleted ) ); |
|
3341 |
|
3342 RRowData rowDataDelContext; |
|
3343 CleanupClosePushL( rowDataDelContext ); |
|
3344 rowDataDelContext.AppendL( TColumn( EMdEObjectFlagRemoved ) ); |
|
3345 rowDataDelContext.AppendL( TColumn( EMdEObjectFlagContext ) ); |
|
3346 rowDataDelContext.AppendL( TColumn( EMdERelationFlagDeleted ) ); |
|
3347 |
|
3348 RRowData emptyRow; |
|
3349 CleanupClosePushL( emptyRow ); |
|
3350 |
|
3351 const RPointerArray<CMdsNamespaceDef>& namespaceDefs = |
3327 const RPointerArray<CMdsNamespaceDef>& namespaceDefs = |
3352 iSchema.NamespaceDefs(); |
3328 iSchema.NamespaceDefs(); |
3353 |
3329 |
3354 CMdSSqLiteConnection& connection = MMdSDbConnectionPool::GetDefaultDBL(); |
3330 CMdSSqLiteConnection& connection = MMdSDbConnectionPool::GetDefaultDBL(); |
3355 TInt deleteObjectResult; |
3331 TInt deleteObjectResult = 0; |
3356 TInt updateResult = 0; |
3332 TInt updateResult = 0; |
3357 |
3333 |
3358 const TInt count = namespaceDefs.Count(); |
3334 const TInt count = namespaceDefs.Count(); |
3359 |
3335 |
3360 for( TInt i = 0; i < count; ++i ) |
3336 for( TInt i = 0; i < count; ++i ) |
3361 { |
3337 { |
3362 const TDefId nmspId = namespaceDefs[i]->GetId(); |
3338 const TDefId nmspId = namespaceDefs[i]->GetId(); |
3363 |
3339 |
3364 // deleting objects |
3340 // deleting objects |
3365 buffer.BufferL().Format( KDeleteObject, nmspId ); |
3341 buffer.BufferL().Format( KDeleteObject, nmspId, nmspId ); |
3366 User::LeaveIfError( deleteObjectResult = connection.ExecuteL( |
3342 User::LeaveIfError( deleteObjectResult = connection.ExecuteL( |
3367 buffer.ConstBufferL(), rowDataDel ) ); |
3343 buffer.ConstBufferL(), rowDataDel ) ); |
3368 |
3344 |
|
3345 if( deleteObjectResult > 0 ) |
|
3346 { |
|
3347 // If objects were deleted, continue garbage collection |
|
3348 iDictionaryToBeCleaned = ETrue; |
|
3349 CleanupStack::PopAndDestroy( 2, &commonClauseOne ); |
|
3350 return ETrue; |
|
3351 } |
|
3352 |
|
3353 RRowData rowDataUpd; |
|
3354 CleanupClosePushL( rowDataUpd ); |
|
3355 rowDataUpd.AppendL( TColumn( EMdEObjectFlagGarbage ) ); |
|
3356 rowDataUpd.AppendL( TColumn( EMdEObjectFlagRemoved ) ); |
|
3357 |
3369 buffer.BufferL().Format( KUpdateDeleteObject, nmspId ); |
3358 buffer.BufferL().Format( KUpdateDeleteObject, nmspId ); |
3370 User::LeaveIfError( updateResult += connection.ExecuteL( |
3359 User::LeaveIfError( updateResult += connection.ExecuteL( |
3371 buffer.ConstBufferL(), rowDataUpd ) ); |
3360 buffer.ConstBufferL(), rowDataUpd ) ); |
3372 |
3361 |
|
3362 if( updateResult > 0 ) |
|
3363 { |
|
3364 // If objects were modified, continue garbage collection |
|
3365 CleanupStack::PopAndDestroy( 3, &commonClauseOne ); |
|
3366 return ETrue; |
|
3367 } |
|
3368 |
|
3369 RRowData rowDataDelRel; |
|
3370 CleanupClosePushL( rowDataDelRel ); |
|
3371 rowDataDelRel.AppendL( TColumn( EMdERelationFlagGarbageDeleted ) ); |
|
3372 |
|
3373 RRowData rowDataUpdRel; |
|
3374 CleanupClosePushL( rowDataUpdRel ); |
|
3375 rowDataUpdRel.AppendL( TColumn( EMdERelationFlagGarbageDeleted ) ); |
|
3376 rowDataUpdRel.AppendL( TColumn( EMdERelationFlagDeleted ) ); |
|
3377 |
3373 // deleting relations |
3378 // deleting relations |
3374 buffer.BufferL().Format( KDeleteRelations, nmspId ); |
3379 buffer.BufferL().Format( KDeleteRelations, nmspId ); |
3375 User::LeaveIfError( connection.ExecuteL( |
3380 User::LeaveIfError( connection.ExecuteL( |
3376 buffer.ConstBufferL(), rowDataDelRel ) ); |
3381 buffer.ConstBufferL(), rowDataDelRel ) ); |
3377 |
3382 |
3378 buffer.BufferL().Format( KUpdateDeleteRelations, nmspId ); |
3383 buffer.BufferL().Format( KUpdateDeleteRelations, nmspId ); |
3379 User::LeaveIfError( updateResult += connection.ExecuteL( |
3384 User::LeaveIfError( updateResult += connection.ExecuteL( |
3380 buffer.ConstBufferL(), rowDataUpdRel ) ); |
3385 buffer.ConstBufferL(), rowDataUpdRel ) ); |
3381 |
3386 |
|
3387 if( updateResult > 0 ) |
|
3388 { |
|
3389 // If objects were modified, continue garbage collection |
|
3390 CleanupStack::PopAndDestroy( 5, &commonClauseOne ); |
|
3391 return ETrue; |
|
3392 } |
|
3393 |
|
3394 RRowData rowDataDelContext; |
|
3395 CleanupClosePushL( rowDataDelContext ); |
|
3396 rowDataDelContext.AppendL( TColumn( EMdEObjectFlagRemoved ) ); |
|
3397 rowDataDelContext.AppendL( TColumn( EMdEObjectFlagContext ) ); |
|
3398 rowDataDelContext.AppendL( TColumn( EMdERelationFlagDeleted ) ); |
|
3399 |
3382 // deleting context objects |
3400 // deleting context objects |
3383 buffer.BufferL().Format( KUpdateDeleteContextObjects, nmspId, nmspId, nmspId ); |
3401 buffer.BufferL().Format( KUpdateDeleteContextObjects, nmspId, nmspId, nmspId ); |
3384 User::LeaveIfError( updateResult += connection.ExecuteL( |
3402 User::LeaveIfError( updateResult += connection.ExecuteL( |
3385 buffer.ConstBufferL(), rowDataDelContext ) ); |
3403 buffer.ConstBufferL(), rowDataDelContext ) ); |
3386 |
3404 |
|
3405 if( updateResult > 0 ) |
|
3406 { |
|
3407 // If objects were modified, continue garbage collection |
|
3408 CleanupStack::PopAndDestroy( 6, &commonClauseOne ); |
|
3409 return ETrue; |
|
3410 } |
|
3411 |
|
3412 RRowData emptyRow; |
|
3413 CleanupClosePushL( emptyRow ); |
|
3414 |
3387 // deleting words from text search dictionary |
3415 // deleting words from text search dictionary |
3388 if ( deleteObjectResult > 0 ) |
3416 if ( iDictionaryToBeCleaned ) |
3389 { |
3417 { |
3390 buffer.BufferL().Format( KDeleteWordFromTextSearchDict, nmspId, nmspId, |
3418 buffer.BufferL().Format( KDeleteWordFromTextSearchDict, nmspId, nmspId, |
3391 nmspId ); |
3419 nmspId ); |
3392 User::LeaveIfError( connection.ExecuteL( |
3420 User::LeaveIfError( connection.ExecuteL( |
3393 buffer.ConstBufferL(), emptyRow ) ); |
3421 buffer.ConstBufferL(), emptyRow ) ); |
|
3422 iDictionaryToBeCleaned = EFalse; |
3394 } |
3423 } |
3395 } |
3424 } |
3396 |
3425 |
3397 // empryRow, rowDataDelContext, rowDataUpdRel, rowDataDelRel, rowDataUpd, |
3426 // empryRow, rowDataDelContext, rowDataUpdRel, rowDataDelRel, rowDataUpd, |
3398 // rowDataDel, commonClauseOne |
3427 // rowDataDel, commonClauseOne |