ncdengine/provider/storage/inc/ncddatabasestorageimpl.h
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2006 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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef MCDATABASESTORAGE_H
       
    20 #define MCDATABASESTORAGE_H
       
    21 
       
    22 
       
    23 #include <e32base.h>
       
    24 #include <f32file.h>
       
    25 #include <d32dbms.h> // RDbNamedDatabase
       
    26 
       
    27 #include "ncdstoragebase.h"
       
    28 
       
    29 /**
       
    30  * 
       
    31  */
       
    32 class CNcdDatabaseStorage : public CNcdStorageBase
       
    33 {
       
    34 
       
    35     friend CNcdStorageBase* CNcdStorageBase::NewL( 
       
    36         RFs&, const TDesC&, const TDesC&, 
       
    37         const TDesC& );
       
    38 
       
    39 
       
    40     public: // Destructor
       
    41 
       
    42          virtual ~CNcdDatabaseStorage();
       
    43 
       
    44 
       
    45     protected: // Construction
       
    46 
       
    47          static CNcdDatabaseStorage* NewL(
       
    48             RFs& aFs,
       
    49             const TDesC& aUid,
       
    50             const TDesC& aStorageFolder,
       
    51             const TDesC& aName );
       
    52 
       
    53          CNcdDatabaseStorage( 
       
    54             RFs& aFs,
       
    55             HBufC* aUid, 
       
    56             HBufC* aStorageFolder, 
       
    57             HBufC* aName );
       
    58 
       
    59          void ConstructL();
       
    60 
       
    61 
       
    62     public: // From CNcdStorageBase
       
    63 
       
    64          virtual void Compact();
       
    65          
       
    66          virtual RDbDatabase::TSize Size() const;
       
    67         
       
    68          virtual TInt DoCommit();
       
    69 
       
    70         
       
    71     protected: // From CNcdStorageBase
       
    72 
       
    73          virtual CNcdStorageItem* CreateStorageItemLC( const TDesC& aUid, TInt aType );
       
    74 
       
    75 
       
    76          virtual TBool ItemExistsL( const TDesC& aUid, TInt aType );
       
    77 
       
    78          virtual void DoOpenItemL( CNcdStorageItem* aItem );
       
    79 
       
    80          virtual void DoRollback();
       
    81 
       
    82          virtual void DoRemoveItemL( CNcdStorageItem* aItem );
       
    83 
       
    84          virtual void DoReadDataL( CNcdStorageItem* aItem, MNcdStorageDataItem& aDataItem );
       
    85 
       
    86          virtual void DoWriteDataL( CNcdStorageItem* aItem, MNcdStorageDataItem& aDataItem );
       
    87 
       
    88          virtual void DoOpenL();
       
    89 
       
    90          virtual void DoClose();
       
    91 
       
    92          virtual void GetAllItemsFromStorageL( RPointerArray<CNcdStorageItemIdentifier>& aItems );
       
    93 
       
    94          virtual HBufC8* DoGetDataL( CNcdStorageItem* aItem );
       
    95 
       
    96          virtual void DoRemoveItemsL( 
       
    97             const RArray<RNcdDatabaseItems>& aDoNotRemoveItems );
       
    98 
       
    99 
       
   100     private: // New methods
       
   101 
       
   102         TInt CalculateSqlRemovalLength( 
       
   103             const RNcdDatabaseItems& aItem ) const;
       
   104 
       
   105 
       
   106         inline TBool BeginTransactionL();
       
   107 
       
   108         inline TBool CloseTransactionL( TBool aForceClose = EFalse );
       
   109 
       
   110         inline void ReadItemDataLC(
       
   111             RDbView& aItemData,
       
   112             const TDesC& aUid,
       
   113             TInt aType,
       
   114             RDbRowSet::TAccess aAccess = RDbRowSet::EReadOnly );
       
   115 
       
   116         inline void ReadItemDataLC(
       
   117             RDbView& aItemData,
       
   118             TUint32 aKey,
       
   119             RDbRowSet::TAccess aAccess = RDbRowSet::EReadOnly );
       
   120             
       
   121         void RecreateDatabaseL();
       
   122 
       
   123 
       
   124     private:
       
   125 
       
   126 
       
   127         RFs&                    iFs;
       
   128 
       
   129         HBufC*                  iDatabaseFileName;
       
   130 
       
   131         RDbNamedDatabase        iDb;
       
   132 
       
   133         TBool                   iUpdated;
       
   134 
       
   135         TInt                    iWastedSpace;
       
   136 
       
   137         TInt                    iNewWastedSpace;
       
   138     };
       
   139 
       
   140 
       
   141 class CNcdDatabaseStorageItem : public CNcdStorageItem
       
   142     {
       
   143 
       
   144     public:
       
   145 
       
   146 
       
   147         static CNcdDatabaseStorageItem* NewLC(
       
   148             CNcdStorageBase* aStorage,
       
   149             const TDesC& aUid,
       
   150             TInt aType,
       
   151             TUint32 aDbKey = 0 );
       
   152 
       
   153 
       
   154         virtual ~CNcdDatabaseStorageItem();
       
   155 
       
   156 
       
   157     public:
       
   158 
       
   159 
       
   160         void SetDbKey( TUint32 aDbKey );
       
   161 
       
   162         TUint32 DbKey() const;
       
   163 
       
   164 
       
   165     protected:
       
   166 
       
   167         CNcdDatabaseStorageItem( CNcdStorageBase* aStorage, TUint32 aDbKey );
       
   168 
       
   169     private:
       
   170 
       
   171         TUint32            iDbKey;
       
   172     };
       
   173 
       
   174 #endif