In C and C++ applications, an
oidcan be declared for the database and used to quickly retrieve the object it identifies. Theoidvalues are assigned by the applications but must be unique within all classes in the database and uniqueness is enforced during object creation by the eXtremeDB runtime. Alternatively, C/C++ and all other native language APIs, can use anautoidto uniquely identify objects. Theautoidis a guaranteed unique value generated by the eXtremeDB runtime.C API
If an
oidis declared for the database, the schema compiler generates a C structure corresponding to the structure defining theoid. For instance, for a schema containing anoiddeclaration like the following:struct structname { uint4 num_in; }; declare oid structname[10000];the schema compiler will generate the following definitions and functions:
typedef struct databasename_oid__ { uint4 num_in; } databasename_oid; static const uint2 databasename_oid_size = sizeof(databasename_oid); MCO_RET databasename_delete_object( /*IN*/ mco_trans_h t, /*IN*/ const databasename_oid * oid ); MCO_RET databasename_get_class_code( /*IN*/ mco_trans_h t, /*IN*/ const databasename_oid * oid, /*OUT*/ uint2 *classcode );Note the prepended
databasenamein these definitions. This evidences the fact that only oneoidcan be defined for a given database and uniqueness for all values of thatoidwill be enforced by the runtime. Thedatabasename_delete_object()function deletes an object based on itsoid. Thedatabasename_get_class_code()function returns an integer that identifies the class of the object referenced by the specifiedoidvalue.For classes containing an
oid, the following two functions are generated to locate an object based on itsoidand to extract theoidof an object;MCO_RET classname_oid_find( /*IN*/ mco_trans_h t, /*IN*/ const databasename_oid *id, /*OUT*/ classname *handle ); MCO_RET classname_oid_get( /*IN*/ classname *handle, /*OUT*/ databasename_oid *id );(Note that the oid feature checks uniqueness of the key before creation of the class instance. Normally the uniqueness of a key is tested on the transaction commit.)
The
oidfeature is not supported in the C# and Java API. So C# and Java applications use other methods such asautoidand unique indexes for object identifiers.Autoids
The
autoidis a guaranteed unique value generated by the eXtremeDB runtime. For C and C++ applications, theautoidis declared within the DDL class definition with a specified number of estimated objects of that class. When a class is declared to have anautoid, the schema compiler will generate the following two functions for the class:MCO_RET classname_autoid_find( /*IN*/ mco_trans_h t, /*IN*/ autoid_t id, /*OUT*/ classname *handle ); MCO_RET classname_autoid_get( /*IN*/ classname *handle, /*OUT*/ autoid_t *id );Applications can retrieve the
autoidvalue with theclassname_autoid_get()function. Anautoidvalue, whether stored in a program variable or a field of another database object as a reference, can be used in theclassname_autoid_find()function to locate the referenced object.The
autoidis defined in Java and C# classes with the Persistent annotation or attribute, for example:Java: @Persistent(autoid=true) class Record { ... } C#: [Persistent(AutoID=true)] class Record { ... }When an object of a class with an
autoidis created, the runtime generates a uniqueautoidfor the object. Theautoidof an object can be retrieved with the Cursor methodGetAutoid()and the object with a specifiedautoidcan be searched in the database using the Cursor methodFind().
Note that the addition of an
oidorautoidcauses the eXtremeDB runtime to maintain an internal hash index that grows with the addition of database objects. As this hash index grows it may affect overall database performance.