Previous Table of Contents Next


5.6 KeysIndexes Metamodel

   The KeysIndexes package depends on the following package:

   org.omg::CWM::ObjectModel::Core

   Keys and indexes as means for specifying instances and for identifying alternate sortings of instances are represented in the CWMFoundation so that they can be shared among the various data models that employ them. The CWM Foundation defines the base concepts (uniqueness and relationships implemented as keys) upon which more specific key structures can be built by other CWM and tool-specific packages.

   




   


/namespacespannedClass



   





   


/namespace

   


Index

   


/ownedElem ent

/ownedElement

   



UniqueKey KeyRelationship

   





   





   




   {ordered}




   




   feature

   feature {ordered}

   IndexedFeature feature




   




   {ordered}




   Figure 5-9 KeysIndexes metamodel

   The concepts of key and index have been placed in the CWM Foundation because they are available in many types of data resources. In the CWM Foundation class and association descriptions that follow, relational model examples are frequently used when discussing the definition and usage of key and index types. This is done because of the wide-spread availability of relational systems and is thought to promote an understanding of the underlying concepts. These concepts, however, are no less applicable to other data models as well.

   The two central classes for representing the concept of keys are UniqueKey and KeyRelationship. UniqueKey instances correspond to the notion that keys represent the identity of instances --similar to the relational model’s concept of a primary key or an object model’s concept of an object identity. In contrast, KeyRelationship instances correspond to the notion that keys embedded in an instance can be used to determine the identity of other related instances --similar to the relational model concept of foreign key and the object model concept of a reference. Consequently, UniqueKey and KeyRelationship are best thought of as representing roles that collections of Features of Classifiers play rather than Classifiers describing the internal structure of keys. Representing keys as roles rather than structural entities provides greater flexibility and allows the reuse of Features in multiple keys and in differing relationships to each other. Associations within the KeysIndexes package describe how UniqueKey and KeyRelationship instances describe the roles they play for various Class instances and the StructuralFeature instances they contain.

   An example of the usage of Index, KeyRelationship, and UniqueKey instances to implement a simple foreign key relationship between stars and the constellations in which they are found can be seen in Figure 5-10. Also, Indexes are used to implement the ordering of constellation and star IDs.


   Figure 5-10 Star and constellation keys and index example