3D PLM Enterprise Architecture |
Database |
Working with Automatic IdentifiersUsing the VPMIIdentifierGeneratorMgr Interface |
Use Case |
AbstractThis article illustrates identifiers creation of identifiers guaranteed to be unique using the VPMIIdentifierGeneratorMgr interface. |
The goal of this use case is to show how the VPMIIdentifierGeneratorMgr interface can be used to create identifiers that are guaranteed to be unique.
[Top]
CAAVpiIdGenerator is a use case of the CAAVPMInterfaces.edu framework that illustrates VPMInterfaces framework capabilities.
[Top]
CAAVpiIdGenerator begins by retrieving a pointer to a VPMIIdentifierGeneratorMgr implementation. Once the Init method is called, identifiers of various formats can be generated with the property of being unique.
[Top]
To launch CAAVpiIdGenerator , you will need to set up the build time environment, then compile CAAVpiIdGenerator along with its prerequisites, set up the run time environment, and then execute the use case. [1]. Launch the use case by executing the following command:
mkrun -c "CAAVpiIdGenerator"
[Top]
The CAAVpiIdGenerator use case is made of a single file located in the CAAVpiIdGenerator.m module of the CAAVPMInterfaces.edu framework:
Windows | InstallRootDirectory\CAAVPMInterfaces.edu\CAAVpiIdGenerator .m\ |
Unix | InstallRootDirectory/CAAVPMInterfaces.edu/ CAAVpiIdGenerator .m/ |
where InstallRootDirectory
is the directory where the CAA CD-ROM
is installed.
[Top]
For demonstration purposes, the code from the CAAVpiIdGenerator use case is shown here. There are seven logical steps in the CAAVpiIdGenerator use case:
[Top]
The VPMIIdentifierGeneratorMgr pointer is retrieved with the global function GetVPMIIdentifierGeneratorMgr:
VPMIIdentifierGeneratorMgr *idGen = NULL; HRESULT hr; // // 1) Retrieve the VPMIIdentifierGeneratorMgr pointer // hr = GetVPMIIdentifierGeneratorMgr(idGen); if (FAILED(hr)) { ... |
[Top]
The generator must be initialized prior to its use by calling the Init method:
... // // 2) Initialize the generator // hr = idGen->init(); if (FAILED(hr)) { ... |
[Top]
Generating an Identifier with a Given Prefix
We begin by generating a single simple identifier prefixed by 'AAA':
... // // 3) Generate a single identifier with prefix 'AAA' // { CATUnicodeString prefix("AAA"); CATUnicodeString id; hr = idGen->getIdentifier(prefix, id); if (FAILED(hr)) { ... } else { cout << "Generated ID: " << id.CastToCharPtr() << endl; } } ... |
The output from the above code should be something like:
Generated ID: AAA:1
Please note that you might not obtain 1 as each run will create different identifiers.
[Top]
Generating an Identifier with Given Prefix and Separator
Next we try to generate an identifier by specifying not only a prefix but also a separator (which is ':' in the previous step):
... // // 4) Generate a single identifier with prefix 'BBB' and separator '-' // { CATUnicodeString prefix("BBB"); CATUnicodeString separator("-"); CATUnicodeString id; hr = idGen->getIdentifier(prefix, separator, id, -1, 10); if (FAILED(hr)) { ... } else { cout << "Generated ID: " << id.CastToCharPtr() << endl; } } ... |
The above code should output something like (again the identifier can be different):
Generated ID: BBB-7
[Top]
Generating Several Consecutive Identifiers with Given Prefix and Separator
If for any reason, several identifiers are need, it is best to generate all of them at once instead of one at a time. In the following code we request 5 consecutive identifiers with a single call to getNConsecutiveIdentifier.
... // // 5) Generate 5 identifiers with prefix 'BBB' and separator '-' // { CATUnicodeString prefix("BBB"); CATUnicodeString separator("-"); CATListOfCATUnicodeString ids(5); int identifierCount(5); hr = idGen->getNConsecutiveIdentifier(prefix, separator, identifierCount, ids, -1, 10); if (FAILED(hr)) { ... } else { int idCount = ids.Size(); cout << "Generated " << idCount << " IDs:" << endl; for (int i = 1; i <= idCount; i++) { cout << " " << ids[i].CastToCharPtr() << endl; } } } ... |
The above code should output something like (again the identifiers can be different):
Generated 5 IDs: BBB-8 BBB-9 BBB-10 BBB-11 BBB-12
[Top]
Generating an Identifier but Obtaining only the Integer Part
If we are only interested in the integer part of the identifier, then getIdentifierSuffix should be used.
... // // 6) Generate a single identifier with prefix 'BBB' and separator '-' // and obtaining it as an integer // // This is identical to step 5) except that only the numeric part of // the identifier is returned, instead of the whole string // { CATUnicodeString prefix("BBB"); CATUnicodeString separator("-"); int id; hr = idGen->getIdentifierSuffix(prefix, id, separator); if (FAILED(hr)) { ... } else { cout << "Generated ID: " << id << endl; } } ... |
[Top]
Releasing a VPMIdentifierGeneratorMgr
When no more identifiers need to be created, it is advised to free its associated resources by calling the end method and releasing the pointer.
... // // 7) Release the VPMIIdentifierGeneratorMgr pointer // idGen->end(); idGen->Release(); idGen = NULL; ... |
This use case has illustrated how to generate unique identifiers with various formats using the VPMIIdentifierGeneratorMgr interface of the VPMInterfaces framework.
[Top]
[1] | Building and Launching a CAA V5 Use Case |
[Top] |
Version: 1 [September 2004] | Document created |
[Top] |
Copyright © 2004, Dassault Systèmes. All rights reserved.