Adding Objects to Collections - Teradata Meta Data Services

Teradata Meta Data Services Programmer Guide

Product
Teradata Meta Data Services
Release Number
15.00
Language
English (United States)
Last Update
2018-09-28
Product Category
Teradata Tools and Utilities

Adding Objects to Collections

This section shows example code to add objects to collections. The example code uses:

  • CMetaObject::AddToDestCollection
  • CMetaObject::AddToOrigCollection
  • CMetaObject::AddManyToDestCollection
  • ////////////////////////////////////////////////////////////////////
    // AddColl function
    //
    // Example of using the CMetaObject::AddToDestCollection function
    ////////////////////////////////////////////////////////////////////
    HRESULT AddColl(CMetaRepository &repos)
    {
    	HRESULT result = S_OK;   // return value
    	CMetaObject obj2;
    	OBJECTID_t
    		RelIDCorpHasDiv		= NULLLOID,
    		loidBigGuy			= NULLLOID,
    		loidAmericanAutos	= NULLLOID;
    	
    	// Get the ObjectIds of EuroDivision, Tornado, Hurrican and the
    	// DivMakesAutos relationship
    	result = repos.GetObjectID(OBJGUID_BigGuyMotors, &loidBigGuy);
    	if (SUCCEEDED(result))
    		result = repos.GetObjectID(OBJGUID_AmericanAutos, &loidAmericanAutos);
     
    	if (SUCCEEDED(result))
    	{
    		// Set the local object ObjectID to BigGuy
    		obj2.SetObjectID(loidBigGuy);
    		// Call AddToDestCollection to add AmericanAutos to the 
    		// CorpHasDivisions collection of BigGuy
    		result = obj2.AddToDestCollection(loidAmericanAutos, NULLGUID, 
    			RelIDCorpHasDiv);
    	}
    	return (result);
    }
    //////////////////////////////////////////////////////////////////
    // AddOrigColl function
    //
    // Example of using the CMetaObject::AddToOrigCollection function
    //////////////////////////////////////////////////////////////////
    HRESULT AddOrigColl(CMetaRepository &repos)
    {
    	HRESULT result = S_OK;   // return value
    	CMetaObject obj;
    	OBJECTID_t
    		RelIDDivMakesAutos	= NULLLOID,
    		RelIDCorpHasDiv		= NULLLOID,
    		loidEuroDiv			= NULLLOID,
    		loidTurtle			= NULLLOID;
    	
    	// Get the ObjectIDs for EuroDivision, Turtle and the DivMakesAutos
    	// relationship
    	result = repos.GetObjectID(OBJGUID_EuroDivision, &loidEuroDiv);
    	if (SUCCEEDED(result))
    		result = repos.GetObjectID(RELGUID_DivMakesAutos, 
    			&RelIDDivMakesAutos);
    	if (SUCCEEDED(result))
    		result = repos.GetObjectID(OBJGUID_FarEastMotors, 
    			&loidFarEast);
    	if (SUCCEEDED(result))
    		result = repos.GetObjectID(OBJGUID_LuxuryMotors, &loidLuxuryMotors);
    	if (SUCCEEDED(result))
    		result = repos.GetObjectID(RELGUID_CorpHasDivisions, 
    			&RelIDCorpHasDiv);
    	if (SUCCEEDED(result))
    		result = repos.GetObjectID(OBJGUID_Turtle, &loidTurtle);
     
    	if (SUCCEEDED(result))
    	{
    		// Set the local object ObjectID to LuxuryMotors
    		obj.SetObjectID(loidLuxuryMotors);
    		// Call AddToOrigCollection to add FarEast Motors to the 
    		// CorpHasDivisions collection
    		result = obj.AddToOrigCollection(loidFarEast, NULLGUID, 
    			RelIDCorpHasDiv);
    	}
     
    	if (SUCCEEDED(result))
    	{
    		// Set the local object ObjectID to Turtle
    		obj.SetObjectID(loidTurtle);
    		// Call AddToOrigCollection to add EuroDivision to the DivMakesAutos
    		result = obj.AddToOrigCollection(loidEuroDiv, NULLGUID, 
    			RelIDDivMakesAutos);
    	}
     
    	return (result);
    }
     
    //////////////////////////////////////////////////////////////////////
    // AddManyColl function
    //
    // Example of using the CMetaObject::AddManyToDestCollection function
    //////////////////////////////////////////////////////////////////////
    HRESULT AddManyColl(CMetaRepository &repos)
    {
    	LLOBJECTID_t inLoids;   // list of loids to add to a collection
    	HRESULT result = S_OK;   // return value
    	CMetaObject obj;
    	OBJECTID_t
    		RelIDDivMakesAutos		= NULLLOID,
    		loidAmericanAutos		= NULLLOID,
    		loidYearling			= NULLLOID,
    		loidTortoise			= NULLLOID;
    	
    	// Get the ObjectIDs 
    	result = repos.GetObjectID(OBJGUID_AmericanAutos, &loidAmericanAutos);
    	if (SUCCEEDED(result))
    		result = repos.GetObjectID(OBJGUID_Yearling, &loidYearling);
    	if (SUCCEEDED(result))
    		result = repos.GetObjectID(OBJGUID_Tortoise, &loidTortoise);
    	if (SUCCEEDED(result))
    		result = repos.GetObjectID(RELGUID_DivMakesAutos, 
    			&RelIDDivMakesAutos);
    	if (SUCCEEDED(result))
    	{
    		// Add the ObjectIDs of Yearling and Tortoise to a list
    		inLoids.push_back(loidYearling);
    		inLoids.push_back(loidTortoise);
    		// Set the local object ObjectID to AmericanAutos
    		obj.SetObjectID(loidAmericanAutos);
    		// Call AddManyToDestCollection to add Yearling and Tortoise to
    		// the DivMakesAutos collection of AmericanAutos
    		result = obj.AddManyToDestCollection(inLoids, NULLGUID,
    			RelIDDivMakesAutos);
    	}
    	return result;
    }