browserutilities/favouritesengine/ClientServer/srvinc/FavouritesSrvTable.h
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2004 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 the License "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 *      Declaration of class RFavouritesSrvTable.
       
    16 *      
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #ifndef FAVOURITES_SRV_TABLE_H
       
    22 #define FAVOURITES_SRV_TABLE_H
       
    23 
       
    24 //  INCLUDES
       
    25 
       
    26 #include <e32base.h>
       
    27 #include <d32dbms.h>
       
    28 #include "FavouritesItemImpl.h"
       
    29 
       
    30 // FORWARD DECLARATION
       
    31 
       
    32 class MFavouritesItemData;
       
    33 class TFavouritesFilter;
       
    34 class MStreamBuf;
       
    35 
       
    36 // CLASS DECLARATION
       
    37 
       
    38 /**
       
    39 * Database table for favourites data.
       
    40 * This class provides the way to access / manipulate database tables, which
       
    41 * store favourites data in the table structure defined by the FavouritesEngine.
       
    42 * Its purpose is to hide the underlying table structure.
       
    43 * It does not provide data validation or sanity checks, and is not intended
       
    44 * to be used by users.
       
    45 */
       
    46 NONSHARABLE_CLASS(RFavouritesSrvTable): public RDbTable
       
    47     {
       
    48 
       
    49     public:     // opening / closing with cleanup support
       
    50 
       
    51         /**
       
    52         * Open the table on this database, push a Close on the
       
    53         * cleanup stack.
       
    54         * @param aDb Open table on this database.
       
    55         * @param aAccess Access mode.
       
    56         * @return Error code.
       
    57         */
       
    58         void OpenL
       
    59             (
       
    60             RDbNamedDatabase& aDb,
       
    61             RDbRowSet::TAccess aAccess = RDbRowSet::EUpdatable
       
    62             );
       
    63 
       
    64         /**
       
    65         * Close the table, pop the cleanup item.
       
    66         */
       
    67         void Close();
       
    68 
       
    69     public:     // update with cleanup support
       
    70 
       
    71         /**
       
    72         * Begin insertion, push a Cancel on the cleanup stack.
       
    73         */
       
    74         void InsertLC();
       
    75 
       
    76         /**
       
    77         * Begin update, push a Cancel on the cleanup stack.
       
    78         */
       
    79         void UpdateLC();
       
    80 
       
    81         /**
       
    82         * Apply changes to database, pop the cleanup item.
       
    83         * @param aTouch If ETrue (the default), last modification time is set
       
    84         * to current universal time.
       
    85         */
       
    86         void PutL( TBool aTouch = ETrue );
       
    87 
       
    88         /**
       
    89         * Cancel changes to database, pop the cleanup item.
       
    90         */
       
    91         void Cancel();
       
    92 
       
    93     public:     // Navigation, filtering
       
    94 
       
    95         /**
       
    96         * Set filters.
       
    97         * @param aFilter Filters.
       
    98         */
       
    99         void SetFiltersL( const TFavouritesFilter& aFilter );
       
   100 
       
   101         /**
       
   102         * Clear filters (all records accepted).
       
   103         */
       
   104         void ClearFilters();
       
   105 
       
   106         /**
       
   107         * Goto next record. If filtering is on, filters are considered.
       
   108         * Otherwise it is eqivalent to base class method.
       
   109         * @return ETrue if positioned on a record.
       
   110         */
       
   111         TBool NextL();
       
   112 
       
   113         /**
       
   114         * Goto record having this Uid. Filters are not considered.
       
   115         * @param aUid Uid of record to go to.
       
   116         * @return ETrue if positioned on a record.
       
   117         */
       
   118         TBool SeekToUidL( TInt aUid );
       
   119 
       
   120         /**
       
   121         * Goto record having this Uid. Filters are not considered.
       
   122         * Leaves with KErrNotFound if no such record exists.
       
   123         * @param aUid Uid of record to go to.
       
   124         */
       
   125         void GotoToUidL( TInt aUid );
       
   126 
       
   127     public:     // data retrieval
       
   128 
       
   129         /**
       
   130         * Read the data from the current row to aItem. Row data must have
       
   131         * been gotten; no validation or sanity check is performed.
       
   132         * @param aItem This item is filled with data from the
       
   133         * current row.
       
   134         */
       
   135         void ReadItemDataL( CFavouritesItemImpl& aItem ) const;
       
   136 
       
   137         /**
       
   138         * Get Uid from the current row. Row data must have been retrieved;
       
   139         * no sanity check.
       
   140         * @return The Uid in the current row.
       
   141         */
       
   142         TInt Uid() const;
       
   143 
       
   144         /**
       
   145         * Get Parent Folder Uid from the current row. Row data must have
       
   146         * been retrieved; no sanity check.
       
   147         * @return Parent Folder's Uid in the current row.
       
   148         */
       
   149         TInt ParentFolder() const;
       
   150 
       
   151         /**
       
   152         * Get type from the current row. Row data must have
       
   153         * been retrieved; no sanity check.
       
   154         * @return Type in the current row.
       
   155         */
       
   156         CFavouritesItem::TType Type() const;
       
   157 
       
   158         /**
       
   159         * Get name from the current row. Row data must have been retrieved;
       
   160         * no sanity check.
       
   161         * @return Pointer containing the name in the current row.
       
   162         */
       
   163         TPtrC Name() const;
       
   164 
       
   165         /**
       
   166         * Get URL from the current row. Row data must have been retrieved;
       
   167         * no sanity check.
       
   168         * @return Buffer containing the URL in the current row. Owner is
       
   169         * the caller.
       
   170         */
       
   171         HBufC* UrlLC() const;
       
   172 
       
   173         /**
       
   174         * Get Wap AP from the current row. Row data must have been retrieved;
       
   175         * no sanity check.
       
   176         * @return WAP AP in the current row.
       
   177         */
       
   178         TFavouritesWapAp WapAp() const;
       
   179 
       
   180         /**
       
   181         * Get username from the current row. Row data must have been retrieved;
       
   182         * no sanity check.
       
   183         * @return Pointer containing the name in the current row.
       
   184         */
       
   185         TPtrC Username() const;
       
   186 
       
   187         /**
       
   188         * Get password from the current row. Row data must have been retrieved;
       
   189         * no sanity check.
       
   190         * @return Pointer containing the name in the current row.
       
   191         */
       
   192         TPtrC Password() const;
       
   193 
       
   194         /**
       
   195         * Get extra data from the current row. Row data must have been
       
   196         * retrieved; no sanity check.
       
   197         * @param aSink Data sink.
       
   198         */
       
   199         void GetExtraDataL( MStreamBuf& aSink );
       
   200 
       
   201         /**
       
   202         * Get Browser data from the current row. Row data must have been
       
   203         * retrieved; no sanity check.
       
   204         * @param aSink Data sink.
       
   205         */
       
   206         void GetBrowserDataL( MStreamBuf& aSink );
       
   207 
       
   208         /**
       
   209         * Get "factory item" flag from the current row. Row data must have
       
   210         * been retrieved; no sanity check.
       
   211         * @return "Factory item" flag.
       
   212         */
       
   213         TBool FactoryItem() const;
       
   214 
       
   215         /**
       
   216         * Get "read-only" flag from the current row. Row data must have
       
   217         * been retrieved; no sanity check.
       
   218         * @return "Read-only" flag.
       
   219         */
       
   220         TBool ReadOnly() const;
       
   221 
       
   222         /**
       
   223         * Get context id from the current row. Row data must have been
       
   224         * retrieved; no sanity check.
       
   225         * @return The context id in the current row.
       
   226         */
       
   227         TInt32 ContextId() const;
       
   228 
       
   229         /**
       
   230         * Get last modification time from the current row. Row data must have
       
   231         * been retrieved; no sanity check.
       
   232         * @return The last modification time in the current row, or zero (0)
       
   233         * if not available.
       
   234         */
       
   235         TTime Modified() const;
       
   236 
       
   237         /**
       
   238         * Get preferred uid from the current row. Row data must have been
       
   239         * retrieved; no sanity check.
       
   240         * @return The preferred uid in the current row.
       
   241         */
       
   242         TInt PreferredUid() const;
       
   243 
       
   244         /**
       
   245         * Get "Hidden" flag from the current row. Row data must have
       
   246         * been retrieved; no sanity check.
       
   247         * @return "Hidden" flag.
       
   248         */
       
   249         TBool Hidden() const;
       
   250     public:     // data update
       
   251 
       
   252         /**
       
   253         * Write the data from aItem to the current row. The table must be
       
   254         * inserting or updating a row; no validation or sanity check is
       
   255         * performed. The current row must not be read-only.
       
   256         * @param aItem Data from this item (except Uid and read-only flag) will
       
   257         * be written to the current row.
       
   258         */
       
   259         void WriteItemDataL( const CFavouritesItemImpl& aItem );
       
   260 
       
   261         /**
       
   262         * Set Uid to the current row. The table must be
       
   263         * updating or inserting a row. No sanity check.
       
   264         * @param aUid Uid to be written to the current row.
       
   265         */
       
   266         void SetUidL( TInt aUid );
       
   267 
       
   268         /**
       
   269         * Set Parent Folder Uid to the current row. The table must be
       
   270         * updating or inserting a row. No sanity check.
       
   271         * @param aUid Parent Folder's Uid to be written to the current row.
       
   272         */
       
   273         void SetParentFolderL( TInt aUid );
       
   274 
       
   275         /**
       
   276         * Set type to the current row. The table must be
       
   277         * updating or inserting a row. No sanity check.
       
   278         * @param aType Type be written to the current row.
       
   279         */
       
   280         void SetTypeL( CFavouritesItem::TType aType );
       
   281 
       
   282         /**
       
   283         * Set name to the current row. The table must be
       
   284         * updating or inserting a row. No sanity check.
       
   285         * @param aName Name to be written to the current row.
       
   286         */
       
   287         void SetNameL( const TDesC& aName );
       
   288 
       
   289         /**
       
   290         * Set URL to the current row. The table must be
       
   291         * updating or inserting a row. No sanity check.
       
   292         * @param aUrl URL to be written to the current row.
       
   293         */
       
   294         void SetUrlL( const TDesC& aUrl );
       
   295 
       
   296         /**
       
   297         * Set WAP AP to the current row. The table must be
       
   298         * updating or inserting a row. No sanity check.
       
   299         * @param aWapAp WAP AP to be written to the current row.
       
   300         */
       
   301         void SetWapApL( const TFavouritesWapAp& aWapAp );
       
   302 
       
   303         /**
       
   304         * Set username to the current row. The table must be
       
   305         * updating or inserting a row. No sanity check.
       
   306         * @param aUsername Username to be written to the current row.
       
   307         */
       
   308         void SetUsernameL( const TDesC& aUsername );
       
   309 
       
   310         /**
       
   311         * Set password to the current row. The table must be
       
   312         * updating or inserting a row. No sanity check.
       
   313         * @param aPassword Password to be written to the current row.
       
   314         */
       
   315         void SetPasswordL( const TDesC& aPassword );
       
   316 
       
   317         /**
       
   318         * Set extra data to the current row. The table must be
       
   319         * updating or inserting a row. No sanity check.
       
   320         * @param aSource Data source.
       
   321         */
       
   322         void SetExtraDataL( MStreamBuf& aSource );
       
   323 
       
   324         /**
       
   325         * Set Browser data to the current row. The table must be
       
   326         * updating or inserting a row. No sanity check.
       
   327         * @param aSource Data source.
       
   328         */
       
   329         void SetBrowserDataL( MStreamBuf& aSource );
       
   330 
       
   331         /**
       
   332         * Set "factory item" flag. The table must be
       
   333         * updating or inserting a row. No sanity check.
       
   334         * @param aFactoryItem "Factory item" flag to be written to the current
       
   335         * row.
       
   336         */
       
   337         void SetFactoryItemL( TBool aFactoryItem );
       
   338 
       
   339         /**
       
   340         * Set "read-only" flag. The table must be
       
   341         * updating or inserting a row. No sanity check.
       
   342         * @param aReadOnly "Read-only"" flag to be written to the current
       
   343         * row.
       
   344         */
       
   345         void SetReadOnlyL( TBool aReadOnly );
       
   346 
       
   347         /**
       
   348         * Set context id to the current row. The table must be
       
   349         * updating or inserting a row. No sanity check.
       
   350         * @param aContextId Context id to be written to the current row.
       
   351         */
       
   352         void SetContextIdL( TInt32 aContextId );
       
   353 
       
   354         /**
       
   355         * Set last modification time to the current row. The table must be
       
   356         * updating or inserting a row. No sanity check.
       
   357         * Note: the database may not store this kind of data. This error is
       
   358         * silently ignored.
       
   359         * @param aModified Last modification time to be written to the current
       
   360         * row.
       
   361         */
       
   362         void SetModifiedL( TTime aModified );
       
   363 
       
   364         /**
       
   365         * Set preferred uid to the current row. The table must be
       
   366         * updating or inserting a row. No sanity check.
       
   367         * @param aUid Preferred uid to be written to the current row.
       
   368         */
       
   369         void SetPreferredUidL( TInt aUid );
       
   370 
       
   371         /**
       
   372         * Set hidden value to the current row. The table must be
       
   373         * updating or inserting a row. No sanity check.
       
   374         * @param aHidden hidden value to be written to the current row.
       
   375         */
       
   376         void SetHiddenL( TBool aHidden );
       
   377     public:     // utility
       
   378 
       
   379         /**
       
   380         * Place a write-lock. The cursor is positioned on an invalid row.
       
   381         */
       
   382         void PutWriteLockL();
       
   383 
       
   384     public:     // creating database structure
       
   385 
       
   386         /**
       
   387         * Create the appropriate structure (table, columns, indexes) in aDb.
       
   388         * @param aDb The database to be used. Must be open.
       
   389         */
       
   390         static void CreateStructureL( RDbNamedDatabase& aDb );
       
   391 
       
   392         /**
       
   393         * Verify the appropriate structure (columns, indexes) in aDb.
       
   394         * @param aDb The database to be used. Must be open, with no rowsets
       
   395         * opened on it.
       
   396         * @param aUpgrade If ETrue, old structure databases are upgraded to
       
   397         * new format (new columns added as necessary). Upgrade errors are
       
   398         * silently ignored.
       
   399         */
       
   400         static void VerifyStructureL( RDbNamedDatabase& aDb, TBool aUpgrade );
       
   401 
       
   402     private:    // implementation details
       
   403 
       
   404         /**
       
   405         * Get the ordinal numbers for database columns.
       
   406         * Expects the table be open.
       
   407         */
       
   408         void GetColumnNumbersL();
       
   409 
       
   410         /**
       
   411         * Cancel changes to database; called in leave processing.
       
   412         * @param aTable The table (RFavouritesTable*) as TAny*.
       
   413         */
       
   414         static void StaticCancel( TAny* aTable );
       
   415 
       
   416     private:        // Data
       
   417 
       
   418         /// Column ordinal for Uid.
       
   419         TDbColNo iColNoUid;
       
   420         /// Column ordinal for parent folder.
       
   421         TDbColNo iColNoParentFolder;
       
   422         /// Column ordinal for type.
       
   423         TDbColNo iColNoType;
       
   424         /// Column ordinal for name.
       
   425         TDbColNo iColNoName;
       
   426         /// Column ordinal for URL.
       
   427         TDbColNo iColNoUrl;
       
   428         /// Column ordinal for username.
       
   429         TDbColNo iColNoUserName;
       
   430         /// Column ordinal for password.
       
   431         TDbColNo iColNoPassword;
       
   432         /// Column ordinal for WAP AP id.
       
   433         TDbColNo iColNoWapApId;
       
   434         /// Column ordinal for WAP AP kind.
       
   435         TDbColNo iColNoWapApValueKind;
       
   436         /// Column ordinal for derived classes' data.
       
   437         TDbColNo iColNoExtraData;
       
   438         /// Column ordinal for factory item flag.
       
   439         TDbColNo iColNoFactoryItem;
       
   440         /// Column ordinal for read-ony flag.
       
   441         TDbColNo iColNoReadOnly;
       
   442         /// Column ordinal for context id.
       
   443         TDbColNo iColNoContextId;
       
   444         /// Column ordinal for last mod time (can be KDbNullColNo if no such).
       
   445         TDbColNo iColNoModified;
       
   446         /// Column ordinal for preferred uid (can be KDbNullColNo if no such).
       
   447         TDbColNo iColNoPreferredUid;
       
   448         /// Column ordinal for Browser data (can be KDbNullColNo if no such).
       
   449         TDbColNo iColNoBrowserData;
       
   450         ///
       
   451         TDbColNo iColNoHidden;
       
   452         /// ETrue if filtering is on.
       
   453         TBool iFiltering;
       
   454         /// Constraint when filtering.
       
   455         RDbRowConstraint iFilter;
       
   456 
       
   457     };
       
   458 
       
   459 #endif
       
   460             
       
   461 // End of File