commsfwtools/preparedefaultcommsdatabase/src/MetaDatabaseSessionImpl.h
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Meta-database session declarations
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file 
       
    20 */
       
    21 
       
    22 #if (! defined METADATABASESSIONIMPL_H)
       
    23 #define        METADATABASESSIONIMPL_H 
       
    24 
       
    25 #include <e32property.h>
       
    26 
       
    27 // Forward declarations
       
    28 namespace CommsDatInternal
       
    29 {
       
    30 class CCDMapper;
       
    31 class CCDNotifier;
       
    32 }
       
    33 
       
    34 namespace CommsDat
       
    35 {
       
    36 
       
    37 using namespace CommsDatInternal;
       
    38 
       
    39 
       
    40 
       
    41 NONSHARABLE_CLASS(CMDBSessionImpl) : public CBase
       
    42 /*
       
    43 CommsDat-specific implementation of a meta database session
       
    44 
       
    45 @internalComponent
       
    46 */
       
    47 {
       
    48 public : 
       
    49     
       
    50     /* Constructor/Destructor
       
    51    
       
    52     @internalComponent
       
    53     */ 
       
    54     
       
    55     CMDBSessionImpl(CMDBSession& aOwner);
       
    56     ~CMDBSessionImpl();
       
    57     
       
    58     
       
    59     /*
       
    60     Open a session with the storage server and compare data versions
       
    61         
       
    62     The MetaDatabase always attempts to support the required version.  If the versions match,
       
    63     KErrNone will be returned.  If the versions are not the same, but the requested version
       
    64     is supported, a warning code will be returned. Otherwise an error will be 
       
    65     returned.  
       
    66     
       
    67     @internalComponent
       
    68     */
       
    69     TInt ConstructL( TVersion aRequiredVersion );  
       
    70 
       
    71     
       
    72     /* 
       
    73     Close session with storage server.
       
    74     
       
    75     @internalComponent
       
    76     */
       
    77     void Close();
       
    78 
       
    79 
       
    80 
       
    81     //
       
    82     // Accessors
       
    83     
       
    84     /*
       
    85     Lookup latest data format version
       
    86     
       
    87     @internalComponent
       
    88     */
       
    89     TVersion LatestVersion();
       
    90     
       
    91     
       
    92     /*
       
    93     Lookup data format version currently in use by client
       
    94     
       
    95     @internalComponent
       
    96     */
       
    97     TVersion VersionInUse();
       
    98     
       
    99     
       
   100     /*
       
   101     Lookup data format version currently in use by client
       
   102     Return ETrue if it is the latest version. 
       
   103     
       
   104     @internalComponent
       
   105     */
       
   106     TBool UsingLatestVersion(); 
       
   107 
       
   108     /*
       
   109 	Non-leaving method for creating notifier object.
       
   110 
       
   111     @internalComponent
       
   112     */
       
   113 	TInt CreateNotifier();
       
   114   
       
   115 
       
   116     
       
   117     /*
       
   118     Notifier object currently in use.
       
   119     
       
   120     @internalComponent
       
   121     */
       
   122     CCDNotifier* NotifierL();
       
   123       
       
   124     
       
   125     /*
       
   126     Storage class to store Comms data.  First call creates the object
       
   127         
       
   128     @internalComponent
       
   129     */
       
   130     CRepository* StorageL();
       
   131   
       
   132     
       
   133     
       
   134     //
       
   135     // Transactionsd with storage server
       
   136     //
       
   137     
       
   138     /* 
       
   139     Start transaction with storage server if available
       
   140     
       
   141     @internalComponent
       
   142     */
       
   143     TBool MaybeOpenTransactionL();
       
   144     
       
   145     
       
   146     /* 
       
   147     Query if transaction is already underway in this session
       
   148     
       
   149     @internalComponent
       
   150     */
       
   151     TBool IsInTransaction();
       
   152    
       
   153    
       
   154     /* 
       
   155     Rollback transaction restoring database state to before transaction started.
       
   156     
       
   157     @internalComponent
       
   158     */
       
   159     void RollbackTransactionL();
       
   160     
       
   161 
       
   162     /* 
       
   163     Commit transaction if outstanding and owned by caller
       
   164     
       
   165     @internalComponent
       
   166     */
       
   167     TInt MaybeCommitTransactionL(TBool aOwnLock, CMDBElement* aDoSync, TInt aErr);
       
   168       
       
   169         
       
   170     /* 
       
   171     Set flags in attribute mask as requested by client
       
   172     
       
   173     @internalComponent
       
   174     */   
       
   175     void SetAttributeMask(TMDBAttributeFlags aAttributeMask);
       
   176     
       
   177     /* 
       
   178     Check flags in attribute mask as requested by client
       
   179     
       
   180     @internalComponent
       
   181     */   
       
   182     TBool IsSetAttributeMask(TMDBAttributeFlags aAttributeMask);
       
   183 
       
   184     /* 
       
   185     Clear flags from attribute mask as requested by client
       
   186     
       
   187     @internalComponent
       
   188     */   
       
   189     void ClearAttributeMask(TMDBAttributeFlags aAttributeMask);
       
   190 
       
   191     
       
   192     /* 
       
   193     Retrieve attribute mask relevant to writing the db
       
   194     
       
   195     @internalComponent
       
   196     */
       
   197     TMDBAttributeFlags GetWriteAttributeMask();
       
   198     
       
   199     /* 
       
   200     Retrieve attribute mask relevant to reading the db
       
   201     
       
   202     @internalComponent
       
   203     */
       
   204     TMDBAttributeFlags GetReadAttributeMask();
       
   205     
       
   206     /* 
       
   207 	Decide whether to create a new node in the database
       
   208     	and then create it if necessary
       
   209 	A node means a new table, new column or new record
       
   210 	 
       
   211     @internalComponent
       
   212     */
       
   213     //void MaybeCreateNodeL(CMDBElement& aElement, TDesc& aName = KNullDesC);    
       
   214     void MaybeCreateNodeL(CMDBElement& aElement);    
       
   215     
       
   216 	/* 
       
   217     Find the element in the DB if it exists and assign its attributes
       
   218 
       
   219     @internalComponent
       
   220     */
       
   221     TInt LoadElementAttributesL(TMDBElementId& aElementId);
       
   222     
       
   223     TInt LoadNodeAttributesL(TMDBElementId& aElementId);
       
   224   
       
   225 	/* 
       
   226     Locate a new node in the database
       
   227    	A node means a new table, new column or new record
       
   228 
       
   229     @internalComponent
       
   230     */
       
   231  	void SetNodeIdL(TMDBElementId& aElementId, TMDBElementId aMask, TMDBElementId aInitialId, TMDBElementId aMaxId, TInt aMaxVal);
       
   232 
       
   233 
       
   234 	/* 
       
   235     Create a new placeholder in the database
       
   236    	A placeholder reserves space for a new table, new column or new record
       
   237     A placeholder never has attributes set
       
   238     tableName is typically KNullDesC, but should be set to something readable for a generic record
       
   239     @internalComponent
       
   240     */
       
   241  	void CreatePlaceholderL(TMDBElementId& aElementId, TMDBElementId aNodeTypeMask, TDesC& aTableName);
       
   242  	
       
   243  	//first try with an overload...
       
   244  	void CreatePlaceholderL(TMDBElementId& aElementId, TMDBElementId aNodeTypeMask, CMDBElement& aElement);
       
   245     
       
   246     /* 
       
   247     Create a new node in the database
       
   248    	A node identifies a new table, new column or new record
       
   249     It carries type information about the node and identifies default attributes for the node and its children
       
   250         Table - table id
       
   251         Column - column id, column name, column type
       
   252         Record - record id
       
   253 
       
   254     A node is used as the primary key to identify an element in the database
       
   255     @internalComponent
       
   256     */
       
   257  	void CreateNodeL(TMDBElementId& aElementId, TMDBElementId aMask, CMDBElement& aElement, SGenericRecordTypeInfo* aFieldTypeInfo = NULL);
       
   258 
       
   259 	/* 
       
   260     If appropriate, modify a node in the database and its placeholder
       
   261    	A node identifies a table, column or record
       
   262 
       
   263     @internalComponent
       
   264     */
       
   265     TInt MaybeModifyNodeL(TMDBElementId& aElementId);   
       
   266 
       
   267 
       
   268 	/* 
       
   269     If appropriate, delete a node in the database and its placeholder
       
   270    	A node identifies a table, column or record
       
   271 
       
   272     @internalComponent
       
   273     */
       
   274  	TInt MaybeDeleteNodeL(CMDBElement* aElement, TMDBElementId& aElementId);
       
   275 
       
   276 
       
   277     /* 
       
   278     Check for match between two arrays of element ids
       
   279     Utility function used by metadatabase and visitors
       
   280 
       
   281     @internalComponent
       
   282     */
       
   283     TInt FindMatchL(RArray<TUint32>& aCandidates, RArray<TUint32>& aMatches, TUint32 aIdMask = 0);
       
   284 
       
   285     void EndModification(){iInModification = EFalse;}
       
   286 
       
   287 	void ReadAllowedL(TMDBElementId aElementId);
       
   288 
       
   289 	void WriteAllowedL(TMDBElementId aElementId);
       
   290 	
       
   291 	void DeleteAllowedL(TMDBElementId aElementId);
       
   292 	
       
   293 	TInt GatherParentAttributesL(TMDBElementId& aElementId);
       
   294 	
       
   295 	TInt FindElementInDatabaseL(TMDBElementId& aElementId);
       
   296 
       
   297 public:
       
   298 
       
   299 	// Need to call back to owner to make recursive db calls for nested elements
       
   300     CMDBSession&                    iOwner;
       
   301     
       
   302     TBool                           iMapping;
       
   303 
       
   304 private:
       
   305     
       
   306     void EstablishVersionL(TVersion aVersionToCheck);   
       
   307 
       
   308     /* Flag to check to see if mapping is required
       
   309     Worth the cost of a flag here because checking it is cheaper than calculating
       
   310     the version all the time*/
       
   311     TBool                           iUsingLatestVersion; 
       
   312     
       
   313     CCDNotifier*                    iNotifier;
       
   314     
       
   315     TRequestStatus                  iStatusIndicator;
       
   316    
       
   317     // Storage server interface
       
   318     CRepository*                    iCommsStorage;
       
   319 
       
   320     TVersion                        iClientsDataSetVersion;   
       
   321     
       
   322     TBool                           iInTransaction;
       
   323     TBool                           iInModification;
       
   324     
       
   325     TMDBAttributeFlags              iReadAttributeMask;
       
   326     TMDBAttributeFlags              iWriteAttributeMask;
       
   327 
       
   328 	RProperty						iCommitSeqProperty;
       
   329 };
       
   330 
       
   331 
       
   332     
       
   333 
       
   334 } // end namespace CommsDatInternal
       
   335 
       
   336 #endif //METADATABASESSIONIMPL_H