upnpharvester/common/cmsqlwrapper/src/cmsqldbmaintenance.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:      SQL database maintenance class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 #include "cmsqldbmaintenance.h"
       
    24 #include "cmsqlconnection.h"
       
    25 #include "cmsqlmaintenanceclauses.h"
       
    26 #include "msdebug.h" 
       
    27 
       
    28 // Constants
       
    29 _LIT(KCmSqlDatabase, "C:\\System\\Data\\MediaServant\\cmmetadatacache.sq");
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 // CCmSqlDbMaintenance::NewL
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 CCmSqlDbMaintenance* CCmSqlDbMaintenance::NewL()
       
    36     {
       
    37     LOG(_L("[SQL Wrapper]\t CCmSqlDbMaintenance::NewL"));
       
    38         
       
    39     CCmSqlDbMaintenance* self = CCmSqlDbMaintenance::NewLC();
       
    40     CleanupStack::Pop( self );
       
    41     return self;
       
    42     }
       
    43  
       
    44 // ---------------------------------------------------------------------------
       
    45 // CCmSqlDbMaintenance::NewLC
       
    46 // ---------------------------------------------------------------------------
       
    47 //    
       
    48 CCmSqlDbMaintenance* CCmSqlDbMaintenance::NewLC()
       
    49     {
       
    50     LOG(_L("[SQL Wrapper]\t CCmSqlDbMaintenance::NewLC"));   
       
    51     
       
    52     CCmSqlDbMaintenance* self = new ( ELeave ) CCmSqlDbMaintenance();
       
    53     CleanupStack::PushL( self );
       
    54     self->ConstructL();
       
    55     return self;  
       
    56     }    
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // CCmSqlDbMaintenance::~CCmSqlDbMaintenance
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 CCmSqlDbMaintenance::~CCmSqlDbMaintenance()
       
    63     {
       
    64     LOG(_L("[SQL Wrapper]\t CCmSqlDbMaintenance::~CCmSqlDbMaintenance"));   
       
    65     }
       
    66     
       
    67 // ---------------------------------------------------------------------------
       
    68 // CCmSqlDbMaintenance::InitConnection
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 TInt CCmSqlDbMaintenance::InitConnection(
       
    72     CCmSqlConnection& aConnection )
       
    73     {
       
    74     LOG(_L("[SQL Wrapper]\t CCmSqlDbMaintenance::InitConnection"));   
       
    75     
       
    76     return aConnection.OpenDb( KCmSqlDatabase );   
       
    77     }    
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // CCmSqlDbMaintenance::CloseConnection
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 void CCmSqlDbMaintenance::CloseConnection(
       
    84     CCmSqlConnection& aConnection )
       
    85     {
       
    86     LOG(_L("[SQL Wrapper]\t CCmSqlDbMaintenance::CloseConnection"));   
       
    87     
       
    88     aConnection.CloseDb();        
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // CCmSqlDbMaintenance::CreateDbFile
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 TInt CCmSqlDbMaintenance::CreateDbFile( CCmSqlConnection& aConnection )
       
    96     {
       
    97     LOG(_L("[SQL Wrapper]\t CCmSqlDbMaintenance::CreateDbFile"));   
       
    98     
       
    99     return aConnection.CreateDbFile( KCmSqlDatabase );
       
   100     }
       
   101     
       
   102 // ---------------------------------------------------------------------------
       
   103 // CCmSqlDbMaintenance::CreateDb
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 void CCmSqlDbMaintenance::CreateDb( 
       
   107     CCmSqlConnection& aConnection )
       
   108     {
       
   109     LOG(_L("[SQL Wrapper]\t CCmSqlDbMaintenance::CreateDb"));
       
   110     LOG(_L("[SQL wrapper]\t Dropping tables..."));
       
   111     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlDropArtists ));
       
   112     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlDropGenres ));
       
   113     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlDropAlbums ));
       
   114     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlDropResolutions ));
       
   115     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlDropUpnpProfiles ));
       
   116     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlDropUpnpClasses ));  
       
   117     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlDropResources ));
       
   118     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlDropItems ));
       
   119            
       
   120     LOG(_L("[SQL wrapper]\t Creating tables..."));
       
   121     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlCreateArtists ) );    
       
   122     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlCreateGenres ) );
       
   123     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlCreateAlbums ) );      
       
   124     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlCreateResolutions ) );
       
   125     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlCreateUpnpProfiles ) ); 
       
   126     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlCreateUpnpclasses ) );
       
   127     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlCreateResources ) );
       
   128     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlCreateItems ) );     
       
   129     }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // CCmSqlDbMaintenance::CreateIndexes
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 void CCmSqlDbMaintenance::CreateIndexes( 
       
   136     CCmSqlConnection& aConnection )
       
   137     {
       
   138     LOG(_L("[SQL Wrapper]\t CCmSqlDbMaintenance::CreateIndexes"));
       
   139     
       
   140     LOG(_L("[SQL wrapper]\t Dropping indexes..."));
       
   141     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlDropItemsIdIndex ) );
       
   142     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlDropItemTitleIndex ) );
       
   143     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlDropItemArtistIndex ) );
       
   144     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlDropItemAlbumIndex ) );
       
   145     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlDropItemGenreIndex ) );
       
   146     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlDropItemUpnpclassIndex ) );
       
   147     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlDropItemResolutionIndex ) );
       
   148     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlDropItemDateIndex ) );
       
   149     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlDropItemHarvestDateIndex ) );
       
   150     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlDropItemUpnpProfileIndex ) );
       
   151     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlDropItemMediatypeIndex ) );
       
   152     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlDropAlbumIdIndex ) );
       
   153     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlDropArtistIdIndex ) );
       
   154     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlDropGenreIdIndex ) );
       
   155     
       
   156     LOG(_L("[SQL wrapper]\t Creating indexes..."));
       
   157     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlCreateItemsIdIndex ) );
       
   158     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlCreateItemTitleIndex ) );
       
   159     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlCreateItemArtistIndex ) );
       
   160     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlCreateItemAlbumIndex ) );
       
   161     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlCreateItemGenreIndex ) );
       
   162     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlCreateItemUpnpclassIndex ) );
       
   163     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlCreateItemResolutionIndex ) );
       
   164     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlCreateItemDateIndex ) );
       
   165     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlCreateItemHarvestDateIndex ) );
       
   166     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlCreateItemUpnpProfileIndex ) );
       
   167     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlCreateItemMediatypeIndex ) );
       
   168     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlCreateAlbumIdIndex ) );
       
   169     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlCreateArtistIdIndex ) );
       
   170     TRAP_IGNORE( aConnection.ExecuteL( KCmSqlCreateGenreIdIndex ) );
       
   171     }
       
   172                 
       
   173 // ---------------------------------------------------------------------------
       
   174 // CCmSqlDbMaintenance::CCmSqlDbMaintenance
       
   175 // ---------------------------------------------------------------------------
       
   176 //    
       
   177 CCmSqlDbMaintenance::CCmSqlDbMaintenance()
       
   178     {
       
   179     LOG(_L("[SQL Wrapper]\t CCmSqlDbMaintenance::CCmSqlDbMaintenance"));
       
   180     }
       
   181  
       
   182 // ---------------------------------------------------------------------------
       
   183 // CCmSqlDbMaintenance::ConstructL
       
   184 // ---------------------------------------------------------------------------
       
   185 //   
       
   186 void CCmSqlDbMaintenance::ConstructL()
       
   187     {
       
   188     LOG(_L("[SQL Wrapper]\t CCmSqlDbMaintenance::ConstructL"));
       
   189     }    
       
   190 
       
   191 // End of file
       
   192