GitHub    Download    Forum
Overview
Tutorial
Database setup
Preparing the project
Establish the connection
Shut down the connection
DTDL types
Creating the schema
DADL classes
Entry point object
Write and read attributes
Write and read lists
Extending the schema
Modified entry point object
Write and read objects
Write and read object lists
C++ API
C# API
DTDL
DADL
Setup
C++
C#

Modified entry point object

We already have an entry point object. The existing one has one class (Supplies). But now, we want to extend it and have an entry point object with two classes (Supplies and Inventory). To do this, we add a new class to the existing object and update (replace) the named object link.
WSupplies* pSupplies = NULL;
WInventory* pInventory = NULL;

DataFoundation::stcObjectLink* pInventoryLink;
if(S_OK == pDomain->QueryNamedObjectLink(&guidEntryPoint, 1, &pInventoryLink))
{
	if(WInventory::IsOfType(pInventoryLink))
	{
		WInventory::Open(&pInventory, *pInventoryLink, pDomain);
		pInventory->Load();

		DataFoundationAccess::MemFree(pInventoryLink);

		if(FAILED(pDomain->Execute(Transaction::Load)))
		{
			wprintf(L"Execute failed...\n");
			return -1;
		}

		pSupplies = WSupplies::CastTo(pInventory);
	}
	else if(WSupplies::IsOfType(pInventoryLink))
	{
		WSupplies::Open(&pSupplies, *pSuppliesLink, pDomain);

		if(FAILED(pDomain->Execute(Transaction::Load)))
		{
			wprintf(L"Execute failed...\n");
			return -1;
		}

		WInventory::Extend(&pInventory, pSupplies);

		pDomain->InsertNamedObject(&pInventory->BuildLink(true), &guidEntryPoint, L"updated entry point");

		pInventory->Store();
		if(FAILED(pDomain->Execute(Transaction::Store)))
		{
			wprintf(L"Execute failed...\n");
		}
	}
	else
	{
		DataFoundationAccess::MemFree(pInventoryLink);

		wprintf(L"Object is not of type WInventory or WSupplies\n");
	}
}
else
{
	WInventory::Create(&pInventory, pDomain);
	pDomain->InsertNamedObject(&pInventory->BuildLink(true), &guidEntryPoint, L"first entry point");

	pSupplies = WSupplies::CastTo(pInventory);

	pInventory->Store();
	if(FAILED(pDomain->Execute(Transaction::Store)))
	{
		wprintf(L"Execute failed...\n");
	}
}
WSupplies pSupplies = null;
WInventory pInventory = null;

DataFoundation.stcObjectLink[] apInventoryLink;
if(0 == pDomain.QueryNamedObjectLink(aguidEntryPoint, out apInventoryLink))
{
	if(WInventory.IsOfType(apInventoryLink[0]))
	{
		WInventory.Open(out pInventory, apInventoryLink[0].oiObjectId, pDomain, Transaction.Load);
		pInventory.Load(_WInventory.ALL_ATTRIBUTES, Transaction.Load);

		if(0 > pDomain.Execute(Transaction.Load))
		{
			Console.WriteLine("Execute failed...");
			return;
		}

		pSupplies = WSupplies.CastTo(pInventory);
	}
	else if(WSupplies.IsOfType(apInventoryLink[0]))
	{
		WSupplies.Open(out pSupplies, apInventoryLink[0].oiObjectId, pDomain, Transaction.Load);

		if(0 > pDomain.Execute(Transaction.Load))
		{
			Console.WriteLine("Execute failed...");
			return;
		}

		WInventory.Extend(out pInventory, pSupplies);

		pDomain.InsertNamedObject(pInventory.BuildLink(true), guidEntryPoint, "updated entry point");

		pInventory.Store(Transaction.Store);
		if(0 > pDomain.Execute(Transaction.Store))
		{
			Console.WriteLine("Execute failed...");
		}
	}
	else
	{
		Console.WriteLine("Object is not of type WSupplies or WSupplies");
	}
}
else
{
	WInventory.Create(out pInventory, pDomain);
	pDomain.InsertNamedObject(pInventory.BuildLink(true), guidEntryPoint, "first entry point", Transaction.Store);

	pSupplies = WSupplies.CastTo(pInventory);

	pInventory->Store(Transaction.Store);
	if(0 > pDomain.Execute(Transaction.Load))
	{
		Console.WriteLine("Execute failed...");
	}
}
Now our object has two classes. Our new code can use both classes, but the old code still works. No changes are required here.
© 2022 Mobiland AG