Defining a Collection

Meta Data Services Programming

Meta Data Services Programming

Defining a Collection

Collections are a kind of property that provide a way to relate and group objects. Each object can support multiple collections.

Collections are materialized at run time, using interfaces that you call. The kind of collection that is materialized depends on the interface you use. Because the repository stores data, the collections that you materialize assume the state that they had the last time the collection was instantiated. For example, a collection that contains three objects at the end of one repository session will still contain those three objects the next time you run a repository session.

The rule for an object-collection association is object to collection to object. In an information model, objects are never related to each other directly. Objects are always associated through a collection. For example, if the relationship between two objects is strictly one-to-one, the collections that associate the objects each contain one object.

To define a collection, use the CollectionDef class or ICollectionDef interface for COM programs, or CollectionDef object for Automation programs.

The following example illustrates how to define two collections for a single relationship. The pattern of two collections for each relationship holds for all relationships that you create. In this example, objid_null is the object identifier, name_ is the string that defines a name, and dispid_ indicates a dispatch identifier (a constant not shown in this example).

Rem ** Declare interfaces, relationship, and collections
Dim oTypeLib as RepositoryTypeLib
Dim oRContains as RelationshipDef
Dim oCTableContains as CollectionDef
Dim oCTableContainedBy as CollectionDef

Rem ** Create the relationship oContains on oTypeLib
Set oRContains = oTypeLib.CreateRelationshipDef(objid_null, name_Contains)

Rem ** Create the Contains and ContainedBy collections
Set oCTableContains = oITypeLib.CreateRelationshipColDef(objid_null, name_TableContains, dispid_TableContains, True, oRContains)
Set oCTableContainedBy = oTypeLib.CreateRelationshipColDef(objid_null, name_TableContainedBy, dispid_TableContainedBy, False, oRContains)

See Also

CollectionDef Class

CollectionDef Object

Defining Relationships and Collections

ICollectionDef Interface

Understanding Collections

Understanding Relationship Roles