mpxplugins/serviceplugins/collectionplugins/mpxsqlitedbcommon/src/mpxdbmanager.cpp
branchRCL_3
changeset 15 a1247965635c
parent 14 c54d95799c80
child 18 56b11cf8addb
equal deleted inserted replaced
14:c54d95799c80 15:a1247965635c
   775         TInt count(iDatabaseHandles.Count());
   775         TInt count(iDatabaseHandles.Count());
   776         for (TInt i = 0; i < count; ++i)
   776         for (TInt i = 0; i < count; ++i)
   777             {
   777             {
   778             if (iDatabaseHandles[i].iDrive == aDrive)
   778             if (iDatabaseHandles[i].iDrive == aDrive)
   779                 {
   779                 {
       
   780                 TBool inTransaction = InTransaction();
   780                 TInt transactionCount = iTransactionCount;
   781                 TInt transactionCount = iTransactionCount;
   781                 if (iTransactionCount > 0) 
   782                 iTransactionCount = 0;								
       
   783 								
       
   784                 if (inTransaction) //if the transaction is ongoing, try committing
   782                     {
   785                     {
   783                     iTransactionCount = 0;
   786                     //if transaction committing fails, try roll-back	
   784                     DoCommitL();
   787                     TInt error = iDatabase.Exec( KCommitTransaction );
       
   788                     if ( error != KErrNone )
       
   789                         {
       
   790                         //The error is ignored since we can't do nothing about it
       
   791                         iDatabase.Exec( KRollbackTransaction ); 
       
   792                         }
   785                     }
   793                     }
   786                 	
   794                 	
   787 #ifdef __RAMDISK_PERF_ENABLE                	
   795 #ifdef __RAMDISK_PERF_ENABLE                	
   788                 if ( iRAMDiskPerfEnabled && iDatabaseHandles[i].iUseRAMdb )
   796                 if ( iRAMDiskPerfEnabled && iDatabaseHandles[i].iUseRAMdb )
   789             	      {
   797             	      {
   809 #endif
   817 #endif
   810                     {
   818                     {
   811                     MPX_DEBUG2("CMPXDbManager::CloseDatabaseL found %d", aDrive);
   819                     MPX_DEBUG2("CMPXDbManager::CloseDatabaseL found %d", aDrive);
   812                     CloseDatabaseAtIndexL( i );
   820                     CloseDatabaseAtIndexL( i );
   813                     }
   821                     }
   814                     
   822                 
   815                 if (transactionCount > 0) 
   823                 //Let MTP handle the transcation if there is any 
       
   824                 if ( inTransaction ) 
   816                     {
   825                     {
   817                     DoBeginL();
   826                     DoBeginL();
   818                     iTransactionCount = transactionCount;
   827                     iTransactionCount = transactionCount;
   819                     }
   828                     }
   820 
   829 
  2804             CopyDBsFromRamL();
  2813             CopyDBsFromRamL();
  2805             }
  2814             }
  2806         else
  2815         else
  2807             {
  2816             {
  2808             TInt size=0;
  2817             TInt size=0;
  2809             TInt err = GetTotalRamDatabasesSize(size);
  2818             TInt err = GetTotalRamDatabasesSizeL(size);
  2810             if ( err || (size > iMaximumAllowedRAMDiskSpaceToCopy) )
  2819             if ( err || (size > iMaximumAllowedRAMDiskSpaceToCopy) )
  2811                 {
  2820                 {
  2812                 // Databases using too much RAM space, copy back to normal drive and continue to harvest.
  2821                 // Databases using too much RAM space, copy back to normal drive and continue to harvest.
  2813                 if ( err )
  2822                 if ( err )
  2814                     {
  2823                     {
  2963     
  2972     
  2964 // ---------------------------------------------------------------------------
  2973 // ---------------------------------------------------------------------------
  2965 // CMPXDbManager::GetTotalRamDatabasesSize
  2974 // CMPXDbManager::GetTotalRamDatabasesSize
  2966 // ---------------------------------------------------------------------------
  2975 // ---------------------------------------------------------------------------
  2967 //
  2976 //
  2968 TInt CMPXDbManager::GetTotalRamDatabasesSize(TInt& aSize)
  2977 TInt CMPXDbManager::GetTotalRamDatabasesSizeL(TInt& aSize)
  2969     {
  2978     {
  2970     MPX_FUNC("CMPXDbManager::GetTotalRamDatabasesSize");
  2979     MPX_FUNC("CMPXDbManager::GetTotalRamDatabasesSize");
  2971     TInt err = KErrNotSupported;
  2980     TInt err = KErrNotSupported;
  2972 #ifdef __RAMDISK_PERF_ENABLE
  2981 #ifdef __RAMDISK_PERF_ENABLE
  2973     TInt size=0;
  2982     TInt size=0;
  2991         temp->Des().Append(iDbFile->Des());
  3000         temp->Des().Append(iDbFile->Des());
  2992         TFileName filename;            
  3001         TFileName filename;            
  2993         filename.Format(KSecurePath, User::Identity().iUid, temp);
  3002         filename.Format(KSecurePath, User::Identity().iUid, temp);
  2994         CleanupStack::PopAndDestroy(temp);
  3003         CleanupStack::PopAndDestroy(temp);
  2995         dbFilename.Append(filename);
  3004         dbFilename.Append(filename);
  2996         MPX_DEBUG2("CMPXDbManager::GetTotalRamDatabasesSize - Database name = %S", &dbFilename);
  3005         MPX_DEBUG2("CMPXDbManager::GetTotalRamDatabasesSizeL - Database name = %S", &dbFilename);
  2997         TEntry entry;
  3006         TEntry entry;
  2998         err = iFs.Entry( dbFilename, entry );
  3007         err = iFs.Entry( dbFilename, entry );
  2999         if ( (err != KErrNone) && (err != KErrNotFound) )
  3008         if ( (err != KErrNone) && (err != KErrNotFound) )
  3000             {
  3009             {
  3001             break;
  3010             break;
  3002             }
  3011             }
  3003         MPX_DEBUG3("CMPXDbManager::GetTotalRamDatabasesSize - Size of Db %S = %d", &dbFilename, entry.iSize);
  3012         MPX_DEBUG3("CMPXDbManager::GetTotalRamDatabasesSizeL - Size of Db %S = %d", &dbFilename, entry.iSize);
  3004         // sum up size
  3013         // sum up size
  3005         size += entry.iSize;
  3014         size += entry.iSize;
  3006         }
  3015         }
  3007     aSize = size;
  3016     aSize = size;
  3008     MPX_DEBUG2("CMPXDbManager::GetTotalRamDatabasesSize - Total Size of Dbs = %d", size);
  3017     MPX_DEBUG2("CMPXDbManager::GetTotalRamDatabasesSizeL - Total Size of Dbs = %d", size);
  3009 #endif //__RAMDISK_PERF_ENABLE    
  3018 #endif //__RAMDISK_PERF_ENABLE    
  3010     MPX_DEBUG2("CMPXDbManager::GetTotalRamDatabasesSize - Return err = %d", err);
  3019     MPX_DEBUG2("CMPXDbManager::GetTotalRamDatabasesSizeL - Return err = %d", err);
  3011     return err;
  3020     return err;
  3012     }
  3021     }
  3013 
  3022 
  3014 // ----------------------------------------------------------------------------
  3023 // ----------------------------------------------------------------------------
  3015 // Creates the absolute database filename on a specified drive.
  3024 // Creates the absolute database filename on a specified drive.