company logo

GUID

Global unique identifiers are created on demand. In order to obtain a GUID, the instance data type has to inherit from __OBJECT . Moreover, the global_identity option in the complex data type definition ( SDB_Structure ) has to be switched on in the data type or collection definition.

When activating global identity for a complex data type, an GUID value will be created when creating the instance. The global identity option is inherited to all complex data types that inherit exclusively from this base type, i.e. complex data types inheriting exclusive from a GUID generating data type will automatically generate GUIDs, too.

Instead of defining a complex data type as GUID generating, one may mark specific collections (extents, references or relationships) as GUID generating collections by switching the global_identity option for the member ( SDB_Member ) on. In this case, a GUID will be created when inserting an instance to a GUID generating collection (when not yet being created).

When setting the global_identity option for a complex data type inheriting shared from its base type, both instances will shared the GUID, which may lead to conflicts when maintaining the __OBJECT extent. Hence, it is suggested to set the global_identity option for those data types, only, which exclusively inherit from the __OBJECT data type.

Reading GUID from an instance

After an instance has been selected in a property handle, the GUID for the instance can be extracted two ways. One is calling the Property ::guid() function, the other is referring to the __GUID property.

When the data type does not support GUIDs, the function and the property will return a string with the LOID number.

... fragment ( Property &person ) {

  persons.get("Miller|Paul");

  persons.guid();  // get GUID string for Paul Miller

  persons.value("__GUID").toString();  // get GUID string

}

Accessing instances via GUID

Instances containing a GUID are collected in the __OBJECT extent, which is automatically part of any data model and can be accessed from within any application. Thus, any instance containing a GUID might be read via the __OBJECT extent, which is a weak-typed collection.

... fragment (Database &dbh) {

  Property  objects(dbh,"__OBJECT",Read);

  while ( objects.next() )

    printf("Type: %s, GUID: %s\n",objects.value("__TYPE").toString(),

                                  objects.guid());

}