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#

Entry point object

For objects that mark the "entry point" or that we use as the first object we open when we connect to a database, we have to store them in a special list within the storage. Such "entry points" are called "named objects" in DataFS because we give the object a unique GUID, which will be its "name".
Tutorial.cpp
Tutorial.cs
const GUID guidEntryPoint
{ 0x71e456a5, 0x6a4e, 0x46aa, { 0xa7, 0x27, 0x10, 0x5d, 0x58, 0x4c, 0x79, 0x17 } };
public static readonly Guid guidEntryPoint = new Guid("71E456A5-6A4E-46aa-A727-105D584C7917");

About links

An object in DataFS only exists if it is sustainably linked from somewhere. There are also lazy links, which do not sustain the object the link points to. This means that lazy-linked objects have to be sustainably linked from somewhere else, or the object will be deleted.

Create an object and link it

First, we create a new object without any relations to another object.
WSupplies* pSupplies;
WSupplies::Create(&pSupplies, pDomain);
WSupplies pSupplies;
WSupplies.Create(out pSupplies, pDomain);
Then, make it an entry point or a named object using the InsertNamedObjectInsertNamedObject function. The GUID or name of the named object must be unique, and no two objects can be named with the same GUID.
We can use the "BuildLink" function to build the necessary parameter for the function call. By passing true as the parameter we specify, this link is a sustainable link and not a lazy link.
pDomain->InsertNamedObject(&pSupplies->BuildLink(true), &guidEntryPoint, L"first entry point");
pDomain.InsertNamedObject(pSupplies.BuildLink(true), guidEntryPoint, "first entry point", Transaction.Store);

Open a named object

If we later want to open our "Supplies" object again, we need to find out its ObjectID first (not to be confused with the GUID). There are several functions available to do this. One is the QueryNamedObjectLinkQueryNamedObjectLink function that we will use now.
DataFoundation::stcObjectLink* pSuppliesLink;
pDomain->QueryNamedObjectLink(&guidEntryPoint, 1, &pSuppliesLink);

WSupplies* pSupplies = NULL;
WSupplies::Open(&pSupplies, *pSuppliesLink, pDomain);
DataFoundation.stcObjectLink[] apSuppliesLink;
pDomain.QueryNamedObjectLink(aguidEntryPoint, out apSuppliesLink);

WSupplies pSupplies = null;
WSupplies.Open(out pSupplies, apSuppliesLink[0].oiObjectId, pDomain, Transaction.Load);

Final code

The code in our main file for opening the Inventory might look something like the next code segment.
Tutorial.cpp
Tutorial.cs
WSupplies* pSupplies = NULL;

DataFoundation::stcObjectLink* pSuppliesLink;
if(S_OK == pDomain->QueryNamedObjectLink(&guidEntryPoint, 1, &pSuppliesLink))
{
	if(WSupplies::IsOfType(pSuppliesLink))
	{
		WSupplies::Open(&pSupplies, *pSuppliesLink, pDomain);
		pSupplies->Load();

		DataFoundationAccess::MemFree(pSuppliesLink);

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

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

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

DataFoundation.stcObjectLink[] apSuppliesLink;
if(0 == pDomain.QueryNamedObjectLink(aguidEntryPoint, out apSuppliesLink))
{
	if(WSupplies.IsOfType(apSuppliesLink[0]))
	{
		WSupplies.Open(out pSupplies, apSuppliesLink[0].oiObjectId, pDomain, Transaction.Load);
		pSupplies.Load(_WSupplies.ALL_ATTRIBUTES, Transaction.Load);

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

	pSupplies->Store(Transaction.Store);
	if(0 > pDomain.Execute(Transaction.Load))
	{
		Console.WriteLine("Execute failed...");
	}
}
© 2022 Mobiland AG