contentpublishingsrv/contentpublishingserver/cpsqlitestorage/inc/cpstorageengine.h
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 11 May 2010 16:30:05 +0300
branchRCL_3
changeset 74 edd621764147
parent 0 79c6a41cd166
permissions -rw-r--r--
Revision: 201017 Kit: 201019

/*
* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:  Database implementation
 *
*/


#ifndef C_CPSTORAGE_ENGINE_H
#define C_CPSTORAGE_ENGINE_H

#include <e32cons.h>
#include <sqldb.h>
#include "cpstorage.h"

// FORWARD DECLARATIONS
#ifdef CONTENT_PUBLISHER_DEBUG
class CCPDebug;
#endif
class MCPChangeNotifier;
class CRepository;
class TLiwVariant;
// CLASS DECLARATION
/**
 *  SQLite based databse for Content Publisher 
 *
 *  @lib cpstorage.dll
 *  @since S60 v5.0
 */
NONSHARABLE_CLASS( CCpStorageEngine ): public CCpStorage
    {
public:

    /**
     * Two-phased constructor.
     */
    static CCpStorageEngine* NewL(TLiwVariant& aDataMapCache);

    /**
     * Two-phased constructor.
     */
    static CCpStorageEngine* NewLC(TLiwVariant& aDataMapCache);

    /**
     * Destructor.
     */
    ~CCpStorageEngine();

    //from CCpStorage

    /**
     * Fetches data from database
     *
     * @param aMap Filtering and sorting criteria
     * @param aList Target for results 
     */
    void GetListL( const CLiwMap* aMap, CLiwGenericParamList& aList );

    /**
     * Adds or Updates data & action to database
     * @param Map containing data item
     * @return id of added entry
     */
    TInt32 AddL( const CLiwMap* aMap );

    /**
     * Remove data item from database
     * @param Filtering and sorting criteria
     */
    void RemoveL( const CLiwMap* aMap );

    /**
     * Set database observer 
     * @param Callback pointer
     */
    void SetCallback( MCPChangeNotifier* aCallback );

private:

    /**
     * Perform the second phase construction of a CCpStorageEngine object.
     */
    void ConstructL(); 

    /**
     * C++ default constructor.
     */
    CCpStorageEngine(TLiwVariant& aDataMapCache);

    /**
     * Creates database tables.
     */
    void CreateTablesL();

    /**
     * Creates new database.
     * If Db is created for the first time,
     * set repository db state into KSQLDBStateNormal  
     */
    void CreateNewDbL();

    /**
     * Deletes database.
     * Called when opening Db try return KSqlErrCorrupt error.
     * Removes KSQLDBStateNormal state and set KSQLDBStateRestored into
     * repository db state.  
     */
    void DeleteCorruptedDbL();

private:

    /**
     * Database.
     * Own. 
     */
    RSqlDatabase iSqlDb;

    /**
     * Callback pointer.
     * Not own.
     */
    MCPChangeNotifier* iCallback;
    
    /**
     * Repository keeps information about Db state.
     * Own.
     */
    CRepository* iRepository;
    
    /**
     * Not own.
     */
    TLiwVariant& iDataMapCache;
#ifdef CONTENT_PUBLISHER_DEBUG
    CCPDebug* iDebug;
#endif
    };

#endif //C_CPSTORAGE_ENGINE_H