ncdengine/provider/server/inc/ncdnodedbmanager.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:   Contains CNcdNodeDbManager class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef NCD_NODE_DB_MANAGER_H
       
    20 #define NCD_NODE_DB_MANAGER_H
       
    21 
       
    22 
       
    23 #include <e32base.h>
       
    24 #include <f32file.h>
       
    25 #include <e32cmn.h>
       
    26 #include <bamdesca.h>
       
    27 
       
    28 #include "ncdstoragedataitem.h"
       
    29 #include "ncdnodeclassids.h"
       
    30 #include "ncddatabaseitems.h"
       
    31 
       
    32 class MNcdStorageManager;
       
    33 class MNcdStorage;
       
    34 class CNcdNodeIdentifier;
       
    35 
       
    36 /**
       
    37  *  CNodeDbManager provides functions manage 
       
    38  *  node db information. Functions to read, write and remove
       
    39  *  data are provided.
       
    40  */
       
    41 class CNcdNodeDbManager : public CBase
       
    42     {
       
    43 
       
    44 public:
       
    45 
       
    46     /**
       
    47      * NewL
       
    48      *
       
    49      * @return CNcdNodeDbManager* Pointer to the created object 
       
    50      * of this class.
       
    51      */
       
    52     static CNcdNodeDbManager* NewL(
       
    53         MNcdStorageManager& aStorageManager );
       
    54 
       
    55     /**
       
    56      * NewLC
       
    57      *
       
    58      * @return CNcdNodeDbManager* Pointer to the created object 
       
    59      * of this class.
       
    60      */
       
    61     static CNcdNodeDbManager* NewLC(
       
    62         MNcdStorageManager& aStorageManager );
       
    63 
       
    64 
       
    65     /**
       
    66      * Destructor
       
    67      *
       
    68      * Deletes the nodes from the node cache.
       
    69      */
       
    70     virtual ~CNcdNodeDbManager();
       
    71 
       
    72 
       
    73 public: // Node db manager configuration functions    
       
    74 
       
    75     /**
       
    76      * Adds the given identifier to the list of nodes that are never removed from DB.
       
    77      *
       
    78      * @param aIdentifier The node identifier.
       
    79      */
       
    80     void AddDoNotRemoveNodeIdentifierL( const CNcdNodeIdentifier& aNodeIdentifier );
       
    81     
       
    82     /**
       
    83      * Adds the given identifiers to the list of nodes that are never removed from DB.
       
    84      *
       
    85      * @param aIdentifiers The node identifiers.
       
    86      */
       
    87     void AddDoNotRemoveNodeIdentifiersL(
       
    88         const RPointerArray<CNcdNodeIdentifier>& aNodeIdentifiers );
       
    89      
       
    90     /**
       
    91      * Removes the given identifier from the list of nodes that are never removed from DB.
       
    92      *
       
    93      * @param aIdentifier The node identifier.
       
    94      */
       
    95     void RemoveDoNotRemoveNodeIdentifier( const CNcdNodeIdentifier& aNodeIdentifier );
       
    96 
       
    97 public: // Database info functions
       
    98 
       
    99     /**
       
   100      * @param aClientUid The uid of the client whose storage is 
       
   101      * examined.
       
   102      * @param aSkipNamespaces The sizes of these namespaces are ignored when
       
   103      * the total size is calculated. Ownership is not transferred.
       
   104      * @return TInt the size in bytes of the whole storage
       
   105      * of the specified client.
       
   106      */
       
   107     TInt StorageSizeL( const TUid& aClientUid,
       
   108                        const MDesCArray& aSkipNamespaces );
       
   109         
       
   110 
       
   111 public: // Database read functions
       
   112     
       
   113     /**
       
   114      * Reads binary data from the database
       
   115      * @param aIdentifier Contains id information that is
       
   116      * used to read right info from db.
       
   117      * @param aClassType Type of the data.
       
   118      * @return HBufC8* Data from db.
       
   119      */
       
   120     HBufC8* ReadDataFromDatabaseL( 
       
   121         const CNcdNodeIdentifier& aIdentifier,
       
   122         const NcdNodeClassIds::TNcdNodeClassType aClassType );
       
   123     
       
   124     /**
       
   125      * @see CNcdNodeDbManager::ReadDataFromDatabaseL
       
   126      */                                
       
   127     HBufC8* ReadDataFromDatabaseLC( 
       
   128         const CNcdNodeIdentifier& aIdentifier,
       
   129         const NcdNodeClassIds::TNcdNodeClassType aClassType );
       
   130 
       
   131 
       
   132     /** 
       
   133      * This function is used to start the database action
       
   134      * that will get the data for some object from the
       
   135      * storage database.
       
   136      * After the data has been found from the storage,
       
   137      * InternalizeL function of the given data item is called.
       
   138      *
       
   139      * @param aIdentifier Contains id information that is
       
   140      * used to read right info from db.
       
   141      * @param aDataItem InternalizeL of this object is called
       
   142      * when the data is read from db.
       
   143      * @param aClassType Type of the data.
       
   144      */    
       
   145     void StartStorageLoadActionL( 
       
   146         const CNcdNodeIdentifier& aIdentifier,
       
   147         MNcdStorageDataItem& aDataItem,
       
   148         const NcdNodeClassIds::TNcdNodeClassType aClassType );
       
   149 
       
   150 
       
   151     /** 
       
   152      *  This function will return the array about the identifiers found from
       
   153      *  the database. Parameters provide ways to limit what identifiers
       
   154      *  should be included in return array.
       
   155      *
       
   156      *  @note Identifiers are included into the array only once. So, if
       
   157      *  multiple db items with different types are having same identifier,
       
   158      *  the identifier will be added to target array only once.
       
   159      *
       
   160      *  @param RPointerArray<CNcdNodeIdentifier> Array that will contain
       
   161      *  identifiers of the database items. Ownership of the identifiers
       
   162      *  are transmitted for the user of the array.
       
   163      *  @param aClientUid Identifies the client whose data is searched.
       
   164      *  @param aSkipNamespaces This array contains the namespaces whose
       
   165      *  data should not be returned.
       
   166      *  @param aAcceptClassType This array contains the class types that
       
   167      *  are accepted for the items. The items of the class types 
       
   168      *  that are not included in this array will not be included into
       
   169      *  the return array.
       
   170      */
       
   171     void GetAllClientItemIdentifiersL( 
       
   172         RPointerArray<CNcdNodeIdentifier>& aItemIdentifiers,
       
   173         const TUid& aClientUid,
       
   174         const MDesCArray& aSkipNamespaces,
       
   175         const RArray<NcdNodeClassIds::TNcdNodeClassType>& aAcceptClassTypes );
       
   176                              
       
   177 
       
   178 public: // Database write functions
       
   179 
       
   180     /**
       
   181      * This function is used to start the database action
       
   182      * that will save the data of the data item into the db.
       
   183      * The ExternalizeL function of the data item is called.
       
   184      * So, the item may insert its data into the given stream.
       
   185      *
       
   186      * @param aIdentifier Contains id information that is
       
   187      * used to read right info from db.
       
   188      * @param aDataItem ExternalizeL of this object is called
       
   189      * when the data is written into db.
       
   190      * @param aClassType Type of the data.
       
   191      */
       
   192     void SaveDataIntoDatabaseL( 
       
   193         const CNcdNodeIdentifier& aIdentifier,
       
   194         MNcdStorageDataItem& aDataItem,
       
   195         const NcdNodeClassIds::TNcdNodeClassType aClassType );        
       
   196 
       
   197 
       
   198 public: // Database remove functions
       
   199 
       
   200     /**
       
   201      * Removes certain data row from the db table according
       
   202      * to the given values that are used as the key values.
       
   203      *
       
   204      * @param aIdentifier The identifier that contains key values.
       
   205      * @param aClassType The class type tells the general type of the data
       
   206      * that should be removed.
       
   207      */
       
   208     void RemoveDataFromDatabaseL( 
       
   209         const CNcdNodeIdentifier& aIdentifier,
       
   210         const NcdNodeClassIds::TNcdNodeClassType aClassType );        
       
   211 
       
   212     /**
       
   213      * Removes certain data rows from the db table according
       
   214      * to the given values that are used as the key values.
       
   215      * This works like the function above, but commits the
       
   216      * removal operation rarely. This should speed
       
   217      * up the removal process.
       
   218      *
       
   219      * @see CNcdNodeDbManager::RemoveDataFromDatabaseL
       
   220      *
       
   221      * @param aIdentifiers The identifier array that contains key values. 
       
   222      * Ownership is not tranferred.
       
   223      * @param aClassTypes The class type array tells the general types of the data
       
   224      * that should be removed. Ownership is not transferred.
       
   225      */
       
   226     void RemoveDataFromDatabaseL( 
       
   227         const RPointerArray<CNcdNodeIdentifier>& aIdentifiers,
       
   228         const RArray<NcdNodeClassIds::TNcdNodeClassType>& aClassTypes,
       
   229         TBool aCompact = ETrue );
       
   230     
       
   231     
       
   232     /**
       
   233      * Removes everything except identifiers that are in the do not remove list
       
   234      *  
       
   235      * @param aNodeIdentifier Used to get the correct storage   
       
   236      */
       
   237     void RemoveDataFromDatabaseL( 
       
   238         const CNcdNodeIdentifier& aNodeIdentifier,
       
   239         const RArray<RNcdDatabaseItems>& aDoNotRemoveItems );
       
   240 
       
   241     
       
   242     /**
       
   243      * Clears client's storage
       
   244      *
       
   245      * @note All of client's files and databases are 
       
   246      * deleted except the ones that are having namespaces
       
   247      * defined in the skip array.
       
   248      *
       
   249      * @param aClientUid Client's uid identifier
       
   250      * @param aSkipNamespaces Array contains the descriptors of
       
   251      * namespaces that should not be cleared. Ownership is not
       
   252      * transferred.
       
   253      */
       
   254     void ClearClientL( const TUid& aClientUid,
       
   255                        const MDesCArray& aSkipNamespaces );
       
   256     
       
   257     
       
   258 protected:
       
   259 
       
   260     /**
       
   261      * Constructor
       
   262      */
       
   263     CNcdNodeDbManager( MNcdStorageManager& aStorageManager );
       
   264 
       
   265     /**
       
   266      * ConstructL
       
   267      */
       
   268     virtual void ConstructL();
       
   269 
       
   270 
       
   271     /**
       
   272      * Returns an old storage or creates a new one if necessary.
       
   273      * Storage will contain the information of the certain client
       
   274      * that has been identifier by its UID.
       
   275      *
       
   276      * @param aIdentifier Identifies what storage is wanted.
       
   277      * @return MNcdStorage& Storage matching the identifier info.
       
   278      * @exception KErrArgument if aIdentifier contains empty fields.
       
   279      * In other error situations, system wide error code.
       
   280      */
       
   281     MNcdStorage& StorageL( const CNcdNodeIdentifier& aIdentifier  ) const;
       
   282 
       
   283 
       
   284     TInt RemoveDataFromNamespaceL( 
       
   285         const RPointerArray<CNcdNodeIdentifier>& aDoNotRemoveIds,
       
   286         TInt aIndex, 
       
   287         TInt aEnd );
       
   288                           
       
   289     
       
   290 private:
       
   291 
       
   292     // Prevent if not implemented
       
   293     CNcdNodeDbManager( const CNcdNodeDbManager& aObject );
       
   294     CNcdNodeDbManager& operator =( const CNcdNodeDbManager& aObject );
       
   295     
       
   296     
       
   297 private: // data
       
   298 
       
   299     // Storage manager is used to load and to save data from
       
   300     // databases.
       
   301     MNcdStorageManager& iStorageManager;
       
   302     
       
   303     };
       
   304 
       
   305 
       
   306 #endif // NCD_NODE_DB_MANAGER_H