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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Meta-database declarations for use in storing comms data
24 #if (!defined METADATABASE_H)
25 #define METADATABASE_H
30 #include <comms-infras/metadata.h>
31 #include <comms-infras/metatype.h>
33 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
34 #include <metadatabase_partner.h>
46 1/ Class for expressing a session with the storage server
50 This class contains functions to create and close a session, to set the dataset version
51 and to request database actions such as locking for a transaction.
53 2/ Generic database functionality interface
57 This class uses a CMDBSession object
60 3/ General base class that inherits from MMetaDatabase to express any database element
64 This class contains the ElementId for each MetaDatabase object
65 An element id locates stored data in the comms database.
68 4/ Data classes that each inherit from CMDBElement
74 where T is a basic type value of the field (TInt, TDes, TBool etc)
76 This class derives from
80 to implement the thin template idiom
85 where T is a record of a particular type. This class expresses a soft-link
86 from a field in one record to a record of a different type (i.e. in another table).
87 The TMDBElementId value stored in this field in the repository is the id of an instance
88 of the record of type T
90 This class derives from
94 to implement the thin template idiom
102 base class for record containing specific list of fields - see CommsDatTypesv1_1.h
107 an array of records where T is the record type. This can represent a Table in a database.
112 5/ Other support classes and type definitions
116 The TMDBElementId locates a data object or set of data objects in the database.
118 A TMDBElementId expresses
120 <TableId><ColumnId><RecordId><Attributes>
122 A TMDBElementId has a different format depending on the data type it expresses
124 Table <TableId><0><0>
125 Column <TableId><ColumnId><0>
127 Record <TableId><0><RecordId>
128 Field <TAbleId><ColumnId><RecordId>
133 Attribute settings for any storable element.
134 Attributes express access control for data in the database
143 using namespace Meta;
146 // Private to implementation
147 //@internalTechnology
149 class CMDBSessionImpl;
151 // Forward declarations
156 Attribute flags for an element in the Meta Database
157 Attributes describe access rights to the data in the database
161 typedef TUint32 TMDBAttributeFlags;
164 The identifier for any entry in the MetaDatabase.
166 <TableId><ColumnId><RecordId>
168 The data location in the database
169 The meaning of the data within in the data schema
175 typedef TUint32 TMDBElementId;
179 // COMMSDAT RECORD BASE CLASS
180 // Contains fields common to all records
186 Field will contain a user-defined numeric tag for a record.
187 Useful for user searches and cheaper to search on a numeric tag than a string name.
189 This tag is not automatically connected with the record id itself,
190 which is contained within the ElementId for the record and not in any field.
195 const TMDBElementId KCDTIdRecordTag = 0x00010000;
198 Field will contain a user-defined string tag for a record.
199 This is used to uniquely identify business level information within a record.
201 This field is useful for user searches, however it should be noted that it would be more efficient to use the KCDTIdRecordTag field instead
202 as it is quicker and cheaper to search for a number than for a string.
207 const TMDBElementId KCDTIdRecordName = 0x00020000;
210 // Element Type Names
211 #define KCDTypeNameRecordTag _S("Id")
212 #define KCDTypeNameRecordName _S("Name")
215 class CMDBSession : public CBase
217 A session with the underlying storage server
225 Open a session with the storage server and establish data format version in use
226 CommsDat always attempts to support the required version of the client-facing data set.
227 The client must carefully choose the dataset version as it affects binary compatibility
229 @params aRequiredVersion
230 If the requested version is deprecated but still supported, mapping will be performed
231 within CommsDat to maintain Data and Binary compatibility for the client
232 If the requested version is the latest version, no mapping will be performed
233 and deprecated fields will be ignored
234 A client that needs to maintain BC must use a specific version
235 A client that always wants to use the latest dataset can start the session with KCDLatestVersion
237 @leave KErrUnsupported If an old unsupported version is requested
238 @leave System-wide error codes if there is an unexpected error
241 @post on success a session has been created and initialised
244 IMPORT_C static CMDBSession* NewL(TVersion aRequiredVersion);
247 As NewL and adds Session to the CleanupStack
250 IMPORT_C static CMDBSession* NewLC(TVersion aRequiredVersion);
256 IMPORT_C ~CMDBSession();
260 Close session with storage server.
262 @deprecated v9.1 Destructor is all that is required
264 IMPORT_C void Close();
268 Returns the KCDCurrentVersion constant which maps to the KCDVersion1_1
269 constant for backward compatibility reason. Please avoid using this method
270 when creating a CommsDat session object and use explicit schema version
280 IMPORT_C static TVersion LatestVersion();
284 Lookup data format version currently in use by client
288 IMPORT_C TVersion VersionInUse();
292 Open Transaction with storage server and obtain write lock - if not already set
294 @capability WriteDeviceData
296 @leave Will leave with KErrNotAvailable if Database write locked by another process
297 @leave Will report KErrAlreadyInTransaction if transaction this session is already in a transaction
298 @leave Will leave with a system-wide error code if an error occurs during commit
301 @post on success the session has exclusive write access to the database
305 IMPORT_C void OpenTransactionL();
309 Commit Transaction in database.
311 @leave Will leave with KErrNotFound if not in transaction
312 @leave Will leave with a system-wide error code if an error occurs during commit
316 @post On success the database is updated with data added, modified or deleted during the transaction
317 @post On failure, any open data containers may not be in sync with the database and should be discarded or reloaded
319 IMPORT_C void CommitTransactionL();
323 Cancel Transaction with database and rollback all associated changes
325 @leave Will fail with KErrNotFound if not in transaction
327 @pre None - though for correct usage, ensure a transaction is already open
328 @post Any open data containers may not be in sync with the database and should be discarded or reloaded
330 IMPORT_C void RollbackTransactionL();
333 Query if this session is in a transaction with the database
334 Return code will indicate
336 Already in transaction for this session,
337 Write-lock not available. Another session has it.
340 IMPORT_C TInt IsInTransaction();
344 Set attributes to ignore for all database operations during this session
346 @params aAttributeFlags indicates the requested access level to stored data.
347 Attributes set by this call will be ignored as restrictions in all database interactions,
348 providing the client has enough platform security capabilities to back up the request
352 IMPORT_C void SetAttributeMask(TMDBAttributeFlags aAttributeFlags);
356 Check flags in attribute mask
357 @params aAttributeFlags indicates the requested access level to stored data
358 Attribute flags that have been set will be ignored as restrictions in all database interactions,
359 providing the client has enough platform security capabilities to back up the request
361 @return ETrue if the flag is set in the session mask
362 This means that the attribute is ignored in database interactions for this session
364 @return EFalse if the flag is not set in the session mask
365 This means that the attribute is obeyed in all database interactions for this session
370 IMPORT_C TBool IsSetAttributeMask(TMDBAttributeFlags aAttributeFlags);
374 Clear attribute mask settings, indicating required access level to stored data
375 Clear flags in the attribute mask for this session
377 Flags indicate the requested access level to stored data
379 Attribute flags that have been set in this function will be cleared from the session's
380 attribute mask and will be obeyed as restrictions in all database interactions,
381 providing the client has enough platform security capabilities to back up the request
387 IMPORT_C void ClearAttributeMask(TMDBAttributeFlags aAttributeFlags);
392 Cancel all notification requests that are outstanding from calls to
393 MMetaDatabase::RequestNotification
394 Individual requests can be cancelled via MMetaDatabase::CancelNotify.
396 @return KErrNone on success or a system-wide error code
401 IMPORT_C TInt CancelAllNotifications();
405 Attempt to create publish/subscribe properties if not already defined.
407 This function is normally called as a setup activity by System components
409 @capability WriteDeviceData - since these properties are created in KUidSystemCategory category.
411 @return KErrNone on success. Otherwise a system-wide error code
416 IMPORT_C TInt PublishProperties();
420 TInt ConstructL( TVersion aRequiredVersion );
426 CMDBSessionImpl* iMDBSessionImpl;
428 friend class MMetaDatabase;
429 friend class CommsDatSchema;
436 class MMetaDatabase : public Meta::MMetaData
438 Interface for interaction with a database server
439 Inherited by each data set type that can be stored
446 IMPORT_C virtual ~MMetaDatabase();
450 LoadL - Load this container with data from the database
452 Any data in the container will be discarded
454 Individual fields may legitimately be NULL in the database, but if no data at all
455 is found for an entire table or record, LoadL will leave with
458 The client can request to ignore access control flags by setting the attribute mask
459 CMDBSession::SetAttributeMask()
460 However, only fields that the client has capabilities to write will be stored in the database
461 A request to read data from an unauthorised area of the database will cause the function to leave.with
464 In a record, fields in an unauthorised column may be silently ignored and returned as NULL
466 May also leave with KErrNoMemory or other general error codes
468 On failure, the container should be discarded or reloaded before it is used again
472 Ensure the ElementId for this container fully identifies the target data in the database
473 <Table><Column><Record>
474 Ensure that the session object has been initialised with the correct dataset version
475 Ensure that the session object has appropriate access control attributes to manage the target data in the database
478 IMPORT_C void LoadL(CMDBSession& aSession);
482 FindL - Find and Load the data set(s) that match all the data values entered by the
483 client in this container
485 Client can request to ignore access control flags by setting the attribute mask,
486 CMDBSession::SetAttributeMask()
487 However will not load data that the client is not authorised to see (by platsec)
488 even if the client has sets the appropriate attribute mask
492 EFalse if no data found that the client is authorised to view
494 May also leave with KErrGeneral or other general error codes.
496 On failure, the container should be discarded or repopulated before it is used again
498 Please note - a case insensitive search is done in the case of text based fields
502 Populate this container where necessary with valid data to match during the find operation
503 Ensure the ElementId for this container correcty identifies the target table in the database
505 Ensure that the session object has been initialised with the correct dataset version
506 Ensure that the session object has appropriate access control attributes to manage the target data in the database
508 IMPORT_C TBool FindL(CMDBSession& aSession);
512 Refresh all fields in the container that have not been changed by the client
514 The client can request to ignore access control flags by setting the attribute mask,
515 CMDBSession::SetAttributeMask()
516 However, only data that the client has capabilities to view will be loaded
517 Unauthorised data elements will be silently ignored and will remain NULL
519 If no data at all is found the functon will leave with
522 If fields are not accessible for reading the function may leave with
525 May also leave with other general error codes if there are unexpected
526 problems (e.g. KErrNoMemory when out of memory)
528 On failure, the container should be discarded or reloaded before it is used again
532 Ensure the ElementId for this container fully identifies the target data in the database
533 <Table><Column><Record>
534 Ensure that the session object has been initialised with the correct dataset version
535 Ensure that the session object has appropriate access control attributes to manage the target data in the database
537 IMPORT_C void RefreshL(CMDBSession& aSession);
541 StoreL - Store all fields in the database that have been changed in this container and
542 create new records where necessary.
544 StoreL is atomic for this container. An internal transaction is used even if
545 no overall transaction is set by client.
546 All changed fields in the element are stored in the database on success.
547 No fields or records are stored in the database if the function leaves
549 If a client has an open transaction in the session, the stored data will be available to this session as
550 soon as StoreL completes but will not be visible to other sessions until the transaction completes successfully
552 The client can request to ignore access control flags by setting the attribute mask
553 CMDBSession::SetAttributeMask()
554 However, only fields that the client has capabilities to write will be stored in the database
555 A request to modify data in an unauthorised area of the database will cause the function to leave.with
558 If a field already exists, StoreL will leave with
561 May also leave with other general error codes if there are unexpected
562 problems (e.g. KErrNoMemory when out of memory)
564 Store will be atomic - all fields stored after success. No fields stored if the function leaves
566 If StoreL fails or the later commit is not successful, The data in the container will not
567 match the data in the database.
569 On failure, the container should be discarded or repopulated before it is used again
573 Populate this container with valid data for storage
574 Ensure the ElementId for this container fully identifies the target location in the database
575 <Table><Column><Record>
576 Ensure that the session object has been initialised with the correct dataset version
577 Ensure that the session object has appropriate access control attributes to manage the target data in the database
580 IMPORT_C void StoreL(CMDBSession& aSession);
584 Modify all fields in the database that have been changed in this container by the caller
586 Modification is atomic for this container. It uses an internal transaction even if
587 no overall transaction set by client.
588 All changed fields in the element are modified in database on success.
589 No fields are altered in the database if the function leaves
591 Client can request to ignore access control flags by setting the attribute mask
592 CMDBSession::SetAttributeMask()
593 However, only fields that the client has capabilities to alter will be modified.in the database
594 A request to modify data in an unauthorised area will cause the function to leave.with
598 May also leave with other general error codes if there are unexpected
599 problems (e.g. KErrNoMemory when out of memory)
601 On failure, the container should be discarded or repopulated before it is used again
605 Populate this container with valid data for storage
606 Ensure the ElementId for this container fully identifies the target data in the database
607 <Table><Column><Record>
608 Ensure that the session object has been initialised with the correct dataset version
609 Ensure that the session object has appropriate access control attributes to manage the target data in the database
611 IMPORT_C void ModifyL(CMDBSession& aSession);
615 Delete fields from the database.
617 Client can request to ignore access control flags by setting the attribute mask,
618 but only fields that the client has capabilities to delete will be removed.
620 A request to delete data in unauthorised area will cause the function to leave
622 @leave If client not authorised to read or write the data, will leave with
624 May also leave with other general error codes if there are unexpected
625 problems (e.g. KErrNoMemory when out of memory)
627 @pre Ensure the ElementId for this container fully identifies the target data in the database
628 <Table><Column><Record>
629 Ensure that the session object has appropriate access control attributes to manage the target data in the database
630 Ensure the ElementId for this container correcty identifies the target data in the database
633 IMPORT_C void DeleteL(CMDBSession& aSession);
637 RequestNotification - Register for notification of events from all clients of the database
639 aRequestStatus will be completed when the following events occur
644 this aRequestStatus can be cancelled by a call to
646 MMetaDatabase::CancelNotification
648 all outstanding aRequestStatus can be cancelled by a call to
650 CMDBSession::CancelAllNotifications
652 @capability WriteDeviceData
654 @return KErrNone on success. A system wide error on failure
656 @params aSession a valid session object
657 @params aRequestStatus the requestStatus object that will be completed on notification
660 @post A notification request will be outstanding
662 IMPORT_C TInt RequestNotification(CMDBSession& aSession,
663 TRequestStatus& aRequestStatus);
666 CancelNotification - cancel an outstanding notification request
668 note that all outstanding notification requests can be cancelled by a call to
670 CMDBSession::CancelAllNotifications
674 There is an outstanding notification request
677 IMPORT_C TInt CancelNotification(CMDBSession& aSession,
678 TRequestStatus& aRequestStatus);
684 IMPORT_C explicit MMetaDatabase();
691 void DoLoadL(CMDBSessionImpl* aSession, CMDBElement* aElement, CMDBElement* aMapper, TInt& aErr, TMDBElementId aRecordId, TMDBElementId aAttributes, TBool isTheLoadForMapper = EFalse);
696 void DoLoadL(CMDBSessionImpl* aSession, CMDBElement* aElement, CMDBElement* aMapper, TInt& aErr, TMDBElementId aRecordId, TMDBElementId aAttributes, RArray<TUint32>& aMatches, TBool isTheLoadForMapper = EFalse);
701 void DoFindL(CMDBSessionImpl* aSession, CMDBElement* aElement, CMDBElement* aMapper, TInt& aErr, RArray<TUint32>& candidates, RArray<TUint32>& matches);
706 void DoRefreshL(CMDBSessionImpl* aSession, CMDBElement* aElement, CMDBElement* aMapper, TInt &aErr);
711 void DoStoreL(CMDBSessionImpl* aSession, CMDBElement* aElement, CMDBElement* aMapper, TInt &aErr);
716 void DoModifyL(CMDBSessionImpl* aSession, CMDBElement* aElement, CMDBElement* aMapper, TInt &aErr);
724 class CMDBElement : public CBase, public MMetaDatabase
726 Every item stored in the database is represented as a CMDBElement
727 This class contains the id and attributes of every item in the database
728 and for individual fields it also contains the value.
740 IMPORT_C CMDBElement();
746 IMPORT_C CMDBElement(TMDBElementId aElementId);
752 IMPORT_C ~CMDBElement();
758 Returns the ElementId of an object of this type.
762 <TableId><ColumnId><RecordId>
764 This identifies the meaning of the field in the database schema
765 It also identifies the type of the data stored in this element
766 and the instance of the type
769 IMPORT_C TMDBElementId ElementId() const;
773 Returns the TypeId of an object of this type.
777 <TableId><ColumnId><x>
779 This identifies the meaning of the data in this element in the database schema
780 It also identifies the type of the data contained in this element
782 For an element that is a Table or a Record, the ColumnId field will be set to
786 IMPORT_C TMDBElementId TypeId() const;
790 Returns the TableId of an object of this type.
792 The TableId is part of the ElementId
796 It identifies the table in the database that holds the data contained in this element
799 IMPORT_C TMDBElementId TableId() const;
803 Returns the RecordId of an object of this type.
805 The RecordId is part of the ElementId <x><x><RecordId>
807 It identifies a particular instance of this type of Element in the database
810 IMPORT_C TInt RecordId() const;
814 Returns the Attributes of an object of this type.
816 Attributes express database access rights for the data of this element
819 IMPORT_C TMDBAttributeFlags Attributes() const;
827 IMPORT_C void SetElementId(TMDBElementId aElementId);
834 IMPORT_C void SetTypeId(TMDBElementId aElementId);
841 IMPORT_C void SetRecordId(TInt aRecordId);
845 Sets one or more attributes
848 IMPORT_C void SetAttributes(TMDBAttributeFlags aAttributes);
852 Clears one or more attributes
855 IMPORT_C void ClearAttributes(TMDBAttributeFlags aAttributes);
859 Queries the attributes
861 Returns ETrue if all queried attributes are set
862 Returns EFalse if any queried attribute is not set.
864 IMPORT_C TBool IsSetAttribute(TMDBAttributeFlags aAttributes) const;
868 Queries the state of the field value
870 Returns ETrue if the value of the element is not set
871 Returns EFalse if the element contains a value
874 IMPORT_C TBool IsNull() const;
881 Queries the type of the field value
883 Returns the enumeration TCDFieldValueTypes that represents the value that can be stored in this element
887 virtual TCDFieldValueTypes Type()=0;
892 TMDBElementId* Data(){return &iElementId;}
896 TMDBElementId iElementId;
906 // COMMSDAT CONTAINERS
910 Commsdat Container classes qualifying numeric values
913 class CMDBNumFieldBase : public CMDBElement
919 IMPORT_C CMDBNumFieldBase();
923 Constructor setting Field's ElementId
925 IMPORT_C CMDBNumFieldBase(TMDBElementId aFieldId);
929 Assignment operator for field value
931 IMPORT_C CMDBNumFieldBase& operator=(const TInt aValue);
933 IMPORT_C void SetMaxLengthL(TInt aLength);
934 TMDBElementId GetL();
940 virtual TCDFieldValueTypes Type()
948 class CMDBField : public CMDBNumFieldBase
950 A thin template that guards typed data access in a single CMDBElement
951 This class describes a single numeric field in the database
967 Constructor setting Field's ElementId
969 inline CMDBField(TMDBElementId aFieldId)
970 : CMDBNumFieldBase(aFieldId)
976 Assignment operator for field value
978 inline CMDBField<TYPE>& operator=(const TYPE& aValue)
980 return (CMDBField<TYPE>&)CMDBNumFieldBase::operator=((TInt&)aValue);
984 inline CMDBField<TYPE>& operator=(const CMDBField<TYPE>& aValue)
986 return (CMDBField<TYPE>&)CMDBNumFieldBase::operator=(aValue);
990 Conversion operator for field value
992 inline operator TYPE&()
994 return (TYPE&)iValue;
998 Conversion operator for field value
1000 inline CMDBField<TYPE>& GetL()
1002 if(IsNull() && !(ElementId() & KCDChangedFlag))
1004 User::Leave(KErrNotFound); //todo commsdat specific error code
1007 return (TYPE&)iValue;
1011 Function for setting a value
1013 inline void SetL(const TYPE& aValue)
1015 CMDBNumFieldBase::operator=(aValue);
1024 Base Container class qualifying a text field
1027 class CMDBTextFieldBase : public CMDBElement
1033 IMPORT_C CMDBTextFieldBase();
1036 Constructor setting Field's ElementId
1038 IMPORT_C CMDBTextFieldBase(TMDBElementId aFieldId);
1042 Destructor that deletes the field value
1044 IMPORT_C ~CMDBTextFieldBase();
1048 Assignment Operator setting Field's value
1050 IMPORT_C CMDBTextFieldBase& operator=(const TDesC& aValue);
1053 IMPORT_C void SetMaxLengthL(TInt aLength);
1058 virtual TCDFieldValueTypes Type()
1072 class CMDBField<TDesC> : public CMDBTextFieldBase
1074 A thin template that guards typed data access in a single CMDBElement
1075 This class describes a single field in the database
1091 Constructor setting Field's ElementId
1093 inline CMDBField(TMDBElementId aFieldId)
1094 : CMDBTextFieldBase(aFieldId)
1099 inline void SetMaxLengthL(TInt aLength)
1100 // create a new buffer if necessary.
1102 CMDBTextFieldBase::SetMaxLengthL(aLength);
1105 inline CMDBField<TDesC>& operator=(const TDesC& aValue)
1107 CMDBTextFieldBase::operator=(aValue);
1111 inline CMDBField<TDesC>& operator=(CMDBField<TDesC>& aValue)
1113 CMDBTextFieldBase::operator=((const TDesC&)aValue);
1118 Conversion operator for field value
1120 inline operator const TDesC&()
1125 return *(HBufC*)iValue;
1129 Conversion operator for field value
1131 inline TDesC& GetL()
1133 if(IsNull() && !(ElementId() & KCDChangedFlag))
1135 User::Leave(KErrNotFound); //todo commsdat specific error code
1138 return *(HBufC*)iValue;
1142 Function for setting a value
1144 inline void SetL(const TDesC& aValue)
1146 SetMaxLengthL(aValue.Length());
1147 CMDBTextFieldBase::operator=(aValue);
1156 Container class for qualifying binary values
1159 class CMDBBinFieldBase : public CMDBElement
1165 IMPORT_C CMDBBinFieldBase();
1169 Constructor setting Field's ElementId
1171 IMPORT_C CMDBBinFieldBase(TMDBElementId aFieldId);
1175 Destructor that deletes the field value
1177 IMPORT_C ~CMDBBinFieldBase();
1181 Assignment Operator setting Field's value
1183 IMPORT_C CMDBBinFieldBase& operator=(const TDesC8& aValue);
1186 To allocate space for field data.
1188 IMPORT_C void SetMaxLengthL(TInt aLength);
1193 virtual TCDFieldValueTypes Type()
1201 class CMDBField<TDesC8> : public CMDBBinFieldBase
1203 A thin template that guards typed data access in a single CMDBElement
1204 This class describes a single field in the database
1220 Constructor setting Field's ElementId
1222 inline CMDBField(TMDBElementId aFieldId)
1223 : CMDBBinFieldBase(aFieldId)
1227 inline void SetMaxLengthL(TInt aLength)
1228 // create a new buffer if necessary.
1230 CMDBBinFieldBase::SetMaxLengthL(aLength);
1234 inline CMDBField<TDesC8>& operator=(const TDesC8& aValue)
1236 return (CMDBField<TDesC8>&)CMDBBinFieldBase::operator=(aValue);
1240 inline CMDBField<TDesC8>& operator=(CMDBField<TDesC8>& aValue)
1243 return (CMDBField<TDesC8>&)CMDBBinFieldBase::operator=((const TDesC8&)aValue);
1248 Conversion operator for field value
1250 inline operator const TDesC8&()
1255 return *(HBufC8*)iValue;
1259 Conversion operator for field value
1261 inline TDesC8& GetL()
1263 if(IsNull() && !(ElementId() & KCDChangedFlag))
1265 User::Leave(KErrNotFound); //todo commsdat specific error code
1268 return *(HBufC8*)iValue;
1272 Function for setting a value
1274 inline void SetL(const TDesC8& aValue)
1276 SetMaxLengthL(aValue.Length());
1277 CMDBBinFieldBase::operator=(aValue);
1287 Base class for CMDBRecordLink
1290 class CMDBRecordLinkBase : public CMDBNumFieldBase
1294 IMPORT_C CMDBRecordLinkBase();
1296 IMPORT_C CMDBRecordLinkBase(TMDBElementId aLinkingFieldId);
1298 IMPORT_C CMDBRecordLinkBase(TMDBElementId aLinkingFieldId, CMDBElement* aLinkedRecord);
1301 IMPORT_C ~CMDBRecordLinkBase();
1304 Assignment operator for field value
1305 which sets the id of the element list
1307 IMPORT_C CMDBRecordLinkBase& operator=(const TMDBElementId aValue);
1311 Conversion operator for field value
1312 which gets the id of the element list
1314 IMPORT_C operator TMDBElementId();
1322 TCDFieldValueTypes Type()
1328 // the record referenced by the link id stored in the value of this field.
1329 CMDBElement* iLinkedRecord;
1334 template<class RECORD_TYPE>
1335 class CMDBRecordLink : public CMDBRecordLinkBase
1337 This container expresses a 'soft-link' to a record in another table.
1339 The value of a CMDBRecordLink field as stored in the database is the
1340 ElementId (<Table><Record>) of the linked record.
1342 The linked record itself can be viewed via the iLinkedRecord member and its accessors
1344 If a record is loaded then the iLinkedRecord must be created explicitly
1345 by the client - either on construction, or by use of the CreateLinkL or
1346 SetLinkL functions. Often the linked record is not required by a caller.
1347 So creating it automatically would just waste memory
1349 However in the case of an explicit load of a LinkedRecord field the ILinkedRecord
1352 When instantiating iLinkedRecord directly take care to match the object's type to the Type
1353 ID that will be found at the linking element. It is better to use the CreateLinkL or
1354 SetLinkL functions to ensure type safety
1356 Calling MMetaDatabase functions on a CMDRecordLink field directly will perform the operation
1357 on the field and also the linked record if it is present
1364 Constructor/Destructor
1367 inline CMDBRecordLink()
1368 : CMDBRecordLinkBase() {}
1373 inline CMDBRecordLink(TMDBElementId aLinkingFieldId)
1374 : CMDBRecordLinkBase(aLinkingFieldId) {}
1379 inline CMDBRecordLink(TMDBElementId aLinkingFieldId, RECORD_TYPE* aLinkedRecord)
1380 : CMDBRecordLinkBase(aLinkingFieldId, (CMDBElement*)aLinkedRecord) {}
1382 inline CMDBRecordLink& operator=(const TMDBElementId aValue)
1384 return (CMDBRecordLink&)CMDBRecordLinkBase::operator=(aValue);
1391 Set the field value (this will be validated on StoreL)
1393 inline void SetL(const TMDBElementId aValue)
1395 CMDBRecordLinkBase::operator=(aValue);
1402 conversion operator for linked record of this type
1404 inline operator RECORD_TYPE*()
1406 return static_cast<RECORD_TYPE*>(iLinkedRecord);
1411 enum TFieldTypeAttributes
1413 To express type information for all MetaDatabase fields
1416 ENoAttrs, //< No attributes associated with this field.
1417 ENotNull, //< Ensures the field contains a value and must not be null.
1422 To express type information for all MetaDatabase fields
1425 const TMDBElementId iTypeId; //< Identifier for the field.
1426 const TInt iValType; //< The field type value e.g.EText, EMedText.
1427 const TFieldTypeAttributes iTypeAttr; //< The field attribute, either ENoAttrs or ENotNull.
1428 const TText * const iTypeName; //< Name of the field type.
1433 #define MDB_GENERIC_TYPE_INFO(a, b, c, d) SGenericRecordTypeInfo(a, b, c, d)
1435 typedef TBuf<64> TGenericTypeName;
1437 typedef struct SGenericRecordTypeInfoTag
1439 To express type information for all MetaDatabase fields
1442 SGenericRecordTypeInfoTag()
1443 : iTypeId(0), iValType(0), iTypeAttr(ENoAttrs) {}
1445 SGenericRecordTypeInfoTag(TMDBElementId aId,
1447 TFieldTypeAttributes aAttrType)
1448 : iTypeId(aId), iValType(aVal), iTypeAttr(aAttrType)
1452 SGenericRecordTypeInfoTag(TMDBElementId aId,
1454 TFieldTypeAttributes aAttrType,
1455 TText * const aTypeName)
1456 : iTypeId(aId), iValType(aVal), iTypeAttr(aAttrType), iTypeName(aTypeName)
1462 SGenericRecordTypeInfoTag( TMDBElementId aId,
1464 TFieldTypeAttributes aAttrType,
1465 const TGenericTypeName& aTypeName)
1466 : iTypeId(aId), iValType(aVal), iTypeAttr(aAttrType), iTypeName(aTypeName) {}
1469 TMDBElementId iTypeId; //< Identifier for the field type.
1470 TInt iValType; //< The field type value e.g.EText, EMedText.
1471 TFieldTypeAttributes iTypeAttr; //< The type's attribute, either ENoAttrs or ENotNull
1472 TGenericTypeName iTypeName; //< Name of the field type.
1473 } SGenericRecordTypeInfo;
1477 class CMDBRecordBase : public CMDBNumFieldBase
1479 Base class for all MetaDatabase records
1486 inline CMDBRecordBase(){}
1487 inline CMDBRecordBase(TMDBElementId aElementId)
1488 : CMDBNumFieldBase(aElementId | KCDMaskShowFieldType){}
1490 IMPORT_C virtual CMDBElement* GetFieldByNameL(const TPtrC& aFieldName, TInt& aValType );
1492 IMPORT_C virtual CMDBElement* GetFieldByIdL(TMDBElementId aId);
1494 IMPORT_C virtual const SRecordTypeInfo* GetRecordInfo();
1500 class CMDBGenericRecord : public CMDBRecordBase
1502 Container for data and type information in a MetaDatabase record
1503 For use to contain user-defined records as an alternative to declaring a
1504 specific record class of type CCDRecordBase
1510 friend class TMDBGenericRecordVisitor;
1511 friend class CMDBSessionImpl;
1517 explicit inline CMDBGenericRecord(TMDBElementId aElementId)
1518 : CMDBRecordBase(aElementId) {}
1520 IMPORT_C ~CMDBGenericRecord();
1522 IMPORT_C virtual CMDBElement* GetFieldByNameL(const TPtrC& aFieldName, TInt& aValType );
1524 IMPORT_C CMDBElement* GetFieldByIdL(TMDBElementId aId);
1527 IMPORT_C void InitializeL(const TDesC& aTableName, const SGenericRecordTypeInfo* aNewTableInfo);
1533 The name of this record type
1535 TBuf<KCDMaxFieldNameLength> iRecordType;
1538 array of type information about fields in this record
1539 order of field info should match order of fields
1541 RArray<SGenericRecordTypeInfo> iRecordInfo;
1543 array of fields in this record
1544 order of fields should match order of field info
1546 RPointerArray<CMDBElement> iFields;
1551 class CMDBRecordSetBase : public CMDBTextFieldBase
1553 Use this class to express a list of records MetaDatabase Element type
1554 Records can be ordered using the standard RPointerArray functions
1561 IMPORT_C CMDBRecordSetBase();
1563 IMPORT_C CMDBRecordSetBase(TMDBElementId aElementId);
1565 IMPORT_C ~CMDBRecordSetBase();
1567 inline CMDBRecordSetBase& operator=(const TPtrC& aValue)
1569 return (CMDBRecordSetBase&)CMDBTextFieldBase::operator=(aValue);
1578 RPointerArray<CMDBRecordBase> iRecords;
1584 template <class TYPE>
1585 class CMDBRecordSet : public CMDBRecordSetBase
1587 Use this class to express a list of records of a particular MetaDatabase Element type
1588 Records can be ordered using the standard RPointerArray functions
1596 inline CMDBRecordSet(){}
1598 inline CMDBRecordSet(TMDBElementId aElementId)
1599 : CMDBRecordSetBase(aElementId) {}
1601 inline CMDBRecordSet<TYPE>& operator=(const TPtrC& aValue)
1603 return (CMDBRecordSet<TYPE>&)CMDBRecordSetBase::operator=(aValue);
1606 inline TYPE* operator [](const TInt i)
1608 return (TYPE*)iRecords[i];
1615 } //end namespace CommsDat
1617 #endif // METADATABASE_H